diff mbox series

chdir01: Fix on more restrictive umask

Message ID 20220111103628.9055-1-chrubis@suse.cz
State Accepted
Headers show
Series chdir01: Fix on more restrictive umask | expand

Commit Message

Cyril Hrubis Jan. 11, 2022, 10:36 a.m. UTC
Fixes the test on more restrictive umask, this was found on FIPS but
it's not limited to the FIPS system at all. All that is needed to
reproduce the problem is to set umask to 077 before the test is
executed.

The troublemaker here is the FAT filesystem since there are no access
bits defined in FAT disk format and they are emulated completely by the
kernel. This means that all files on FAT filesytem have access bits
generated by the kernel accordingly to system umask at the time the
filesystem was mounted. This means that in order to be able to access
the files on FAT we have to set the umask(0) before we mount the
filesystem.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 testcases/kernel/syscalls/chdir/chdir01.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Petr Vorel Jan. 11, 2022, 12:41 p.m. UTC | #1
Hi Cyril,

thanks a lot for this fix!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Tested-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr
Cyril Hrubis Jan. 12, 2022, 10:01 a.m. UTC | #2
Hi!
Pushed, thanks for the review and testing.
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
index aa25adf6a..c7902376d 100644
--- a/testcases/kernel/syscalls/chdir/chdir01.c
+++ b/testcases/kernel/syscalls/chdir/chdir01.c
@@ -50,16 +50,18 @@  static void setup(void)
 	int fd;
 	struct stat statbuf;
 
+	umask(0);
+
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+
 	cwd = SAFE_GETCWD(NULL, 0);
 	workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2);
 	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
 	free(cwd);
 	SAFE_CHDIR(workdir);
 
-	mode_t sys_umask = umask(0);
 	SAFE_MKDIR(DIR_NAME, 0755);
 	SAFE_MKDIR(BLOCKED_NAME, 0644);
-	umask(sys_umask);
 
 	/* FAT and NTFS override file and directory permissions */
 	SAFE_STAT(BLOCKED_NAME, &statbuf);
@@ -132,12 +134,14 @@  static void run(unsigned int n)
 
 static void cleanup(void)
 {
+	SAFE_CHDIR("..");
+	tst_umount(workdir);
 	free(workdir);
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
-	.mount_device = 1,
+	.format_device = 1,
 	.mntpoint = MNTPOINT,
 	.all_filesystems = 1,
 	.test = run,