Skip to content

Commit fea204e

Browse files
committed
Fixes inability to use /dev/null when inside a container
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.
1 parent 8523022 commit fea204e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libcontainer/cgroups/systemd/common.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,14 @@ 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} being populated.
297+
// (/dev/{block,char} is populated by udev, which isn't strictly required for systemd).
298+
// Ironically, this happens most easily when starting containerd within a runc created
299+
// container itself.
300+
if _, err := os.Stat("/sys" + entry.Path); err != nil {
301+
logrus.Warnf("skipping device %s for systemd: %s", entry.Path, err)
302+
continue
303+
}
298304
}
299305
}
300306
deviceAllowList = append(deviceAllowList, entry)

0 commit comments

Comments
 (0)