@@ -234,6 +234,87 @@ function test_mount_order() {
234234 [[ " $( stat -c %a rootfs/setgid/a/b/c) " == 2755 ]]
235235}
236236
237+ # https://github.com/opencontainers/runc/issues/4971
238+ @test " runc run [tmpfs mount mode= inherit]" {
239+ mkdir rootfs/tmpfs
240+ chmod " =0710" rootfs/tmpfs
241+
242+ update_config ' .mounts += [{
243+ type: "tmpfs",
244+ source: "tmpfs",
245+ destination: "/tmpfs",
246+ options: ["rw", "nodev", "nosuid"]
247+ }]'
248+ update_config ' .process.args = ["stat", "-c", "%a", "/tmpfs"]'
249+
250+ runc run test_busybox
251+ [ " $status " -eq 0 ]
252+ [[ " $output " == " 710" ]]
253+
254+ update_config ' .process.args = ["cat", "/proc/self/mounts"]'
255+ runc run test_busybox
256+ [ " $status " -eq 0 ]
257+ grep -Ex " tmpfs /tmpfs tmpfs [^ ]*\bmode=710\b[^ ]* .*" <<< " $output"
258+ }
259+
260+ # https://github.com/opencontainers/runc/issues/4971
261+ @test " runc run [tmpfs mount explicit mode=]" {
262+ mkdir rootfs/tmpfs
263+ chmod " =0710" rootfs/tmpfs
264+
265+ update_config ' .mounts += [{
266+ type: "tmpfs",
267+ source: "tmpfs",
268+ destination: "/tmpfs",
269+ options: ["rw", "nodev", "nosuid", "mode=1500"]
270+ }]'
271+ update_config ' .process.args = ["stat", "-c", "%a", "/tmpfs"]'
272+
273+ # Explicitly setting mode= overrides whatever mode we would've inherited.
274+ runc run test_busybox
275+ [ " $status " -eq 0 ]
276+ [[ " $output " == " 1500" ]]
277+
278+ update_config ' .process.args = ["cat", "/proc/self/mounts"]'
279+ runc run test_busybox
280+ [ " $status " -eq 0 ]
281+ grep -Ex " tmpfs /tmpfs tmpfs [^ ]*\bmode=1500\b[^ ]* .*" <<< " $output"
282+
283+ # Verify that the actual directory was not chmod-ed.
284+ [[ " $( stat -c %a rootfs/tmpfs) " == 710 ]]
285+ }
286+
287+ # https://github.com/opencontainers/runc/issues/4971
288+ @test " runc run [tmpfs mount mode=1777 default]" {
289+ update_config ' .mounts += [{
290+ type: "tmpfs",
291+ source: "tmpfs",
292+ destination: "/non-existent/foo/bar/baz",
293+ options: ["rw", "nodev", "nosuid"]
294+ }]'
295+ update_config ' .process.args = ["stat", "-c", "%a", "/non-existent/foo/bar/baz"]'
296+
297+ rm -rf rootfs/non-existent
298+ runc run test_busybox
299+ [ " $status " -eq 0 ]
300+ [[ " $output " == " 1777" ]]
301+
302+ update_config ' .process.args = ["cat", "/proc/self/mounts"]'
303+
304+ rm -rf rootfs/non-existent
305+ runc run test_busybox
306+ [ " $status " -eq 0 ]
307+ # We don't explicitly set a mode= in this case, it is just the tmpfs default.
308+ grep -Ex " tmpfs /non-existent/foo/bar/baz tmpfs .*" <<< " $output"
309+ run ! grep -Ex " tmpfs /non-existent/foo/bar/baz tmpfs [^ ]*\bmode=[0-7]+\b[^ ]* .*" <<< " $output"
310+
311+ # Verify that the actual modes are *not* 1777.
312+ [[ " $( stat -c %a rootfs/non-existent) " == 755 ]]
313+ [[ " $( stat -c %a rootfs/non-existent/foo) " == 755 ]]
314+ [[ " $( stat -c %a rootfs/non-existent/foo/bar) " == 755 ]]
315+ [[ " $( stat -c %a rootfs/non-existent/foo/bar/baz) " == 755 ]]
316+ }
317+
237318@test " runc run [ro /sys/fs/cgroup mounts]" {
238319 # Without cgroup namespace.
239320 update_config ' .linux.namespaces -= [{"type": "cgroup"}]'
0 commit comments