All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/1] creat09: Run on all_filesystems
@ 2021-10-14 15:35 Petr Vorel
  2021-10-14 15:45 ` Martin Doucha
  0 siblings, 1 reply; 2+ messages in thread
From: Petr Vorel @ 2021-10-14 15:35 UTC (permalink / raw)
  To: ltp

To make sure bug on XFS is detected on systems which use it.

Due setgid is test problematic on Microsoft filesystems:

creat09.c:81: TBROK: ntfs: Setgid bit not set
creat09.c:76: TBROK: chown(exfat,65533,4) failed: EPERM (1)
creat09.c:76: TBROK: chown(vfat,65533,4) failed: EPERM (1)

thus they're disabled.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/kernel/syscalls/creat/creat09.c | 57 +++++++++++++++++------
 1 file changed, 43 insertions(+), 14 deletions(-)

diff --git a/testcases/kernel/syscalls/creat/creat09.c b/testcases/kernel/syscalls/creat/creat09.c
index 681b80c7d..04f92ba21 100644
--- a/testcases/kernel/syscalls/creat/creat09.c
+++ b/testcases/kernel/syscalls/creat/creat09.c
@@ -33,15 +33,20 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <pwd.h>
+#include <stdio.h>
 #include "tst_test.h"
 #include "tst_uid.h"
 
 #define MODE_RWX        0777
 #define MODE_SGID       (S_ISGID|0777)
 
-#define WORKDIR		"testdir"
-#define CREAT_FILE	WORKDIR "/creat.tmp"
-#define OPEN_FILE	WORKDIR "/open.tmp"
+#define MNTPOINT	"mntpoint"
+#define CREAT_FILE	"creat.tmp"
+#define OPEN_FILE	"open.tmp"
+
+static char *workdir;
+static char *creat_file;
+static char *open_file;
 
 static gid_t free_gid;
 static int fd = -1;
@@ -51,21 +56,32 @@ static void setup(void)
 	struct stat buf;
 	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
+	SAFE_CHDIR(MNTPOINT);
+
 	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)ltpuser->pw_uid,
 		(int)ltpuser->pw_gid);
 	free_gid = tst_get_free_gid(ltpuser->pw_gid);
 
 	/* Create directories and set permissions */
-	SAFE_MKDIR(WORKDIR, MODE_RWX);
-	SAFE_CHOWN(WORKDIR, ltpuser->pw_uid, free_gid);
-	SAFE_CHMOD(WORKDIR, MODE_SGID);
-	SAFE_STAT(WORKDIR, &buf);
+	workdir = SAFE_MALLOC(strlen(tst_device->fs_type) + 1);
+	sprintf(workdir, "%s", tst_device->fs_type);
+
+	creat_file = SAFE_MALLOC(strlen(workdir) + strlen(CREAT_FILE) + 2);
+	sprintf(creat_file, "%s/%s", workdir, CREAT_FILE);
+
+	open_file = SAFE_MALLOC(strlen(tst_device->fs_type) + strlen(OPEN_FILE) + 2);
+	sprintf(open_file, "%s/%s", workdir, OPEN_FILE);
+
+	SAFE_MKDIR(workdir, MODE_RWX);
+	SAFE_CHOWN(workdir, ltpuser->pw_uid, free_gid);
+	SAFE_CHMOD(workdir, MODE_SGID);
+	SAFE_STAT(workdir, &buf);
 
 	if (!(buf.st_mode & S_ISGID))
-		tst_brk(TBROK, "%s: Setgid bit not set", WORKDIR);
+		tst_brk(TBROK, "%s: Setgid bit not set", workdir);
 
 	if (buf.st_gid != free_gid) {
-		tst_brk(TBROK, "%s: Incorrect group, %u != %u", WORKDIR,
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", workdir,
 			buf.st_gid, free_gid);
 	}
 
@@ -95,20 +111,24 @@ static void file_test(const char *name)
 
 static void run(void)
 {
-	fd = SAFE_CREAT(CREAT_FILE, MODE_SGID);
+	fd = SAFE_CREAT(creat_file, MODE_SGID);
 	SAFE_CLOSE(fd);
-	file_test(CREAT_FILE);
+	file_test(creat_file);
 
-	fd = SAFE_OPEN(OPEN_FILE, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
-	file_test(OPEN_FILE);
+	fd = SAFE_OPEN(open_file, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
+	file_test(open_file);
 	SAFE_CLOSE(fd);
 
 	/* Cleanup between loops */
-	tst_purge_dir(WORKDIR);
+	tst_purge_dir(workdir);
 }
 
 static void cleanup(void)
 {
+	free(workdir);
+	free(creat_file);
+	free(open_file);
+
 	if (fd >= 0)
 		SAFE_CLOSE(fd);
 }
@@ -119,6 +139,15 @@ static struct tst_test test = {
 	.cleanup = cleanup,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.skip_filesystems = (const char*[]) {
+		"exfat",
+		"ntfs",
+		"vfat",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "0fa3ecd87848"},
 		{"CVE", "2018-13405"},
-- 
2.33.0


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

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

* Re: [LTP] [PATCH 1/1] creat09: Run on all_filesystems
  2021-10-14 15:35 [LTP] [PATCH 1/1] creat09: Run on all_filesystems Petr Vorel
@ 2021-10-14 15:45 ` Martin Doucha
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Doucha @ 2021-10-14 15:45 UTC (permalink / raw)
  To: Petr Vorel, ltp

Hi,

On 14. 10. 21 17:35, Petr Vorel wrote:
> To make sure bug on XFS is detected on systems which use it.
> 
> Due setgid is test problematic on Microsoft filesystems:
> 
> creat09.c:81: TBROK: ntfs: Setgid bit not set
> creat09.c:76: TBROK: chown(exfat,65533,4) failed: EPERM (1)
> creat09.c:76: TBROK: chown(vfat,65533,4) failed: EPERM (1)
> 
> thus they're disabled.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/kernel/syscalls/creat/creat09.c | 57 +++++++++++++++++------
>  1 file changed, 43 insertions(+), 14 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/creat/creat09.c b/testcases/kernel/syscalls/creat/creat09.c
> index 681b80c7d..04f92ba21 100644
> --- a/testcases/kernel/syscalls/creat/creat09.c
> +++ b/testcases/kernel/syscalls/creat/creat09.c
> @@ -33,15 +33,20 @@
>  #include <stdlib.h>
>  #include <sys/types.h>
>  #include <pwd.h>
> +#include <stdio.h>
>  #include "tst_test.h"
>  #include "tst_uid.h"
>  
>  #define MODE_RWX        0777
>  #define MODE_SGID       (S_ISGID|0777)
>  
> -#define WORKDIR		"testdir"
> -#define CREAT_FILE	WORKDIR "/creat.tmp"
> -#define OPEN_FILE	WORKDIR "/open.tmp"
> +#define MNTPOINT	"mntpoint"
> +#define CREAT_FILE	"creat.tmp"
> +#define OPEN_FILE	"open.tmp"
> +
> +static char *workdir;
> +static char *creat_file;
> +static char *open_file;
>  
>  static gid_t free_gid;
>  static int fd = -1;
> @@ -51,21 +56,32 @@ static void setup(void)
>  	struct stat buf;
>  	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
>  
> +	SAFE_CHDIR(MNTPOINT);
> +
>  	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)ltpuser->pw_uid,
>  		(int)ltpuser->pw_gid);
>  	free_gid = tst_get_free_gid(ltpuser->pw_gid);
>  
>  	/* Create directories and set permissions */
> -	SAFE_MKDIR(WORKDIR, MODE_RWX);
> -	SAFE_CHOWN(WORKDIR, ltpuser->pw_uid, free_gid);
> -	SAFE_CHMOD(WORKDIR, MODE_SGID);
> -	SAFE_STAT(WORKDIR, &buf);
> +	workdir = SAFE_MALLOC(strlen(tst_device->fs_type) + 1);
> +	sprintf(workdir, "%s", tst_device->fs_type);
> +
> +	creat_file = SAFE_MALLOC(strlen(workdir) + strlen(CREAT_FILE) + 2);
> +	sprintf(creat_file, "%s/%s", workdir, CREAT_FILE);
> +
> +	open_file = SAFE_MALLOC(strlen(tst_device->fs_type) + strlen(OPEN_FILE) + 2);
> +	sprintf(open_file, "%s/%s", workdir, OPEN_FILE);
> +
> +	SAFE_MKDIR(workdir, MODE_RWX);
> +	SAFE_CHOWN(workdir, ltpuser->pw_uid, free_gid);
> +	SAFE_CHMOD(workdir, MODE_SGID);
> +	SAFE_STAT(workdir, &buf);

You do not need to do any of this. Simply prefix WORDKIR with MNTPOINT:

-#define WORKDIR	"testdir"
+#define MNTPOINT	"mntpoint"
+#define WORKDIR	MNTPOINT "/testdir"

-- 
Martin Doucha   mdoucha@suse.cz
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

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

end of thread, other threads:[~2021-10-14 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-14 15:35 [LTP] [PATCH 1/1] creat09: Run on all_filesystems Petr Vorel
2021-10-14 15:45 ` Martin Doucha

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.