chdir01.c: set umask to 0 within setup
PATCH 1/1 chdir01.c: set umask to 0 within setup
When system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)
--- testcases/kernel/syscalls/chdir/chdir01.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/chdir/chdir01.c +8 -3
@@ -56,12 +56,15 @@ static struct test_case {static void setup (void ) { +mode_t old_umask =umask (0 ); + +SAFE_MKFS (tst_device->dev, tst_device->fs_type,NULL ,NULL ); +SAFE_MOUNT (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,0 ); +char *cwd;int fd;struct stat statbuf; -umask (0 ); - cwd =SAFE_GETCWD (NULL ,0 ); workdir =SAFE_MALLOC (strlen (cwd) +strlen (MNTPOINT ) +2 );sprintf (workdir,"%s/%s" , cwd,MNTPOINT );
@@ -89,6 +92,7 @@ static void setup(void)if (!ltpuser) ltpuser =SAFE_GETPWNAM (TESTUSER ); +umask (old_umask); } static void check_result(const char *user, const char *name, int retval,
@@ -146,13 +150,14 @@ static void cleanup(void) {SAFE_CHDIR (".." );free (workdir); +SAFE_UMOUNT (MNTPOINT ); }static struct tst_test test = { .needs_root =1 , - .mount_device =1 , .mntpoint =MNTPOINT , .all_filesystems =1 , + .needs_device =1 , .test = run, .tcnt =ARRAY_SIZE (testcase_list), .setup = setup,
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value inside safe_mount().
Quoted 54 lines · Wei Gao via ltp
When system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody:chdir("subdir")returned unexpected value -1: EACCES (13)Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/chdir/chdir01.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)testcases/kernel/syscalls/chdir/chdir01.c +8
-3@@ -56,12 +56,15 @@ static struct test_case {static void setup (void ) { +mode_t old_umask =umask (0 ); + +SAFE_MKFS (tst_device->dev, tst_device->fs_type,NULL ,NULL );Hi, +SAFE_MOUNT (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,0 ); +char *cwd;int fd;struct stat statbuf; -umask (0 ); - cwd =SAFE_GETCWD (NULL ,0 ); workdir =SAFE_MALLOC (strlen (cwd) +strlen (MNTPOINT ) +2 );sprintf (workdir,"%s/%s" , cwd,MNTPOINT );@@ -89,6 +92,7 @@ static void setup(void)if (!ltpuser) ltpuser =SAFE_GETPWNAM (TESTUSER ); +umask (old_umask); } static void check_result(const char *user, const char *name, int retval,@@ -146,13 +150,14 @@ static void cleanup(void) {SAFE_CHDIR (".." );free (workdir); +SAFE_UMOUNT (MNTPOINT ); }static struct tst_test test = { .needs_root =1 , - .mount_device =1 , .mntpoint =MNTPOINT , .all_filesystems =1 , + .needs_device =1 , .test = run, .tcnt =ARRAY_SIZE (testcase_list), .setup = setup,
Signature · 11 lines
Martin Doucha [email protected] SW Quality Engineer 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 4 lines · Martin Doucha
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value insidesafe_mount().
Thanks for your feedback.
For chdir case i just use Petr's below suggestion(Detail info you can check patch link in below):
"2) tests, which set .mount_device = 1 and have more restrictive umask will not work. Workaround would be to not use it and mount manually in the setup(). Or, reset umask with umask(0)."
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
BTW: for similar issues we also do fix within test file in stead of lib such as:
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 9 lines
Signature · 7 lines
Martin Doucha [email protected] SW Quality Engineer SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 8 lines · Wei Gao
Quoted 4 lines · Martin Doucha
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value insidesafe_mount().Thanks for your feedback.
Quoted 8 lines
For chdir case i just use Petr's below suggestion(Detail info you can check patch link in below):
"2) tests, which set .mount_device = 1 and have more restrictive umask will not work. Workaround would be to not use it and mount manually in the
setup(). Or, reset umask with umask(0)."https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
I'd rather avoid mounting in setup unless you need to set special mount parameters.
Mount-time umask does not matter for most filesystem. The exception are vfat and exfat which don't have any internal concept of access permissions and instead you need to either pass mount options that'll define access permissions for all files and directories, otherwise current process umask value will be used as the default.
So resetting umask to 0 before mount and restoring immediately after is perfectly safe. But we should later fix it properly by implementing per-filesystem mount options.
Signature · 11 lines
Martin Doucha [email protected] SW Quality Engineer 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 18 lines · Wei Gao
Quoted 8 lines · Martin Doucha
Quoted 4 lines
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value insidesafe_mount().Thanks for your feedback.
Quoted 8 lines
For chdir case i just use Petr's below suggestion(Detail info you can check patch link in below):
"2) tests, which set .mount_device = 1 and have more restrictive umask will not work. Workaround would be to not use it and mount manually in the
setup(). Or, reset umask with umask(0)."https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/
Quoted 8 lines
I'd rather avoid mounting in setup unless you need to set special mount parameters.
Mount-time umask does not matter for most filesystem. The exception are vfat and exfat which don't have any internal concept of access permissions and instead you need to either pass mount options that'll define access permissions for all files and directories, otherwise current process umask value will be used as the default.
+1
Quoted 3 lines
So resetting umask to 0 before mount and restoring immediately after is perfectly safe. But we should later fix it properly by implementing per-filesystem mount options.
Yeah, I was thinking about it, but haven't implement it yet because not many tests need it and it can be mostly workarounded. Do you know tests (beside this one) which need it?
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Martin, all,
Quoted 4 lines
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value insidesafe_mount().
This makes sense. FYI Wei first tried to adjust umask globally for all tests in the do_setup() [1], which I worried it would influence tests.
Later Li fixed problem in cgroup tests [2]. This is obviously more general solution, Wei please send a patch for it and to the commit message
While we are fixing issues caused by too restrictive umask (Wei fixed e.g. statx07 [3]), just to let you know that some failures are kernel failures (at least creat09 which uses all_filesystems, had bug on XFS [4], which got fixed in the kernel).
Kind regards,
Petr
[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://github.com/linux-test-project/ltp/commit/50626b4a1d01caacd418156ec997853bd4a9fc39
[3] https://github.com/linux-test-project/ltp/commit/d95f453ac624dc159d3acddb62eadeb9a8215f0e
[4] https://lore.kernel.org/ltp/[email protected]/
Quoted 50 lines · Wei Gao via ltp
Quoted 49 lines
When system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody:chdir("subdir")returned unexpected value -1: EACCES (13)Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/syscalls/chdir/chdir01.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)testcases/kernel/syscalls/chdir/chdir01.c +8
-3@@ -56,12 +56,15 @@ static struct test_case {static void setup (void ) { +mode_t old_umask =umask (0 ); + +SAFE_MKFS (tst_device->dev, tst_device->fs_type,NULL ,NULL );Hi, +SAFE_MOUNT (tst_device->dev,MNTPOINT , tst_device->fs_type,0 ,0 ); +char *cwd;int fd;struct stat statbuf; -umask (0 ); - cwd =SAFE_GETCWD (NULL ,0 ); workdir =SAFE_MALLOC (strlen (cwd) +strlen (MNTPOINT ) +2 );sprintf (workdir,"%s/%s" , cwd,MNTPOINT );@@ -89,6 +92,7 @@ static void setup(void)if (!ltpuser) ltpuser =SAFE_GETPWNAM (TESTUSER ); +umask (old_umask); } static void check_result(const char *user, const char *name, int retval,@@ -146,13 +150,14 @@ static void cleanup(void) {SAFE_CHDIR (".." );free (workdir); +SAFE_UMOUNT (MNTPOINT ); }static struct tst_test test = { .needs_root =1 , - .mount_device =1 , .mntpoint =MNTPOINT , .all_filesystems =1 , + .needs_device =1 , .test = run, .tcnt =ARRAY_SIZE (testcase_list), .setup = setup,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines
Hi Martin, all,
Quoted 4 lines
Hi,
you're trying to fix a vfat mount quirk. We should fix that in the LTP library instead, e.g. by setting umask(0) and then restoring the original value insidesafe_mount().This makes sense. FYI Wei first tried to adjust umask globally for all tests in the
do_setup()[1], which I worried it would influence tests.
Also, it would be good to update:
https://github.com/linux-test-project/ltp/wiki/C-Test-API#21-umask
Kind regards,
Petr
Quoted 16 lines
Later Li fixed problem in cgroup tests [2]. This is obviously more general solution, Wei please send a patch for it and to the commit message
Suggested-by Martin Doucha <[email protected]>While we are fixing issues caused by too restrictive umask (Wei fixed e.g. statx07 [3]), just to let you know that some failures are kernel failures (at least creat09 which uses
all_filesystems, had bug on XFS [4], which got fixed in the kernel).Kind regards,
Petr[1] https://lore.kernel.org/ltp/[email protected]/
[2] https://github.com/linux-test-project/ltp/commit/50626b4a1d01caacd418156ec997853bd4a9fc39
[3] https://github.com/linux-test-project/ltp/commit/d95f453ac624dc159d3acddb62eadeb9a8215f0e
[4] https://lore.kernel.org/ltp/[email protected]/
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 safe_macros.c: set umask to 0 within safe_mount
In reply to Wei Gao via ltpWhen system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody: chdir("subdir") returned unexpected value -1: EACCES (13)
--- doc/C-Test-API.asciidoc | 4 +++- lib/safe_macros.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)
doc/C-Test-API.asciidoc +3 -1
@@ -2460,7 +2460,9 @@ with 'open()' or 'creat()' etc, the mode specified as the last parameter *is not* the mode the file is created with. The mode depends on current 'umask()' settings which may clear some of the bits. If your test depends on specific file permissions you need either to change umask to 0 or 'chmod()' the file -afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. +afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. SAFE_MOUNT +also does similar action such as setting umask(0) and then restoring the +original value. 2.2 access() ~~~~~~~~~~~~
lib/safe_macros.c +3 -0
@@ -913,7 +913,10 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),* the kernel's NTFS driver doesn't have proper write support. */ if (!filesystemtype ||strcmp (filesystemtype,"ntfs" )) { +mode_t old_umask =umask (0 ); + rval =mount (source, target, filesystemtype, mountflags, data); +umask (old_umask);if (!rval)return 0 ; }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2] safe_macros.c: set umask to 0 within safe_mount
Hi Wei, all,
Quoted 16 lines
When system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody:chdir("subdir")returned unexpected value -1: EACCES (13)Suggested-by Martin Doucha <[email protected]>Signed-off-by Wei Gao <[email protected]>--- doc/C-Test-API.asciidoc | 4 +++- lib/safe_macros.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)doc/C-Test-API.asciidoc +0
-0
doc/C-Test-API.asciidoc with 'open()' or 'creat()' etc, the mode specified as the last parameter *is · line 2463
Quoted 5 lines
doc/C-Test-API.asciidoc +1
-1@@ -2460,7 +2460,9 @@ with 'open()' or 'creat()' etc, the mode specified as the last parameter *is not* the mode the file is created with. The mode depends on current 'umask()' settings which may clear some of the bits. If your test depends on specific file permissions you need either to change umask to 0 or 'chmod()' the file -afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. +afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. SAFE_MOUNT
s/SAFE_MOUNT/'SAFE_MOUNT()'/
doc/C-Test-API.asciidoc with 'open()' or 'creat()' etc, the mode specified as the last parameter *is · line 2465
Quoted 2 lines
doc/C-Test-API.asciidoc +2
-0+also does similar action such as setting umask(0) and then restoring the +original value.
I'm not sure about the wording. Maybe:
Temporarily clearing umask with 'umask(0)' is done before mounting in 'SAFE_MOUNT()' and before creating a new subdir in the cgroup in 'cgroup_dir_mk()'.
(based on my patch
https://lore.kernel.org/ltp/[email protected]/).
It could be changed before merge.
Kind regards,
Petr
Quoted 17 lines
doc/C-Test-API.asciidoc +0
-02.2 access() ~~~~~~~~~~~~lib/safe_macros.c +3
-0@@ -913,7 +913,10 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),* the kernel's NTFS driver doesn't have proper write support. */ if (!filesystemtype ||strcmp (filesystemtype,"ntfs" )) { +mode_t old_umask =umask (0 ); + rval =mount (source, target, filesystemtype, mountflags, data); +umask (old_umask);if (!rval)return 0 ; }
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2] safe_macros.c: set umask to 0 within safe_mount
In reply to Wei Gao via ltpHi,
the doc change is not needed. For the lib change alone:
Quoted 40 lines · Wei Gao
When system's default umask is 0077, this will trigger following issues:
chdir01.c:100: TFAIL: nobody:chdir("subdir")returned unexpected value -1: EACCES (13)Suggested-by Martin Doucha <[email protected]>Signed-off-by Wei Gao <[email protected]>--- doc/C-Test-API.asciidoc | 4 +++- lib/safe_macros.c | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-)doc/C-Test-API.asciidoc +3
-1@@ -2460,7 +2460,9 @@ with 'open()' or 'creat()' etc, the mode specified as the last parameter *is not* the mode the file is created with. The mode depends on current 'umask()' settings which may clear some of the bits. If your test depends on specific file permissions you need either to change umask to 0 or 'chmod()' the file -afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. +afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you. SAFE_MOUNT +also does similar action such as setting umask(0) and then restoring the +original value. 2.2 access() ~~~~~~~~~~~~lib/safe_macros.c +3
-0@@ -913,7 +913,10 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),* the kernel's NTFS driver doesn't have proper write support. */ if (!filesystemtype ||strcmp (filesystemtype,"ntfs" )) { +mode_t old_umask =umask (0 ); + rval =mount (source, target, filesystemtype, mountflags, data); +umask (old_umask);if (!rval)return 0 ; }
Signature · 11 lines
Martin Doucha [email protected] SW Quality Engineer 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
Re: [LTP] [PATCH v2] safe_macros.c: set umask to 0 within safe_mount
Hi Martin, Wei,
Quoted 2 lines
Hi,
the doc change is not needed. For the lib change alone:
+1. Merged only change in the library, reworded commit message.
Thanks to both!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp