All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 1/2] syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE'
@ 2017-12-08 14:07 Punit Agrawal
  2017-12-08 14:07 ` [LTP] [PATCH v4 2/2] getdtablesize01: Handle ENFILE errno Punit Agrawal
  2017-12-11 13:17 ` [LTP] [PATCH v4 1/2] syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE' Cyril Hrubis
  0 siblings, 2 replies; 6+ messages in thread
From: Punit Agrawal @ 2017-12-08 14:07 UTC (permalink / raw)
  To: ltp

When testing the MS_NOSUID mount flag, mount03 forgets to copy
setuid_test into the new filesystem. Instead it writes 'TEST FILE' into
a new file and attempts to execute it with S_ISUID. This fails, but not
for the reasons ltp expects.

Fix this by copying the test helper binary instead.

While we're touching the test, also rename the helper to
mount03_setuid_test so as to follow current ltp convention.

Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
---
Changes since v3:
* Dropped the duplicate TST_RESOURCE_COPY()
* Moved setting SUID_MODE to setup()

 testcases/kernel/syscalls/mount/mount03.c          | 26 +++++++++++++---------
 .../mount/{setuid_test.c => mount03_setuid_test.c} |  0
 2 files changed, 15 insertions(+), 11 deletions(-)
 rename testcases/kernel/syscalls/mount/{setuid_test.c => mount03_setuid_test.c} (100%)

diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
index bf78c797f..6603fb77a 100644
--- a/testcases/kernel/syscalls/mount/mount03.c
+++ b/testcases/kernel/syscalls/mount/mount03.c
@@ -261,15 +261,7 @@ int test_rwflag(int i, int cnt)
 	case 5:
 		/* Validate MS_NOSUID flag of mount call */
 
-		snprintf(file, PATH_MAX, "%ssetuid_test", path_name);
-		SAFE_FILE_PRINTF(cleanup, file, "TEST FILE");
-
-		SAFE_STAT(cleanup, file, &file_stat);
-
-		if (file_stat.st_mode != SUID_MODE &&
-		    chmod(file, SUID_MODE) < 0)
-			tst_brkm(TBROK, cleanup,
-				 "setuid for setuid_test failed");
+		snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name);
 
 		pid = fork();
 		switch (pid) {
@@ -291,9 +283,8 @@ int test_rwflag(int i, int cnt)
 				/* reset the setup_uid */
 				if (status)
 					return 0;
-				else
-					return 1;
 			}
+			return 1;
 		}
 	case 6:
 		/* Validate MS_NOATIME flag of mount call */
@@ -346,6 +337,7 @@ int test_rwflag(int i, int cnt)
 static void setup(void)
 {
 	char path[PATH_MAX];
+	struct stat file_stat;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
@@ -373,6 +365,18 @@ static void setup(void)
 	strncpy(path, path_name, PATH_MAX);
 	snprintf(path_name, PATH_MAX, "%s/%s/", path, mntpoint);
 
+	SAFE_MOUNT(cleanup, device, mntpoint, fs_type, 0, NULL);
+	TST_RESOURCE_COPY(cleanup, "mount03_setuid_test", path_name);
+
+	snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name);
+	SAFE_STAT(cleanup, file, &file_stat);
+
+	if (file_stat.st_mode != SUID_MODE &&
+	    chmod(file, SUID_MODE) < 0)
+		tst_brkm(TBROK, cleanup,
+			 "setuid for setuid_test failed");
+	SAFE_UMOUNT(cleanup, mntpoint);
+
 	TEST_PAUSE;
 }
 
diff --git a/testcases/kernel/syscalls/mount/setuid_test.c b/testcases/kernel/syscalls/mount/mount03_setuid_test.c
similarity index 100%
rename from testcases/kernel/syscalls/mount/setuid_test.c
rename to testcases/kernel/syscalls/mount/mount03_setuid_test.c
-- 
2.15.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-20 11:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-08 14:07 [LTP] [PATCH v4 1/2] syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE' Punit Agrawal
2017-12-08 14:07 ` [LTP] [PATCH v4 2/2] getdtablesize01: Handle ENFILE errno Punit Agrawal
2017-12-11 13:18   ` Cyril Hrubis
2017-12-20 10:55     ` Punit Agrawal
2017-12-20 11:07       ` Cyril Hrubis
2017-12-11 13:17 ` [LTP] [PATCH v4 1/2] syscalls/mount03: Copy setuid_test to execute instead of 'TEST FILE' Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.