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