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