Skip to contentSkip to conversation

chdir01: Fix on more restrictive umask

PATCH In review Cyril Hrubis 2 participants 3 messages Jan 11, 2022 – Jan 12, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 chdir01: Fix on more restrictive umask

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.

---
 testcases/kernel/syscalls/chdir/chdir01.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
testcases/kernel/syscalls/chdir/chdir01.c +7 -3
index aa25adf6a..c7902376d 100644
@@ -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,
Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!
Pushed, thanks for the review and testing.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp