security/dirtyc0w_shmem: Fix remaining cases where UFFD_FEATURE_MINOR_SHMEM is absent
PATCH 1/1 security/dirtyc0w_shmem: Fix remaining cases where UFFD_FEATURE_MINOR_SHMEM is absent
When UFFD_FEATURE_MINOR_SHMEM is not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test if UFFD_FEATURE_MINOR_SHMEM is really returned by the UFFD_API ioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.
--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +12 -4
@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif -#ifdef UFFD_FEATURE_MINOR_SHMEM -#define TST_NO_DEFAULT_MAIN #include "tst_test.h" #include "tst_safe_macros.h" #include "tst_safe_pthread.h" + +#ifdef UFFD_FEATURE_MINOR_SHMEM #include "lapi/syscalls.h" #define TMP_DIR "tmp_dirtyc0w_shmem"
@@ -162,6 +162,10 @@ retry: "Could not create userfault file descriptor"); } +if (!(uffdio_api.features &UFFD_FEATURE_MINOR_SHMEM )) +tst_brk (TCONF , +"System does not have userfaultfd minor fault support for shmem" ); + uffdio_register.range.start = (unsigned long ) map; uffdio_register.range.len = page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MINOR ;
@@ -236,6 +240,10 @@ int main(void) return 0; }#else /* UFFD_FEATURE_MINOR_SHMEM */ -#include "tst_test.h" -TST_TEST_TCONF ("System does not have userfaultfd minor fault support for shmem" ); +int main (void ) +{ +tst_reinit (); +TST_CHECKPOINT_WAKE (0 ); +tst_brk (TCONF ,"System does not have userfaultfd minor fault support for shmem" ); +}#endif /* UFFD_FEATURE_MINOR_SHMEM */
Signature · 5 lines
2.38.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi David,
Quoted 19 lines
When
UFFD_FEATURE_MINOR_SHMEMis not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test ifUFFD_FEATURE_MINOR_SHMEMis really returned by theUFFD_APIioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.Reported-by Martin Doucha <[email protected]>Cc Petr Vorel <[email protected]>Cc Cyril Hrubis <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-0
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c line 27
Quoted 4 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-1@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif -#ifdef UFFD_FEATURE_MINOR_SHMEM
Shouldn't be the check and TST_TEST_TCONF() actually be in dirtyc0w_shmem.c? I overlooked that, but IMHO test does not make sense at all if UFFD_FEATURE_MINOR_SHMEM not defined, right?
Also Martin noted that ("The parent process should not even fork() when UFFD_FEATURE_MINOR_SHMEM is not defined in config.h.").
Therefore one fix would be to move the check to parent and second (maybe better in separate commit) to add check for uffdio_api.features.
Kind regards,
Petr
Quoted 34 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +12
-3-#define TST_NO_DEFAULT_MAIN #include "tst_test.h" #include "tst_safe_macros.h" #include "tst_safe_pthread.h" + +#ifdef UFFD_FEATURE_MINOR_SHMEM #include "lapi/syscalls.h" #define TMP_DIR "tmp_dirtyc0w_shmem"@@ -162,6 +162,10 @@ retry: "Could not create userfault file descriptor"); } +if (!(uffdio_api.features &UFFD_FEATURE_MINOR_SHMEM )) +tst_brk (TCONF , +"System does not have userfaultfd minor fault support for shmem" ); + uffdio_register.range.start = (unsigned long ) map; uffdio_register.range.len = page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MINOR ;@@ -236,6 +240,10 @@ int main(void) return 0; }#else /* UFFD_FEATURE_MINOR_SHMEM */ -#include "tst_test.h" -TST_TEST_TCONF ("System does not have userfaultfd minor fault support for shmem" ); +int main (void ) +{ +tst_reinit (); +TST_CHECKPOINT_WAKE (0 ); +tst_brk (TCONF ,"System does not have userfaultfd minor fault support for shmem" ); +}#endif /* UFFD_FEATURE_MINOR_SHMEM */
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 24 lines · Petr Vorel
Hi David,
Quoted 21 lines
When
UFFD_FEATURE_MINOR_SHMEMis not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test ifUFFD_FEATURE_MINOR_SHMEMis really returned by theUFFD_APIioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.Reported-by Martin Doucha <[email protected]>Cc Petr Vorel <[email protected]>Cc Cyril Hrubis <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-0@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif
Quoted 8 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c line 27
Quoted 1 line
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-1-#ifdef UFFD_FEATURE_MINOR_SHMEM Shouldn't be the check and
TST_TEST_TCONF()actually be indirtyc0w_shmem.c? I overlooked that, but IMHO test does not make sense at all ifUFFD_FEATURE_MINOR_SHMEMnot defined, right?Also Martin noted that ("The parent process should not even
fork()whenUFFD_FEATURE_MINOR_SHMEMis not defined inconfig.h.").
I tried that first, but then we can still run into the runtime absence of UFFD_FEATURE_MINOR_SHMEM. Checking that also in the parent resulted in some IMHO unpleasant code while I worked on that.
This is certainly the easiest approach, because we still have to make the child program compile either way.
Anyhow, I'll do whatever you decide, because I want to cross this off my list. So any guidance on how to complete this would be appreciated.
Signature · 7 lines
Thanks, David / dhildenb -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 34 lines · Petr Vorel
Quoted 24 lines
Hi David,
Quoted 21 lines
When
UFFD_FEATURE_MINOR_SHMEMis not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test ifUFFD_FEATURE_MINOR_SHMEMis really returned by theUFFD_APIioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.Reported-by Martin Doucha <[email protected]>Cc Petr Vorel <[email protected]>Cc Cyril Hrubis <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-0@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif Quoted 7 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c line 27
Quoted 1 line
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +0
-1-#ifdef UFFD_FEATURE_MINOR_SHMEM Shouldn't be the check and
TST_TEST_TCONF()actually be indirtyc0w_shmem.c? I overlooked that, but IMHO test does not make sense at all ifUFFD_FEATURE_MINOR_SHMEMnot defined, right?Also Martin noted that ("The parent process should not even
fork()whenUFFD_FEATURE_MINOR_SHMEMis not defined inconfig.h.").
Quoted 6 lines
I tried that first, but then we can still run into the runtime absence of
UFFD_FEATURE_MINOR_SHMEM. Checking that also in the parent resulted in some IMHO unpleasant code while I worked on that.This is certainly the easiest approach, because we still have to make the child program compile either way.
Right, it needs to be in child. Using TST_TEST_TCONF() also in master does not look to me as too unpleasant code, but take it just a suggestion. Obviously the only requirement is code compiles and works on both defined and undefined UFFD_FEATURE_MINOR_SHMEM.
Quoted 2 lines
Anyhow, I'll do whatever you decide, because I want to cross this off my list. So any guidance on how to complete this would be appreciated.
Understand.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
Quoted 47 lines · David Hildenbrand
When
UFFD_FEATURE_MINOR_SHMEMis not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test ifUFFD_FEATURE_MINOR_SHMEMis really returned by theUFFD_APIioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.Reported-by Martin Doucha <[email protected]>Cc Petr Vorel <[email protected]>Cc Cyril Hrubis <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +6
-2@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif -#ifdef UFFD_FEATURE_MINOR_SHMEM -#define TST_NO_DEFAULT_MAIN #include "tst_test.h" #include "tst_safe_macros.h" #include "tst_safe_pthread.h" + +#ifdef UFFD_FEATURE_MINOR_SHMEM #include "lapi/syscalls.h" #define TMP_DIR "tmp_dirtyc0w_shmem"@@ -162,6 +162,10 @@ retry: "Could not create userfault file descriptor"); } +if (!(uffdio_api.features &UFFD_FEATURE_MINOR_SHMEM )) +tst_brk (TCONF , +"System does not have userfaultfd minor fault support for shmem" ); + uffdio_register.range.start = (unsigned long ) map; uffdio_register.range.len = page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MINOR ;@@ -236,6 +240,10 @@ int main(void)return 0 ; }
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c int main(void) · line 249
Quoted 10 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +6
-2#else /* UFFD_FEATURE_MINOR_SHMEM */ -#include "tst_test.h" -TST_TEST_TCONF ("System does not have userfaultfd minor fault support for shmem" ); +int main (void ) +{ +tst_reinit (); +TST_CHECKPOINT_WAKE (0 ); +tst_brk (TCONF ,"System does not have userfaultfd minor fault support for shmem" ); +}#endif /* UFFD_FEATURE_MINOR_SHMEM */
This would work as a workaround but I'd recommend adding the necessary structures and constants to include/lapi/userfaultfd.h instead. Then you won't need this conditional compilation at all.
I also recommend looking at the fuzzy sync library we use for race conditions:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#133-reproducing-race-conditions
The original dirtyc0w test was written before this library but using it generally makes race condition reproducers faster, simpler and more reliable.
Signature · 11 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 56 lines · Martin Doucha
Hi,
Quoted 53 lines · David Hildenbrand
When
UFFD_FEATURE_MINOR_SHMEMis not defined, we still have to make the checkpoint happy, otherwise our parent process will run into a timeout. Further, we have to test ifUFFD_FEATURE_MINOR_SHMEMis really returned by theUFFD_APIioctl: if the kernel knows about the feature but doesn't support it, it will be masked off.Reported-by Martin Doucha <[email protected]>Cc Petr Vorel <[email protected]>Cc Cyril Hrubis <[email protected]>Signed-off-by David Hildenbrand <[email protected]>--- .../dirtyc0w_shmem/dirtyc0w_shmem_child.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +9
-4@@ -24,12 +24,12 @@#include <linux/userfaultfd.h> #endif -#ifdef UFFD_FEATURE_MINOR_SHMEM -#define TST_NO_DEFAULT_MAIN #include "tst_test.h" #include "tst_safe_macros.h" #include "tst_safe_pthread.h" + +#ifdef UFFD_FEATURE_MINOR_SHMEM #include "lapi/syscalls.h" #define TMP_DIR "tmp_dirtyc0w_shmem"@@ -162,6 +162,10 @@ retry: "Could not create userfault file descriptor"); } +if (!(uffdio_api.features &UFFD_FEATURE_MINOR_SHMEM )) +tst_brk (TCONF , +"System does not have userfaultfd minor fault support for shmem" ); + uffdio_register.range.start = (unsigned long ) map; uffdio_register.range.len = page_size; uffdio_register.mode =UFFDIO_REGISTER_MODE_MINOR ;@@ -236,6 +240,10 @@ int main(void) return 0; }#else /* UFFD_FEATURE_MINOR_SHMEM */ -#include "tst_test.h" -TST_TEST_TCONF ("System does not have userfaultfd minor fault support for shmem" ); +int main (void ) +{ +tst_reinit ();
Quoted 8 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c int main(void) · line 249
Quoted 4 lines
testcases/kernel/security/dirtyc0w_shmem/dirtyc0w_shmem_child.c +3
-0+TST_CHECKPOINT_WAKE (0 ); + tst_brk(TCONF, "System does not have userfaultfd minor fault support for shmem"); +}#endif /* UFFD_FEATURE_MINOR_SHMEM */ This would work as a workaround but I'd recommend adding the necessary structures and constants to
include/lapi/userfaultfd.hinstead. Then you won't need this conditional compilation at all.
That seems to work as well, although I'm still a bit unsure what to include in that file, what not, what to strip, ...
I'll use include/lapi/io_uring.h as an orientation but will most probably mess it up on the first attempt.
Quoted 5 lines
I also recommend looking at the fuzzy sync library we use for race conditions:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#133-reproducing-race-conditions
I'll look into that as well.
Quoted 3 lines
The original dirtyc0w test was written before this library but using it generally makes race condition reproducers faster, simpler and more reliable.
Thanks
Signature · 7 lines
Thanks, David / dhildenb -- Mailing list info: https://lists.linux.it/listinfo/ltp