Skip to content

Commit 43e3eab

Browse files
Jiri Olsasmb49
authored andcommitted
bpf/selftests: Fix namespace mount setup in tc_redirect
BugLink: https://bugs.launchpad.net/bugs/1962230 [ Upstream commit 5e22dd1 ] The tc_redirect umounts /sys in the new namespace, which can be mounted as shared and cause global umount. The lazy umount also takes down mounted trees under /sys like debugfs, which won't be available after sysfs mounts again and could cause fails in other tests. # cat /proc/self/mountinfo | grep debugfs 34 23 0:7 / /sys/kernel/debug rw,nosuid,nodev,noexec,relatime shared:14 - debugfs debugfs rw # cat /proc/self/mountinfo | grep sysfs 23 86 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:2 - sysfs sysfs rw # mount | grep debugfs debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) # ./test_progs -t tc_redirect torvalds#164 tc_redirect:OK Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED # mount | grep debugfs # cat /proc/self/mountinfo | grep debugfs # cat /proc/self/mountinfo | grep sysfs 25 86 0:22 / /sys rw,relatime shared:2 - sysfs sysfs rw Making the sysfs private under the new namespace so the umount won't trigger the global sysfs umount. Reported-by: Hangbin Liu <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Cc: Jussi Maki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent c7f5226 commit 43e3eab

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tools/testing/selftests/bpf/prog_tests/tc_redirect.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ static int setns_by_fd(int nsfd)
104104
if (!ASSERT_OK(err, "unshare"))
105105
return err;
106106

107+
/* Make our /sys mount private, so the following umount won't
108+
* trigger the global umount in case it's shared.
109+
*/
110+
err = mount("none", "/sys", NULL, MS_PRIVATE, NULL);
111+
if (!ASSERT_OK(err, "remount private /sys"))
112+
return err;
113+
107114
err = umount2("/sys", MNT_DETACH);
108115
if (!ASSERT_OK(err, "umount2 /sys"))
109116
return err;

0 commit comments

Comments
 (0)