Skip to content

Commit 3b95828

Browse files
committed
Fixes inability to use /dev/null when inside a container
This is a forward port of #3620 The original code depended on the origin filesystem to have /dev/{block,char} populated. This is done by udev normally and while is very common non-containerized systemd installs, it's very easy to start systemd in a container created by runc itself and not have /dev/{block,char} populated. When this occurs, the following error output is observed: $ docker run hello-world docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error reopening /dev/null inside container: open /dev/null: operation not permitted: unknown. /dev/null can't be opened because it was not added to the deviceAllowList, as there was no /dev/char directory. The change here utilizes the fact that when sysfs in in use, there is a /sys/dev/{block,char} that is kernel maintained that we can check. Signed-off-by: Evan Phoenix <[email protected]> (cherry picked from commit 462e719)
1 parent 28fa513 commit 3b95828

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

libcontainer/cgroups/systemd/common.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,18 @@ func generateDeviceProperties(r *configs.Resources) ([]systemdDbus.Property, err
293293
// rules separately to systemd) we can safely skip entries that don't
294294
// have a corresponding path.
295295
if _, err := os.Stat(entry.Path); err != nil {
296-
logrus.Debugf("skipping device %s for systemd: %s", entry.Path, err)
297-
continue
296+
// Also check /sys/dev so that we don't depend on /dev/{block,char}
297+
// being populated. (/dev/{block,char} is populated by udev, which
298+
// isn't strictly required for systemd). Ironically, this happens most
299+
// easily when starting containerd within a runc created container
300+
// itself.
301+
302+
// We don't bother with securejoin here because we create entry.Path
303+
// right above here, so we know it's safe.
304+
if _, err := os.Stat("/sys" + entry.Path); err != nil {
305+
logrus.Warnf("skipping device %s for systemd: %s", entry.Path, err)
306+
continue
307+
}
298308
}
299309
}
300310
deviceAllowList = append(deviceAllowList, entry)

0 commit comments

Comments
 (0)