From 886a0e4986628488e9a711b576296f8be58a8b19 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 9 Oct 2018 13:30:54 +0000 Subject: [PATCH] composeutil: Test for ability to open new /dev/null If `nodev` is set, we should fail fast. See also https://github.com/containers/storage/pull/208 Closes: #1604 Approved by: jlebon --- src/app/rpmostree-composeutil.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/app/rpmostree-composeutil.c b/src/app/rpmostree-composeutil.c index 0a64b9f4..a2704f45 100644 --- a/src/app/rpmostree-composeutil.c +++ b/src/app/rpmostree-composeutil.c @@ -131,6 +131,16 @@ rpmostree_composeutil_legacy_prep_dev (int rootfs_dfd, return glnx_throw_errno (error); } + { GLNX_AUTO_PREFIX_ERROR ("Testing /dev/null in target root (is nodev set?)", error); + glnx_autofd int devnull_fd = -1; + if (!glnx_openat_rdonly (dest_fd, "null", TRUE, &devnull_fd, error)) + return FALSE; + char buf[1]; + ssize_t s = read (devnull_fd, buf, sizeof (buf)); + if (s < 0) + return glnx_throw_errno_prefix (error, "read"); + } + return TRUE; }