27a4e9
From 2ce40b6ad72b4bd4391380cafc5ef1bad1fa0b31 Mon Sep 17 00:00:00 2001
27a4e9
From: Kir Kolyshkin <kolyshkin@gmail.com>
27a4e9
Date: Wed, 4 May 2022 14:56:16 -0700
27a4e9
Subject: [PATCH] Remove tun/tap from the default device rules
27a4e9
27a4e9
Looking through git blame, this was added by commit 9fac18329
27a4e9
aka "Initial commit of runc binary", most probably by mistake.
27a4e9
27a4e9
Obviously, a container should not have access to tun/tap device, unless
27a4e9
it is explicitly specified in configuration.
27a4e9
27a4e9
Now, removing this might create a compatibility issue, but I see no
27a4e9
other choice.
27a4e9
27a4e9
Aside from the obvious misconfiguration, this should also fix the
27a4e9
annoying
27a4e9
27a4e9
> Apr 26 03:46:56 foo.bar systemd[1]: Couldn't stat device /dev/char/10:200: No such file or directory
27a4e9
27a4e9
messages from systemd on every container start, when runc uses systemd
27a4e9
cgroup driver, and the system runs an old (< v240) version of systemd
27a4e9
(the message was presumably eliminated by [1]).
27a4e9
27a4e9
[1] https://github.com/systemd/systemd/pull/10996/commits/d5aecba6e0b7c73657c4cf544ce57289115098e7
27a4e9
27a4e9
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
27a4e9
---
27a4e9
 .../ebpf/devicefilter/devicefilter_test.go    | 19 ++++++-------------
27a4e9
 libcontainer/specconv/spec_linux.go           | 10 ----------
27a4e9
 2 files changed, 6 insertions(+), 23 deletions(-)
27a4e9
27a4e9
diff --git a/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go b/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
27a4e9
index d279335821..25703be5ad 100644
27a4e9
--- a/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
27a4e9
+++ b/libcontainer/cgroups/ebpf/devicefilter/devicefilter_test.go
27a4e9
@@ -120,21 +120,14 @@ block-8:
27a4e9
         51: Mov32Imm dst: r0 imm: 1
27a4e9
         52: Exit
27a4e9
 block-9:
27a4e9
-// tuntap (c, 10, 200, rwm, allow)
27a4e9
+// /dev/pts (c, 136, wildcard, rwm, true)
27a4e9
         53: JNEImm dst: r2 off: -1 imm: 2 <block-10>
27a4e9
-        54: JNEImm dst: r4 off: -1 imm: 10 <block-10>
27a4e9
-        55: JNEImm dst: r5 off: -1 imm: 200 <block-10>
27a4e9
-        56: Mov32Imm dst: r0 imm: 1
27a4e9
-        57: Exit
27a4e9
+        54: JNEImm dst: r4 off: -1 imm: 136 <block-10>
27a4e9
+        55: Mov32Imm dst: r0 imm: 1
27a4e9
+        56: Exit
27a4e9
 block-10:
27a4e9
-// /dev/pts (c, 136, wildcard, rwm, true)
27a4e9
-        58: JNEImm dst: r2 off: -1 imm: 2 <block-11>
27a4e9
-        59: JNEImm dst: r4 off: -1 imm: 136 <block-11>
27a4e9
-        60: Mov32Imm dst: r0 imm: 1
27a4e9
-        61: Exit
27a4e9
-block-11:
27a4e9
-        62: Mov32Imm dst: r0 imm: 0
27a4e9
-        63: Exit
27a4e9
+        57: Mov32Imm dst: r0 imm: 0
27a4e9
+        58: Exit
27a4e9
 `
27a4e9
 	var devices []*devices.Rule
27a4e9
 	for _, device := range specconv.AllowedDevices {
27a4e9
diff --git a/libcontainer/specconv/spec_linux.go b/libcontainer/specconv/spec_linux.go
27a4e9
index 5ae95c6c18..83c7a2c348 100644
27a4e9
--- a/libcontainer/specconv/spec_linux.go
27a4e9
+++ b/libcontainer/specconv/spec_linux.go
27a4e9
@@ -302,16 +302,6 @@ var AllowedDevices = []*devices.Device{
27a4e9
 			Allow:       true,
27a4e9
 		},
27a4e9
 	},
27a4e9
-	// tuntap
27a4e9
-	{
27a4e9
-		Rule: devices.Rule{
27a4e9
-			Type:        devices.CharDevice,
27a4e9
-			Major:       10,
27a4e9
-			Minor:       200,
27a4e9
-			Permissions: "rwm",
27a4e9
-			Allow:       true,
27a4e9
-		},
27a4e9
-	},
27a4e9
 }
27a4e9
 
27a4e9
 type CreateOpts struct {