mount08.c: Restrict overmounting of ephemeral entities on /proc/<pid>/fd/<nr>
PATCH 1/1 mount08.c: Restrict overmounting of ephemeral entities on /proc/<pid>/fd/<nr>
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 56 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +56 -0
56 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Some comments below. LGTM otherwise
Quoted 1 line · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>
We miss a description here. Maybe something like:
Add a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>. Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
Quoted 34 lines
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 56 ++++++++++++++++++++++ 3 files changed, 58 insertions(+)create mode 100644
testcases/kernel/syscalls/mount/mount08.cruntest/syscalls +1
-0@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01testcases/kernel/syscalls/mount/.gitignore +1
-0@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08testcases/kernel/syscalls/mount/mount08.c new file +0
-0
testcases/kernel/syscalls/mount/mount08.c line 7
Quoted 7 lines
testcases/kernel/syscalls/mount/mount08.c new file +7
-0@@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Wei Gao <[email protected]> +*/ + +/*\ +* [Description]
This is not needed anymore.
testcases/kernel/syscalls/mount/mount08.c line 11
Quoted 4 lines
testcases/kernel/syscalls/mount/mount08.c new file +4
-0+* +* This test check restrict overmounting on /proc/<pid>/fd/<nr>. +* It is based on the following kernel commit: +* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
"Verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>."
Link is not needed if we already have .tags in the "struct tst_test". See below
Quoted 34 lines
testcases/kernel/syscalls/mount/mount08.c new file +34
-0+*/ + +#include "tst_test.h" +#include <sys/mount.h> +#include "tst_safe_file_at.h" + +#define MNTPOINT "mntpoint" +#define FOO MNTPOINT "/foo" +#define BAR MNTPOINT "/bar" + +static void run (void ) +{ +char path[PATH_MAX ]; +int foo_fd, newfd, proc_fd; + + foo_fd =SAFE_OPEN (FOO ,O_RDONLY |O_NONBLOCK ,0640 ); + newfd =SAFE_DUP (foo_fd); +SAFE_CLOSE (foo_fd); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), newfd); + + proc_fd =SAFE_OPENAT (AT_FDCWD , path,O_PATH |O_NOFOLLOW ); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), proc_fd); + +TST_EXP_FAIL ( +mount (BAR , path,"" ,MS_BIND ,0 ), +ENOENT , +"mount() on proc failed expectedly" + ); +} + +static void setup (void ) +{
testcases/kernel/syscalls/mount/mount08.c line 55
Quoted 10 lines
testcases/kernel/syscalls/mount/mount08.c new file +10
-0+SAFE_CREAT (FOO ,0777 ); +SAFE_CREAT (BAR ,0777 ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .mntpoint =MNTPOINT , + .min_kver ="6.12" ,
We miss .tags to the kernel commit in here:
testcases/kernel/syscalls/mount/mount08.c line 56
Quoted 1 line
testcases/kernel/syscalls/mount/mount08.c new file +1
-0+};
Kind regards,
Andrea Cervesato
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 mount08.c: Restrict overmounting of ephemeral entities on /proc/<pid>/fd/<nr>
In reply to Wei Gao via ltpAdd a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +57 -0
57 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Commit message is a bit long. it should be 72 chars max. Maybe we can just use "mount08: Restrict overmounting of ephemeral entities".
Quoted 1 line · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>
Uhm Signed-off-by here is a weird thing :-)
Otherwise LGTM.
Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpAdd a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +57 -0
57 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] mount08.c: Restrict overmounting of ephemeral entities
Quoted 2 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>Reviewed-by Andrea Cervesato <[email protected]>
This is still wrong. :(
Quoted 98 lines
Add a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172Signed-off-by Wei Gao <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.cruntest/syscalls +1
-0@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01testcases/kernel/syscalls/mount/.gitignore +1
-0@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08testcases/kernel/syscalls/mount/mount08.c new file +57
-0@@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Wei Gao <[email protected]> +*/ + +/*\ +* Verify that mount will raise ENOENT if we try to mount on magic links +* under /proc/<pid>/fd/<nr>. +*/ + +#include "tst_test.h" +#include <sys/mount.h> +#include "tst_safe_file_at.h" + +#define MNTPOINT "mntpoint" +#define FOO MNTPOINT "/foo" +#define BAR MNTPOINT "/bar" + +static void run (void ) +{ +char path[PATH_MAX ]; +int foo_fd, newfd, proc_fd; + + foo_fd =SAFE_OPEN (FOO ,O_RDONLY |O_NONBLOCK ,0640 ); + newfd =SAFE_DUP (foo_fd); +SAFE_CLOSE (foo_fd); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), newfd); + + proc_fd =SAFE_OPENAT (AT_FDCWD , path,O_PATH |O_NOFOLLOW ); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), proc_fd); + +TST_EXP_FAIL ( +mount (BAR , path,"" ,MS_BIND ,0 ), +ENOENT , +"mount() on proc failed expectedly" + ); +} + +static void setup (void ) +{ +SAFE_CREAT (FOO ,0777 ); +SAFE_CREAT (BAR ,0777 ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .mntpoint =MNTPOINT , + .min_kver ="6.12" , + .tags = (const struct tst_tag []) { + {"linux-git" ,"d80b065bb172" }, + {} + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] mount08.c: Restrict overmounting of ephemeral entities
Quoted 5 lines · Ricardo B. Marlière
Quoted 2 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>Reviewed-by Andrea Cervesato <[email protected]>This is still wrong. :(
@Ricardo Thanks for point this out.
@Andrea Sorry for misunderstanding your comments in v2 comments.
Quoted 5 lines
Quoted 5 lines
Add a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpAdd a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +57 -0
57 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4] mount08.c: Restrict overmounting of ephemeral entities
Hi!
Quoted 52 lines
Signed-off-by Wei Gao <[email protected]>Reviewed-by Andrea Cervesato <[email protected]>--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.cruntest/syscalls +1
-0@@ -852,6 +852,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01testcases/kernel/syscalls/mount/.gitignore +1
-0@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08testcases/kernel/syscalls/mount/mount08.c new file +16
-0@@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Wei Gao <[email protected]> +*/ + +/*\ +* Verify that mount will raise ENOENT if we try to mount on magic links +* under /proc/<pid>/fd/<nr>. +*/ + +#include "tst_test.h" +#include <sys/mount.h> +#include "tst_safe_file_at.h" + +#define MNTPOINT "mntpoint" +#define FOO MNTPOINT "/foo"
testcases/kernel/syscalls/mount/mount08.c line 26
Quoted 10 lines
testcases/kernel/syscalls/mount/mount08.c new file +10
-0+#define BAR MNTPOINT "/bar" + +static void run (void ) +{ +char path[PATH_MAX ]; +int foo_fd, newfd, proc_fd; + + foo_fd =SAFE_OPEN (FOO ,O_RDONLY |O_NONBLOCK ,0640 ); + newfd =SAFE_DUP (foo_fd); +SAFE_CLOSE (foo_fd);
AFAIK the dup() here is not needed, the original reproducer used the dup() to create a file descriptor with exact number for the loop. In this case we can just take the fd from SAFE_OPEN() and use it instead of the newfd.
testcases/kernel/syscalls/mount/mount08.c line 37
Quoted 10 lines
testcases/kernel/syscalls/mount/mount08.c new file +10
-0+sprintf (path,"/proc/%d/fd/%d" ,getpid (), newfd); + + proc_fd =SAFE_OPENAT (AT_FDCWD , path,O_PATH |O_NOFOLLOW ); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), proc_fd); + +TST_EXP_FAIL ( +mount (BAR , path,"" ,MS_BIND ,0 ), +ENOENT , + "mount() on proc failed expectedly"
^
This message is used even if the call passed unexpectedly, so it should describe what is being done rather than the expected outcome, e.g.:
"mount(/proc/$PID/fd/$FD)"
testcases/kernel/syscalls/mount/mount08.c line 38
Quoted 1 line
testcases/kernel/syscalls/mount/mount08.c new file +1
-0+ );
You are not closing the file descriptors here, so the test fails with:
"-i 1000" command line params.
testcases/kernel/syscalls/mount/mount08.c line 44
Quoted 6 lines
testcases/kernel/syscalls/mount/mount08.c new file +6
-0+} + +static void setup (void ) +{ +SAFE_CREAT (FOO ,0777 ); +SAFE_CREAT (BAR ,0777 );
This leaks two file descriptors too, but at least it's these are not opened on each iteration.
If you just need to create a file do SAFE_TOUCH(FOO, 0777, NULL) instead.
testcases/kernel/syscalls/mount/mount08.c line 52
Quoted 8 lines
testcases/kernel/syscalls/mount/mount08.c new file +8
-0+} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .mntpoint =MNTPOINT , + .min_kver ="6.12" ,
With this you are masking the problem on older kernels, please do not, as the problem has possible security implications.
Quoted 11 lines
testcases/kernel/syscalls/mount/mount08.c new file +5
-0+ .tags = (const struct tst_tag[]) { + {"linux-git" ,"d80b065bb172" }, + {} + } +};Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 1/1 mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpAdd a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -865,6 +865,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +57 -0
57 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5] mount08.c: Restrict overmounting of ephemeral entities
Hi!
please achieve the v4 given by Cyryil before sending a new patch.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v5] mount08.c: Restrict overmounting of ephemeral entities
Quoted 4 lines · Andrea Cervesato
Hi!
please achieve the v4 given by Cyryil before sending a new patch.
Sorry, the diff not --amend before i format patch. Resent patch v6.
Thansk.
Quoted 2 lines
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/1 mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpAdd a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
--- runtest/syscalls | 1 + testcases/kernel/syscalls/mount/.gitignore | 1 + testcases/kernel/syscalls/mount/mount08.c | 57 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 testcases/kernel/syscalls/mount/mount08.c
runtest/syscalls +1 -0
@@ -865,6 +865,7 @@ mount04 mount04 mount05 mount05 mount06 mount06 mount07 mount07 +mount08 mount08 mount_setattr01 mount_setattr01
testcases/kernel/syscalls/mount/.gitignore +1 -0
@@ -6,3 +6,4 @@ /mount05 /mount06 /mount07 +/mount08
testcases/kernel/syscalls/mount/mount08.c new file +57 -0
57 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6] mount08.c: Restrict overmounting of ephemeral entities
Hi!
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6] mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpHi!
Pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6] mount08.c: Restrict overmounting of ephemeral entities
In reply to Wei Gao via ltpHi Wei, all,
Quoted 4 lines
Add a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172
...
Quoted 28 lines
testcases/kernel/syscalls/mount/mount08.c new file +25
-0@@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Wei Gao <[email protected]> +*/ + +/*\ +* Verify that mount will raise ENOENT if we try to mount on magic links +* under /proc/<pid>/fd/<nr>. +*/ + +#include "tst_test.h" +#include <sys/mount.h> +#include "tst_safe_file_at.h" + +#define MNTPOINT "mntpoint" +#define FOO MNTPOINT "/foo" +#define BAR MNTPOINT "/bar" + +static void run (void ) +{ +char path[PATH_MAX ]; +int fd, proc_fd; + + fd =SAFE_OPEN (FOO ,O_RDONLY |O_NONBLOCK ,0640 ); +
testcases/kernel/syscalls/mount/mount08.c line 35
Quoted 10 lines
testcases/kernel/syscalls/mount/mount08.c new file +10
-0+sprintf (path,"/proc/%d/fd/%d" ,getpid (), fd); + + proc_fd =SAFE_OPENAT (AT_FDCWD , path,O_PATH |O_NOFOLLOW ); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), proc_fd); + +TST_EXP_FAIL ( +mount (BAR , path,"" ,MS_BIND ,0 ), +ENOENT , + "mount(%s)", path
FYI Test is failing on Tumbleweed 6.15.7, can you please have look? mount08.c:32: TFAIL: mount(/proc/130511/fd/4) expected ENOENT: EACCES (13)
As Tumbleweed is very close to mainline kernel it will probably fail on mainline as well. But maybe it's one of few Tumbleweed patches which causes that.
Kind regards,
Petr
Quoted 22 lines
testcases/kernel/syscalls/mount/mount08.c new file +22
-0+ ); + +SAFE_CLOSE (fd); +SAFE_CLOSE (proc_fd); +} + +static void setup (void ) +{ +SAFE_TOUCH (FOO ,0777 ,NULL ); +SAFE_TOUCH (BAR ,0777 ,NULL ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .mntpoint =MNTPOINT , + .tags = (const struct tst_tag []) { + {"linux-git" ,"d80b065bb172" }, + {} + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6] mount08.c: Restrict overmounting of ephemeral entities
Quoted 50 lines
Hi Wei, all,
Quoted 4 lines
Add a new test to verify that mount will raise ENOENT if we try to mount on magic links under /proc/<pid>/fd/<nr>.
Refer to the following kernel commit for more information:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d80b065bb172...
Quoted 28 lines
testcases/kernel/syscalls/mount/mount08.c new file +25
-0@@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024 Wei Gao <[email protected]> +*/ + +/*\ +* Verify that mount will raise ENOENT if we try to mount on magic links +* under /proc/<pid>/fd/<nr>. +*/ + +#include "tst_test.h" +#include <sys/mount.h> +#include "tst_safe_file_at.h" + +#define MNTPOINT "mntpoint" +#define FOO MNTPOINT "/foo" +#define BAR MNTPOINT "/bar" + +static void run (void ) +{ +char path[PATH_MAX ]; +int fd, proc_fd; + + fd =SAFE_OPEN (FOO ,O_RDONLY |O_NONBLOCK ,0640 ); +testcases/kernel/syscalls/mount/mount08.c line 35
Quoted 10 lines
testcases/kernel/syscalls/mount/mount08.c new file +10
-0+sprintf (path,"/proc/%d/fd/%d" ,getpid (), fd); + + proc_fd =SAFE_OPENAT (AT_FDCWD , path,O_PATH |O_NOFOLLOW ); + +sprintf (path,"/proc/%d/fd/%d" ,getpid (), proc_fd); + +TST_EXP_FAIL ( +mount (BAR , path,"" ,MS_BIND ,0 ), +ENOENT , + "mount(%s)", pathFYI Test is failing on Tumbleweed 6.15.7, can you please have look? mount08.c:32: TFAIL: mount(/proc/130511/fd/4) expected ENOENT: EACCES (13)
Quoted 2 lines
As Tumbleweed is very close to mainline kernel it will probably fail on mainline as well. But maybe it's one of few Tumbleweed patches which causes that.
Maybe it's just the environment in openQA, because running on Tumbleweed VM with enabled SELinux it works well on both 6.15.6 and 6.16-rc1.
The same applies to recent error on ioctl_pidfd01:
ioctl_pidfd01.c:28: TFAIL: ioctl(memfd secret, PIDFD_GET_INFO, info) expected EINVAL, EBADF, ENOTTY: EACCES (13)
Kind regards,
Petr
Quoted 25 lines
Kind regards,
PetrQuoted 22 lines
testcases/kernel/syscalls/mount/mount08.c new file +22
-0+ ); + +SAFE_CLOSE (fd); +SAFE_CLOSE (proc_fd); +} + +static void setup (void ) +{ +SAFE_TOUCH (FOO ,0777 ,NULL ); +SAFE_TOUCH (BAR ,0777 ,NULL ); +} + +static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .mntpoint =MNTPOINT , + .tags = (const struct tst_tag []) { + {"linux-git" ,"d80b065bb172" }, + {} + } +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6] mount08.c: Restrict overmounting of ephemeral entities
Quoted 8 lines · Petr Vorel
Quoted 7 lines
Hi Wei, all,
FYI Test is failing on Tumbleweed 6.15.7, can you please have look? mount08.c:32: TFAIL: mount(/proc/130511/fd/4) expected ENOENT: EACCES (13)
As Tumbleweed is very close to mainline kernel it will probably fail on mainline as well. But maybe it's one of few Tumbleweed patches which causes that.
Quoted 8 lines
Maybe it's just the environment in openQA, because running on Tumbleweed VM with enabled SELinux it works well on both 6.15.6 and 6.16-rc1.
The same applies to recent error on
ioctl_pidfd01:
ioctl_pidfd01.c:28: TFAIL:ioctl(memfd secret, PIDFD_GET_INFO, info)expected EINVAL, EBADF, ENOTTY: EACCES (13)Kind regards,
Petr
Will check this, thanks for notification.
Quoted 4 lines
Quoted 3 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp