Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests
@ 2025-04-14 20:09 Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
                   ` (7 more replies)
  0 siblings, 8 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

If needed, you can find this series available here:

https://git.marliere.net/ltp/ltp/

`git clone --branch conversions/mknod --single-branch https://git.marliere.net/ltp/ltp/`

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
Changes in v3:
- mknod03:
	Fixed test description alignment
	Removed an outdated comment (CVE)
	Made functions static
	Moved setgid() and setreuid() calls to setup()
	Rename TST_DIR and TST_NODE to TEMP_*
- Also refactored remaining mknod tests
- Link to v2: https://lore.kernel.org/r/20250321-conversions-mknod-v2-1-c9c27bde5b07@suse.com

Changes in v2:
- Made use of TST_EXP_EQ_LI
- Moved test tmp directory creation into setup()
- Removed now unneeded orig_uid
- Link to v1: https://lore.kernel.org/r/20250319-conversions-mknod-v1-1-f46e763d7200@suse.com

---
Ricardo B. Marlière (8):
      syscalls/mknod01: Fix checkpatch.pl warnings
      syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
      syscalls/mknod03: Convert to new API
      syscalls/mknod04: Convert to new API
      syscalls/mknod05: Convert to new API
      syscalls/mknod06: Convert to new API
      syscalls/mknod07: Convert to new API
      syscalls/mknod08: Convert to new API

 testcases/kernel/syscalls/mknod/mknod01.c |   5 +-
 testcases/kernel/syscalls/mknod/mknod02.c |   4 +-
 testcases/kernel/syscalls/mknod/mknod03.c | 314 ++++-------------------------
 testcases/kernel/syscalls/mknod/mknod04.c | 319 ++++--------------------------
 testcases/kernel/syscalls/mknod/mknod05.c | 285 ++++----------------------
 testcases/kernel/syscalls/mknod/mknod06.c | 301 ++++------------------------
 testcases/kernel/syscalls/mknod/mknod07.c | 209 ++++++--------------
 testcases/kernel/syscalls/mknod/mknod08.c | 312 ++++-------------------------
 8 files changed, 261 insertions(+), 1488 deletions(-)
---
base-commit: e0ff0da58267959e4a13ff7b7038106976ed24ab
change-id: 20250319-conversions-mknod-cd8cb407d24d

Best regards,
-- 
Ricardo B. Marlière <rbm@suse.com>


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

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

* [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-22 10:52   ` Petr Vorel
  2025-04-14 20:09 ` [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Fix the following warnings:

	Alignment should match open parenthesis
	Please don't use multiple blank lines

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod01.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod01.c b/testcases/kernel/syscalls/mknod/mknod01.c
index fe0a1cfa6a473f9c2b2a55493f830f13b86560a8..39e402ee412de39c7929dcae65fdf3e302de9b45 100644
--- a/testcases/kernel/syscalls/mknod/mknod01.c
+++ b/testcases/kernel/syscalls/mknod/mknod01.c
@@ -26,7 +26,6 @@ static int tcases[] = {
 	S_IFREG | 06700,
 };
 
-
 static void run(unsigned int i)
 {
 	dev_t dev = 0;
@@ -35,8 +34,8 @@ static void run(unsigned int i)
 		dev = makedev(1, 3);
 
 	TST_EXP_PASS(mknod(PATH, tcases[i], dev),
-				"mknod(PATH, %o, %ld)",
-				tcases[i], dev);
+		     "mknod(PATH, %o, %ld)",
+		     tcases[i], dev);
 	SAFE_UNLINK(PATH);
 }
 

-- 
2.49.0


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

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

* [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-22 13:06   ` Petr Vorel
  2025-04-14 20:09 ` [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod02.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod02.c b/testcases/kernel/syscalls/mknod/mknod02.c
index 89dd1d8740234b788554e625e693693b954440cc..bd476fff79cdde9073dd49664f6fd32031f9d966 100644
--- a/testcases/kernel/syscalls/mknod/mknod02.c
+++ b/testcases/kernel/syscalls/mknod/mknod02.c
@@ -20,7 +20,7 @@
 #define MODE_SGID	02000
 
 #define TEMP_DIR "testdir"
-#define TEMP_NODE "testnode"
+#define TEMP_NODE TEMP_DIR "/testnode"
 
 static struct stat buf;
 static struct passwd *user_nobody;
@@ -37,14 +37,12 @@ static void setup(void)
 
 static void run(void)
 {
-	SAFE_CHDIR(TEMP_DIR);
 	TST_EXP_PASS(mknod(TEMP_NODE, MODE1, 0), "mknod(%s, %o, 0)", TEMP_NODE, MODE1);
 
 	SAFE_STAT(TEMP_NODE, &buf);
 	TST_EXP_EQ_LI(buf.st_gid, 0);
 
 	SAFE_UNLINK(TEMP_NODE);
-	SAFE_CHDIR("..");
 }
 
 static struct tst_test test = {

-- 
2.49.0


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

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

* [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-22 14:02   ` Petr Vorel
  2025-04-14 20:09 ` [LTP] [PATCH v3 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod03.c | 314 ++++--------------------------
 1 file changed, 41 insertions(+), 273 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod03.c b/testcases/kernel/syscalls/mknod/mknod03.c
index 7ecadb5b37c3ab7eded90aa8a6d1e27f07236b1f..1bc9f7e8587ed3c34b00f82e959bcca19063b545 100644
--- a/testcases/kernel/syscalls/mknod/mknod03.c
+++ b/testcases/kernel/syscalls/mknod/mknod03.c
@@ -1,296 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- * Test Name: mknod03
- *
- * Test Description:
- *  Verify that mknod(2) succeeds when used to create a filesystem
- *  node with set group-ID bit set on a directory with set group-ID bit set.
- *  The node created should have set group-ID bit set and its gid should be
- *  equal to the effective gid of the process.
- *
- * Expected Result:
- *  mknod() should return value 0 on success and node created should have
- *  set group-ID bit set, its gid should be equal to the effective gid of
- *  the process.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  mknod03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * Verify that mknod(2) succeeds when used to create a filesystem node with
+ * set-group-ID bit set on a directory with set-group-ID bit set. The node
+ * created should have set-group-ID bit set and its gid should be equal to
+ * the "nobody" gid.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define LTPUSER		"nobody"
-#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
-#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
-#define DIR_TEMP	"testdir_3"
-#define TNODE		"tnode_%d"
+#include "tst_uid.h"
+#include "tst_test.h"
 
-struct stat buf;		/* struct. to hold stat(2) o/p contents */
-struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
+#define MODE_RWX 0777
+#define MODE_SGID 2777
 
-char *TCID = "mknod03";
-int TST_TOTAL = 1;
-char node_name[PATH_MAX];	/* buffer to hold node name created */
+#define TEMP_DIR "testdir"
+#define TEMP_NODE TEMP_DIR "/testnode"
 
-gid_t group1_gid, group2_gid, mygid;	/* user and process group id's */
-uid_t save_myuid, user1_uid;	/* user and process user id's */
-pid_t mypid;			/* process id */
+static uid_t nobody_uid;
+static gid_t nobody_gid, free_gid;
 
-void setup();			/* setup function for the test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	int fflag;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	struct stat buf;
 
-		tst_count = 0;
+	SAFE_STAT(TEMP_DIR, &buf);
+	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
 
-		/*
-		 *  Attempt to create a filesystem node with group id (sgid)
-		 *  bit set on a directory with group id (sgid) bit set
-		 *  such that, the node created by mknod(2) should have
-		 *  group id (sgid) bit set and node's gid should be equal
-		 *  to that of effective gid of the process.
-		 */
-		TEST(mknod(node_name, MODE_SGID, 0));
+	SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
 
-		/* Check return code from mknod(2) */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "mknod(%s, %#o, 0)  failed, errno=%d : "
-				 "%s", node_name, MODE_SGID, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			continue;
-		}
-		/* Set the functionality flag */
-		fflag = 1;
+	SAFE_STAT(TEMP_NODE, &buf);
+	TST_EXP_EQ_LI(buf.st_gid, free_gid);
 
-		/* Check for node's creation */
-		if (stat(node_name, &buf) < 0) {
-			tst_resm(TFAIL, "stat() of %s failed, errno:%d",
-				 node_name, TEST_ERRNO);
-			/* unset functionality flag */
-			fflag = 0;
-		}
-
-		/*
-		 * Skip S_ISGID check
-		 * 0fa3ecd87848 ("Fix up non-directory creation in SGID directories")
-		 * clears S_ISGID for files created by non-group members
-		 */
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group",
-				 node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-		if (fflag) {
-			tst_resm(TPASS, "Functionality of mknod(%s, "
-				 "%#o, 0) successful",
-				 node_name, MODE_SGID);
-		}
-
-		/* Remove the node for the next go `round */
-		if (unlink(node_name) == -1) {
-			tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
-				 node_name, errno, strerror(errno));
-		}
-	}
-
-	/* Change the directory back to temporary directory */
-	SAFE_CHDIR(cleanup, "..");
-
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup() and exit main().
-	 */
-	cleanup();
-
-	tst_exit();
+	SAFE_UNLINK(TEMP_NODE);
 }
 
-/*
- * setup(void) - performs all ONE TIME setup for this test.
- * 	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory used to hold test directories created
- *	and change the directory to it.
- *	Verify that pid of process executing the test is root.
- *	Create a test directory on temporary directory and set the ownership
- *	of test directory to guest user and process, change mode permissions
- *	to set group id bit on it.
- *	Set the effective uid/gid of the process to that of guest user.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	TEST_PAUSE;
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	free_gid = tst_get_free_gid(nobody_gid);
 
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
+	SAFE_MKDIR(TEMP_DIR, MODE_RWX);
+	SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
+	SAFE_CHMOD(TEMP_DIR, MODE_SGID);
 
-	/* fix permissions on the tmpdir */
-	if (chmod(".", 0711) != 0) {
-		tst_brkm(TBROK, cleanup, "chmod() failed");
-	}
-
-	/* Save the real user id of the current test process */
-	save_myuid = getuid();
-	/* Save the process id of the current test process */
-	mypid = getpid();
-
-	/* Get the node name to be created in the test */
-	sprintf(node_name, TNODE, mypid);
-
-	/* Get the uid/gid of ltpuser user */
-	if ((user1 = getpwnam(LTPUSER)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
-	}
-	user1_uid = user1->pw_uid;
-	group1_gid = user1->pw_gid;
-
-	/* Get the effective group id of the test process */
-	group2_gid = getegid();
-
-	/*
-	 * Create a test directory under temporary directory with the
-	 * specified mode permissions, with uid/gid set to that of guest
-	 * user and the test process.
-	 */
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
-	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
-
-	/*
-	 * Verify that test directory created with expected permission modes
-	 * and ownerships.
-	 */
-	SAFE_STAT(cleanup, DIR_TEMP, &buf);
-
-	/* Verify modes of test directory */
-	if (!(buf.st_mode & S_ISGID)) {
-		tst_brkm(TBROK, cleanup,
-			 "%s: Incorrect modes, setgid bit not set", DIR_TEMP);
-	}
-
-	/* Verify group ID of test directory */
-	if (buf.st_gid != group2_gid) {
-		tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
-	}
-
-	/*
-	 * Set the effective group id and user id of the test process
-	 * to that of guest user (nobody)
-	 */
-	SAFE_SETGID(cleanup, group1_gid);
-	if (setreuid(-1, user1_uid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process uid to that of ltp user");
-	}
-
-	/* Save the real group ID of the current process */
-	mygid = getgid();
-
-	/* Change directory to DIR_TEMP */
-	SAFE_CHDIR(cleanup, DIR_TEMP);
+	SAFE_SETGID(nobody_gid);
+	SAFE_SETREUID(-1, nobody_uid);
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Restore the real/effective user id of the process changed during
- *	setup().
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Restore the effective uid of the process changed in the
-	 * setup().
-	 */
-	if (setreuid(-1, save_myuid) < 0) {
-		tst_brkm(TBROK, NULL,
-			 "resetting process real/effective uid failed");
-	}
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};

-- 
2.49.0


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

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

* [LTP] [PATCH v3 4/8] syscalls/mknod04: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (2 preceding siblings ...)
  2025-04-14 20:09 ` [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-22 14:06   ` Petr Vorel
  2025-04-14 20:09 ` [LTP] [PATCH v3 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod04.c | 319 ++++--------------------------
 1 file changed, 40 insertions(+), 279 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod04.c b/testcases/kernel/syscalls/mknod/mknod04.c
index e0123ec07d95887a5fb8ab730103ba9531d4783d..637dd4f8dfd113a81f48489a221b850c57418249 100644
--- a/testcases/kernel/syscalls/mknod/mknod04.c
+++ b/testcases/kernel/syscalls/mknod/mknod04.c
@@ -1,301 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- * Test Name: mknod04
- *
- * Test Description:
- *  Verify that mknod(2) succeeds when used to create a filesystem
- *  node on a directory with set group-ID bit set.
- *  The node created should not have group-ID bit set and its gid should be
- *  equal to the effective gid of the process.
- *
- * Expected Result:
- *  mknod() should return value 0 on success and node created should not
- *  have set group-ID bit set and its gid should be equal to the effective
- *  gid of the process.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  mknod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * Verify that mknod(2) succeeds when used to create a filesystem node on a
+ * directory with set-group-ID bit set. The node created should not have
+ * set-group-ID bit set and its gid should be equal to the effective
+ * gid of the process.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define LTPUSER		"nobody"
-#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
-#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
-#define DIR_TEMP	"testdir_4"
-#define TNODE		"tnode_%d"
+#include "tst_uid.h"
+#include "tst_test.h"
 
-struct stat buf;		/* struct. to hold stat(2) o/p contents */
-struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
+#define MODE_RWX 0777
+#define MODE_SGID 2777
 
-char *TCID = "mknod04";
-int TST_TOTAL = 1;
-char node_name[PATH_MAX];	/* buffer to hold node name created */
+#define TEMP_DIR "testdir"
+#define TEMP_NODE TEMP_DIR "/testnode"
 
-gid_t group1_gid, group2_gid, mygid;	/* user and process group id's */
-uid_t save_myuid, user1_uid;	/* user and process user id's */
-pid_t mypid;			/* process id */
+static uid_t nobody_uid;
+static gid_t nobody_gid, free_gid;
 
-void setup();			/* setup function for the test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	int fflag;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	struct stat buf;
 
-		/*
-		 * TEST CASE CONDITION:
-		 *  Attempt to create a filesystem node on a directory
-		 *  with group id (sgid) bit set such that,
-		 *  the node created by mknod(2) should not have group id
-		 *  (sgid) bit set and node's gid should be equal to the
-		 *  effective gid of the process.
-		 */
-		TEST(mknod(node_name, MODE_RWX, 0));
+	SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
 
-		/* Check return code from mknod(2) */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "mknod(%s, %#o, 0)  failed, errno=%d : "
-				 "%s", node_name, MODE_RWX, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			continue;
-		}
-		/* Set the functionality flag */
-		fflag = 1;
+	SAFE_STAT(TEMP_NODE, &buf);
+	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
+	TST_EXP_EQ_LI(buf.st_gid, free_gid);
 
-		/* Check for node's creation */
-		if (stat(node_name, &buf) < 0) {
-			tst_resm(TFAIL, "stat() of %s failed, errno:%d",
-				 node_name, TEST_ERRNO);
-			/* unset fflag */
-			fflag = 0;
-		}
-
-		/* Verify mode permissions of node */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid "
-				 "bit set", node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-
-		/* Verify group ID of node */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group",
-				 node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-		if (fflag) {
-			tst_resm(TPASS, "Functionality of mknod(%s, "
-				 "%#o, 0) successful",
-				 node_name, MODE_RWX);
-		}
-
-		/* Remove the node for the next go `round */
-		if (unlink(node_name) == -1) {
-			tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
-				 node_name, errno, strerror(errno));
-		}
-	}
-
-	/* Change the directory back to temporary directory */
-	SAFE_CHDIR(cleanup, "..");
-
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup() and exit main().
-	 */
-	cleanup();
-
-	tst_exit();
+	SAFE_UNLINK(TEMP_NODE);
 }
 
-/*
- * void
- * setup(void) - performs all ONE TIME setup for this test.
- *	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory used to hold test directories created
- *	and change the directory to it.
- *	Verify that pid of process executing the test is root.
- *	Create a test directory on temporary directory and set the ownership
- *	of test directory to guest user and process, change mode permissions
- *	to set group-id bit on it.
- *	Set the effective uid/gid of the process to that of guest user.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	TEST_PAUSE;
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	free_gid = tst_get_free_gid(nobody_gid);
 
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
+	SAFE_MKDIR(TEMP_DIR, MODE_RWX);
+	SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
+	SAFE_CHMOD(TEMP_DIR, MODE_SGID);
 
-	/* fix permissions on the tmpdir */
-	if (chmod(".", 0711) != 0) {
-		tst_brkm(TBROK, cleanup, "chmod() failed");
-	}
-
-	/* Save the real user id of the current test process */
-	save_myuid = getuid();
-
-	/* Save the process id of the current test process */
-	mypid = getpid();
-
-	/* Get the node name to be created in the test */
-	sprintf(node_name, TNODE, mypid);
-
-	/* Get the uid/gid of ltp user */
-	if ((user1 = getpwnam(LTPUSER)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
-	}
-	user1_uid = user1->pw_uid;
-	group1_gid = user1->pw_gid;
-
-	/* Get the effective group id of the test process */
-	group2_gid = getegid();
-
-	/*
-	 * Create a test directory under temporary directory with the
-	 * specified mode permissions, with uid/gid set to that of guest
-	 * user and the test process.
-	 */
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
-	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
-
-	/*
-	 * Verify that test directory created with expected permission modes
-	 * and ownerships.
-	 */
-	SAFE_STAT(cleanup, DIR_TEMP, &buf);
-
-	/* Verify modes of test directory */
-	if (!(buf.st_mode & S_ISGID)) {
-		tst_brkm(TBROK, cleanup,
-			 "%s: Incorrect modes, setgid bit not set", DIR_TEMP);
-	}
-
-	/* Verify group ID */
-	if (buf.st_gid != group2_gid) {
-		tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
-	}
-
-	/*
-	 * Set the effective group id and user id of the test process
-	 * to that of guest user (nobody)
-	 */
-	SAFE_SETGID(cleanup, group1_gid);
-	if (setreuid(-1, user1_uid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process uid to that of ltp user");
-	}
-
-	/* Save the real group ID of the current process */
-	mygid = getgid();
-
-	/* Change directory to DIR_TEMP */
-	SAFE_CHDIR(cleanup, DIR_TEMP);
+	SAFE_SETGID(nobody_gid);
+	SAFE_SETREUID(-1, nobody_uid);
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Restore the real/effective user id of the process changed during
- *	setup().
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Restore the effective uid of the process changed in the
-	 * setup().
-	 */
-	if (setreuid(-1, save_myuid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "resetting process real/effective uid failed");
-	}
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};

-- 
2.49.0


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

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

* [LTP] [PATCH v3 5/8] syscalls/mknod05: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (3 preceding siblings ...)
  2025-04-14 20:09 ` [LTP] [PATCH v3 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-25 15:30   ` Cyril Hrubis
  2025-04-14 20:09 ` [LTP] [PATCH v3 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod05.c | 285 ++++--------------------------
 1 file changed, 38 insertions(+), 247 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod05.c b/testcases/kernel/syscalls/mknod/mknod05.c
index fbc5575403665803beb7f34b1da155e2224b4f20..c225516cda468ca6773a8806c49cfd0fff267068 100644
--- a/testcases/kernel/syscalls/mknod/mknod05.c
+++ b/testcases/kernel/syscalls/mknod/mknod05.c
@@ -1,268 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- * Test Name: mknod05
- *
- * Test Description:
- *  Verify that mknod(2) succeeds when used by root to create a filesystem
- *  node with set group-ID bit set on a directory with set group-ID bit set.
- *  The node created should have set group-ID bit set and its gid should be
- *  equal to that of its parent directory.
- *
- * Expected Result:
- *  mknod() should return value 0 on success and node created should have
- *  set group-ID bit set and its gid should be equal to that of its parent
- *  directory.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  mknod05 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * Verify that mknod(2) succeeds when used to create a filesystem node with
+ * set group-ID bit set on a directory with set group-ID bit set. The node
+ * created should have set group-ID bit set and its gid should be equal to
+ * that of its parent directory.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define LTPUSER		"nobody"
-#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
-#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
-#define DIR_TEMP	"testdir_5"
-#define TNODE		"tnode_%d"
+#include "tst_uid.h"
+#include "tst_test.h"
 
-struct stat buf;		/* struct. to hold stat(2) o/p contents */
-struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
+#define MODE_RWX 0777
+#define MODE_SGID 2777
 
-char *TCID = "mknod05";
-int TST_TOTAL = 1;
-char node_name[PATH_MAX];	/* buffer to hold node name created */
+#define TEMP_DIR "testdir"
+#define TEMP_NODE TEMP_DIR "/testnode"
 
-gid_t group1_gid, group2_gid, mygid;	/* user and process group id's */
-uid_t save_myuid, user1_uid;	/* user and process user id's */
-pid_t mypid;			/* process id */
+static uid_t nobody_uid;
+static gid_t nobody_gid, free_gid;
 
-void setup();			/* setup function for the test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	int fflag;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	struct stat buf;
 
-		tst_count = 0;
+	SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
 
-		/*
-		 *  Attempt to create a filesystem node with group id (sgid)
-		 *  bit set on a directory with group id (sgid) bit set
-		 *  such that, the node created by mknod(2) should have
-		 *  group id (sgid) bit set and node's gid should be equal
-		 *  to that of effective gid of the process.
-		 */
-		TEST(mknod(node_name, MODE_SGID, 0));
+	SAFE_STAT(TEMP_NODE, &buf);
+	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
+	TST_EXP_EQ_LI(buf.st_gid, free_gid);
 
-		/* Check return code from mknod(2) */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "mknod(%s, %#o, 0)  failed, errno=%d : "
-				 "%s", node_name, MODE_SGID, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			continue;
-		}
-		/* Set the functionality flag */
-		fflag = 1;
-
-		/* Check for node's creation */
-		if (stat(node_name, &buf) < 0) {
-			tst_resm(TFAIL, "stat() of %s failed, errno:%d",
-				 node_name, TEST_ERRNO);
-			/* unset functionality flag */
-			fflag = 0;
-		}
-
-		/* Verify mode permissions of node */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL, "%s: Incorrect modes, "
-				 "setgid bit not set", node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group",
-				 node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-		if (fflag) {
-			tst_resm(TPASS, "Functionality of mknod(%s, "
-				 "%#o, 0) successful",
-				 node_name, MODE_SGID);
-		}
-
-		/* Remove the node for the next go `round */
-		if (unlink(node_name) == -1) {
-			tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
-				 node_name, errno, strerror(errno));
-		}
-	}
-
-	/* change the directory back to temporary directory */
-	SAFE_CHDIR(cleanup, "..");
-
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup() and exit main().
-	 */
-	cleanup();
-
-	tst_exit();
+	SAFE_UNLINK(TEMP_NODE);
 }
 
-/*
- * setup(void) - performs all ONE TIME setup for this test.
- * 	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory used to hold test directories created
- *	and change the directory to it.
- *	Verify that pid of process executing the test is root.
- *	Create a test directory on temporary directory and set the ownership
- *	of test directory to guest user and process, change mode permissions
- *	to set group id bit on it.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
-
-	/* Save the real user id of the current test process */
-	save_myuid = getuid();
-
-	/* Save the process id of the current test process */
-	mypid = getpid();
-
-	/* Get the node name to be created in the test */
-	sprintf(node_name, TNODE, mypid);
-
-	/* Get the uid/gid of ltp user */
-	if ((user1 = getpwnam(LTPUSER)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
-	}
-	user1_uid = user1->pw_uid;
-	group1_gid = user1->pw_gid;
-
-	/* Get the effective group id of the test process */
-	group2_gid = getegid();
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	/*
-	 * Create a test directory under temporary directory with the
-	 * specified mode permissions, with uid/gid set to that of guest
-	 * user and the test process.
-	 */
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
-	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_SGID);
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	free_gid = tst_get_free_gid(nobody_gid);
 
-	/*
-	 * Verify that test directory created with expected permission modes
-	 * and ownerships.
-	 */
-	SAFE_STAT(cleanup, DIR_TEMP, &buf);
-	/* Verify modes of test directory */
-	if (!(buf.st_mode & S_ISGID)) {
-		tst_brkm(TBROK, cleanup,
-			 "%s: Incorrect modes, setgid bit not set", DIR_TEMP);
-	}
-
-	/* Verify group ID of test directory */
-	if (buf.st_gid != group2_gid) {
-		tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
-	}
-
-	/* Change directory to DIR_TEMP */
-	SAFE_CHDIR(cleanup, DIR_TEMP);
+	SAFE_MKDIR(TEMP_DIR, MODE_RWX);
+	SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
+	SAFE_CHMOD(TEMP_DIR, MODE_SGID);
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};

-- 
2.49.0


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

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

* [LTP] [PATCH v3 6/8] syscalls/mknod06: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (4 preceding siblings ...)
  2025-04-14 20:09 ` [LTP] [PATCH v3 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
  7 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod06.c | 301 +++++-------------------------
 1 file changed, 43 insertions(+), 258 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c
index 8f70cf07a260a4709242e67a8c3df983936eb63e..6691e0c6746ec5679a4c5b38101ceba799665c41 100644
--- a/testcases/kernel/syscalls/mknod/mknod06.c
+++ b/testcases/kernel/syscalls/mknod/mknod06.c
@@ -1,280 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- * Test Name: mknod06
- *
- * Test Description:
- * Verify that,
- *   1) mknod(2) returns -1 and sets errno to EEXIST if specified path
- *	already exists.
- *   2) mknod(2) returns -1 and sets errno to EFAULT if pathname points
- *	outside user's accessible address space.
- *   3) mknod(2) returns -1 and sets errno to ENOENT if the directory
- *	component in pathname does not exist.
- *   4) mknod(2) returns -1 and sets errno to ENAMETOOLONG if the pathname
- *	component was too long.
- *   5) mknod(2) returns -1 and sets errno to ENOTDIR if the directory
- *	component in pathname is not a directory.
- *
- * Expected Result:
- *  mknod() should fail with return value -1 and set expected errno.
+/*\
+ * Verify that mknod(2) fails with the correct error codes:
  *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	if errno set == expected errno
- *   		Issue sys call fails with expected return value and errno.
- *   	Otherwise,
- *		Issue sys call fails with unexpected errno.
- *   Otherwise,
- *	Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  mknod06 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be executed by super-user (root) only.
+ * - ENAMETOOLONG if the pathname component was too long.
+ * - EEXIST if specified path already exists.
+ * - EFAULT if pathname points outside user's accessible address space.
+ * - ENOENT if the directory component in pathname does not exist.
+ * - ENOENT if the pathname is empty.
+ * - ENOTDIR if the directory component in pathname is not a directory.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <sys/mman.h>
+#include "tst_test.h"
 
-#include "test.h"
+#define MODE_FIFO_RWX 0010777
 
-#define MODE_RWX		S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
+static char *longpathname;
 
-int setup1();			/* setup function to test mknod for EEXIST */
-int setup3();			/* setup function to test mknod for ENOTDIR */
-int longpath_setup();		/* setup function to test mknod for ENAMETOOLONG */
-int no_setup();			/* simply returns 0 to the caller */
-char Longpathname[PATH_MAX + 2];
-
-struct test_case_t {		/* test case struct. to hold ref. test cond's */
+static struct tcase {
 	char *pathname;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{"tnode_1", "Specified node already exists", EEXIST, setup1}, {
-	NULL, "Invalid address", EFAULT, no_setup}, {
-	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
-	"", "Pathname is empty", ENOENT, no_setup}, {
-	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
-	"tnode/tnode_3", "Path contains regular file", ENOTDIR, setup3}, {
-	NULL, NULL, 0, no_setup}
+} tcases[] = {
+	{ NULL, "Pathname too long", ENAMETOOLONG },
+	{ "tnode_1", "Specified node already exists", EEXIST },
+	{ NULL, "Invalid address", EFAULT },
+	{ "testdir_2/tnode_2", "Non-existent file", ENOENT },
+	{ "", "Pathname is empty", ENOENT },
+	{ "tnode/tnode_3", "Path contains regular file", ENOTDIR },
 };
 
-char *TCID = "mknod06";
-int TST_TOTAL = ARRAY_SIZE(Test_cases);
-
-void setup();			/* setup function for the tests */
-void cleanup();			/* cleanup function for the tests */
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc;
-	char *node_name;	/* ptr. for node name created */
-	char *test_desc;	/* test specific error message */
-	int ind;		/* counter to test different test conditions */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * Invoke setup function to call individual test setup functions
-	 * for the test which run as root/super-user.
-	 */
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-			node_name = Test_cases[ind].pathname;
-			test_desc = Test_cases[ind].desc;
-
-			/*
-			 * Call mknod(2) to test different test conditions.
-			 * verify that it fails with -1 return value and
-			 * sets appropriate errno.
-			 */
-			TEST(mknod(node_name, MODE_RWX, 0));
-
-			/* Check return code from mknod(2) */
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL,
-					 "mknod() returned %ld, expected "
-					 "-1, errno:%d", TEST_RETURN,
-					 Test_cases[ind].exp_errno);
-				continue;
-			}
+	struct tcase *tc = &tcases[i];
 
-			if (TEST_ERRNO == Test_cases[ind].exp_errno) {
-				tst_resm(TPASS, "mknod() fails, %s, errno:%d",
-					 test_desc, TEST_ERRNO);
-			} else {
-				tst_resm(TFAIL, "mknod() fails, %s, errno:%d, "
-					 "expected errno:%d", test_desc,
-					 TEST_ERRNO, Test_cases[ind].exp_errno);
-			}
-		}
-
-	}
-
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup().
-	 */
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(mknod(tc->pathname, MODE_FIFO_RWX, 0), tc->exp_errno, "%s",
+		     tc->desc);
 }
 
-/*
- * setup(void) - performs all ONE TIME setup for this test.
- * 	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory used to hold test directories and nodes
- *	created and change the directory to it.
- *	Invoke individual test setup functions according to the order
- *	set in struct. definition.
- */
-void setup(void)
+static void setup(void)
 {
-	int ind;
-
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	SAFE_MKNOD("tnode_1", MODE_FIFO_RWX, 0);
+	SAFE_MKNOD("tnode", MODE_FIFO_RWX, 0);
 
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
-
-	/* call individual setup functions */
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (!Test_cases[ind].pathname)
-			Test_cases[ind].pathname = tst_get_bad_addr(cleanup);
-		Test_cases[ind].setupfunc();
-	}
-}
-
-/*
- * no_setup() - Some test conditions for mknod(2) do not any setup.
- *		Hence, this function just returns 0.
- */
-int no_setup(void)
-{
-	return 0;
-}
-
-/*
- * longpath_setup() - setup to create a node with a name length exceeding
- *		      the MAX. length of PATH_MAX.
- *   This function retruns 0.
- */
-int longpath_setup(void)
-{
-	int ind;		/* counter variable */
-
-	for (ind = 0; ind <= (PATH_MAX + 1); ind++) {
-		Longpathname[ind] = 'a';
-	}
-	return 0;
+	for (int i = 0; i <= (PATH_MAX + 1); i++)
+		longpathname[i] = 'a';
+	tcases[0].pathname = longpathname;
 }
 
-/*
- * setup1() - setup function for a test condition for which mknod(2)
- *	      returns -1 and sets errno to EEXIST.
- *  This function creates a node using mknod(2) and tries to create
- *  same node in the test and fails with above errno.
- *  This function returns 0.
- */
-int setup1(void)
-{
-	/* Create a node using mknod */
-	if (mknod("tnode_1", MODE_RWX, 0) < 0) {
-		tst_brkm(TBROK, cleanup, "Fails to create node in setup1()");
-	}
-
-	return 0;
-}
-
-/*
- * setup3() - setup function for a test condition for which mknod(2)
- *	      returns -1 and sets errno to ENOTDIR.
- *  This function creates a node under temporary directory and the
- *  test attempts to create another node under under this node and fails
- *  with ENOTDIR as the node created here is a regular file.
- *  This function returns 0.
- */
-int setup3(void)
-{
-	/* Create a node using mknod */
-	if (mknod("tnode", MODE_RWX, 0) < 0) {
-		tst_brkm(TBROK, cleanup, "Fails to create node in setup3()");
-	}
-
-	return 0;
-}
-
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_tmpdir = 1,
+	.bufs = (struct tst_buffers[]) {
+		{ &longpathname, .size = PATH_MAX + 2 },
+		{},
+	},
+};

-- 
2.49.0


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

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

* [LTP] [PATCH v3 7/8] syscalls/mknod07: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (5 preceding siblings ...)
  2025-04-14 20:09 ` [LTP] [PATCH v3 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  2025-04-14 20:09 ` [LTP] [PATCH v3 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
  7 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod07.c | 209 +++++++++---------------------
 1 file changed, 59 insertions(+), 150 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod07.c b/testcases/kernel/syscalls/mknod/mknod07.c
index 829199061532fabffb1ba2c892cc8cccfd1d4b6a..13b883c36684bab7bf3933777656f74a057495c6 100644
--- a/testcases/kernel/syscalls/mknod/mknod07.c
+++ b/testcases/kernel/syscalls/mknod/mknod07.c
@@ -1,184 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *   07/2001 Ported by Wayne Boyer
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software Foundation,
- *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- *
- * Test Description:
- * Verify that,
- *   1) mknod(2) returns -1 and sets errno to EPERM if the process id of
- *	the caller is not super-user.
- *   2) mknod(2) returns -1 and sets errno to EACCES if parent directory
- *	does not allow  write  permission  to  the process.
- *   3) mknod(2) returns -1 and sets errno to EROFS if pathname refers to
- *	a file on a read-only file system.
- *   4) mknod(2) returns -1 and sets errno to ELOOP if too many symbolic
- *	links were encountered in resolving pathname.
+/*\
+ * Verify that mknod(2) fails with the correct error codes:
  *
+ * - EACCES if parent directory does not allow write permission to the process.
+ * - EPERM if the process id of the caller is not super-user.
+ * - EROFS if pathname refers to a file on a read-only file system.
+ * - ELOOP if too many symbolic links were encountered in resolving pathname.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
 #include <sys/sysmacros.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
-#define DIR_TEMP		"testdir_1"
-#define DIR_TEMP_MODE		(S_IRUSR | S_IXUSR)
-#define DIR_MODE		(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
-				 S_IXGRP|S_IROTH|S_IXOTH)
-#define MNT_POINT		"mntpoint"
+#define TEMP_MNT "mnt"
+#define TEMP_DIR "testdir"
+#define TEMP_DIR_MODE 0500
 
-#define FIFO_MODE	(S_IFIFO | S_IRUSR | S_IRGRP | S_IROTH)
-#define SOCKET_MODE	(S_IFSOCK | S_IRWXU | S_IRWXG | S_IRWXO)
-#define CHR_MODE	(S_IFCHR | S_IRUSR | S_IWUSR)
-#define BLK_MODE	(S_IFBLK | S_IRUSR | S_IWUSR)
+#define ELOOP_DIR "test_eloop"
+#define ELOOP_FILE "/test_eloop"
+#define ELOOP_DIR_MODE 0755
+#define ELOOP_MAX 43
 
-#define ELOPFILE	"/test_eloop"
+#define FIFO_MODE 0010444
+#define SOCKET_MODE 00140777
+#define CHR_MODE 0020500
+#define BLK_MODE 0060500
 
-static char elooppathname[sizeof(ELOPFILE) * 43] = ".";
+static char *elooppathname;
 
-static const char *device;
-static int mount_flag;
-
-static struct test_case_t {
+static struct tcase {
 	char *pathname;
 	int mode;
 	int exp_errno;
 	int major, minor;
-} test_cases[] = {
-	{ "testdir_1/tnode_1", SOCKET_MODE, EACCES, 0, 0 },
-	{ "testdir_1/tnode_2", FIFO_MODE, EACCES, 0, 0 },
-	{ "tnode_3", CHR_MODE, EPERM, 1, 3 },
-	{ "tnode_4", BLK_MODE, EPERM, 0, 0 },
-	{ "mntpoint/tnode_5", SOCKET_MODE, EROFS, 0, 0 },
-	{ elooppathname, FIFO_MODE, ELOOP, 0, 0 },
+} tcases[] = {
+	{ NULL, FIFO_MODE, ELOOP, 0, 0 },
+	{ TEMP_DIR "/tnode1", SOCKET_MODE, EACCES, 0, 0 },
+	{ TEMP_DIR "/tnode2", FIFO_MODE, EACCES, 0, 0 },
+	{ "tnode3", CHR_MODE, EPERM, 1, 3 },
+	{ "tnode4", BLK_MODE, EPERM, 0, 0 },
+	{ TEMP_MNT "/tnode5", SOCKET_MODE, EROFS, 0, 0 },
 };
 
-char *TCID = "mknod07";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void mknod_verify(const struct test_case_t *test_case);
-static void cleanup(void);
+#define TEST_SIZE ARRAY_SIZE(tcases)
 
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc;
-	int i;
+	struct tcase *tc = &tcases[i];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++)
-			mknod_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(mknod(tc->pathname, tc->mode,
+			   makedev(tc->major, tc->minor)),
+		     tc->exp_errno);
 }
 
 static void setup(void)
 {
-	int i;
-	struct passwd *ltpuser;
-	const char *fs_type;
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_tmpdir();
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
+	SAFE_SETEUID(ltpuser->pw_uid);
+	SAFE_MKDIR(TEMP_DIR, TEMP_DIR_MODE);
 
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to acquire device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	TEST_PAUSE;
-
-	/* mount a read-only file system for EROFS test */
-	SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
-	SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL);
-	mount_flag = 1;
-
-	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
-	SAFE_MKDIR(cleanup, DIR_TEMP, DIR_TEMP_MODE);
+	SAFE_MKDIR(ELOOP_DIR, ELOOP_DIR_MODE);
+	SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop");
 
 	/*
-	 * NOTE: the ELOOP test is written based on that the consecutive
-	 * symlinks limits in kernel is hardwired to 40.
+	 * The kernel limits symlink resolution hop amount to 40,
+	 * create a pathname with more than that
 	 */
-	SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
-	SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
-	for (i = 0; i < 43; i++)
-		strcat(elooppathname, ELOPFILE);
-}
-
-static void mknod_verify(const struct test_case_t *test_case)
-{
-	TEST(mknod(test_case->pathname, test_case->mode,
-		makedev(test_case->major, test_case->minor)));
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "mknod succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test_case->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "mknod failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "mknod failed unexpectedly; expected: "
-			 "%d - %s", test_case->exp_errno,
-			 strerror(test_case->exp_errno));
-	}
+	strcpy(elooppathname, ".");
+	for (int i = 0; i < ELOOP_MAX; i++)
+		strcat(elooppathname, ELOOP_FILE);
+	tcases[0].pathname = elooppathname;
 }
 
-static void cleanup(void)
-{
-	if (seteuid(0) == -1)
-		tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
-	if (mount_flag && tst_umount(MNT_POINT) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mntpoint = TEMP_MNT,
+	.needs_rofs = 1,
+	.bufs = (struct tst_buffers[]){
+		{ &elooppathname, .size = sizeof(ELOOP_FILE) * ELOOP_MAX },
+		{},
+	},
+};

-- 
2.49.0


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

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

* [LTP] [PATCH v3 8/8] syscalls/mknod08: Convert to new API
  2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (6 preceding siblings ...)
  2025-04-14 20:09 ` [LTP] [PATCH v3 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
@ 2025-04-14 20:09 ` Ricardo B. Marlière via ltp
  7 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-14 20:09 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

From: Ricardo B. Marlière <rbm@suse.com>

Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
 testcases/kernel/syscalls/mknod/mknod08.c | 312 ++++--------------------------
 1 file changed, 37 insertions(+), 275 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod08.c b/testcases/kernel/syscalls/mknod/mknod08.c
index 8647fdebb4766151ffd91fd30083389e5def4850..56fd26204ff89aba541663d61067f886b42784fc 100644
--- a/testcases/kernel/syscalls/mknod/mknod08.c
+++ b/testcases/kernel/syscalls/mknod/mknod08.c
@@ -1,296 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
  */
 
-/*
- * Test Name: mknod08
- *
- * Test Description:
- *  Verify that mknod(2) succeeds when used to create a filesystem
- *  node on a directory without set group-ID bit set. The node created
- *  should not have set group-ID bit set and its gid should be equal to that
- *  of its parent directory.
- *
- * Expected Result:
- *  mknod() should return value 0 on success and node created should not
- *  have set group-ID bit set.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  mknod08 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'super-user' (root) only.
- *
+/*\
+ * Verify that mknod(2) succeeds when used to create a filesystem node on a
+ * directory without set group-ID bit set. The node created should not have
+ * set group-ID bit set and its gid should be equal to that of its parent
+ * directory.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define LTPUSER		"nobody"
-#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
-#define DIR_TEMP	"testdir_1"
-#define TNODE		"tnode_%d"
+#include "tst_uid.h"
+#include "tst_test.h"
 
-struct stat buf;		/* struct. to hold stat(2) o/p contents */
-struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
+#define MODE_RWX 0777
 
-char *TCID = "mknod08";
-int TST_TOTAL = 1;
-char node_name[PATH_MAX];	/* buffer to hold node name created */
+#define TEMP_DIR "tempdir"
+#define TEMP_NODE TEMP_DIR "/testnode"
 
-gid_t group1_gid, group2_gid, mygid;	/* user and process group id's */
-uid_t save_myuid, user1_uid;	/* user and process user id's */
-pid_t mypid;			/* process id */
+uid_t nobody_uid;
+gid_t nobody_gid, free_gid;
 
-void setup();			/* setup function for the test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	int fflag;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	struct stat buf;
 
-		/*
-		 * Call mknod() to creat a node on a directory without
-		 * set group-ID (sgid) bit set.
-		 */
-		TEST(mknod(node_name, MODE_RWX, 0));
+	SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
 
-		/* Check return code from mknod(2) */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL,
-				 "mknod(%s, %#o, 0)  failed, errno=%d : %s",
-				 node_name, MODE_RWX, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			continue;
-		}
-		/* Set the functionality flag */
-		fflag = 1;
+	SAFE_STAT(TEMP_NODE, &buf);
+	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
+	TST_EXP_EQ_LI(buf.st_gid, nobody_gid);
 
-		/* Check for node's creation */
-		if (stat(node_name, &buf) < 0) {
-			tst_resm(TFAIL,
-				 "stat() of %s failed, errno:%d",
-				 node_name, TEST_ERRNO);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-
-		/* Verify mode permissions of node */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid "
-				 "bit set", node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != mygid) {
-			tst_resm(TFAIL, "%s: Incorrect group",
-				 node_name);
-			/* unset flag as functionality fails */
-			fflag = 0;
-		}
-		if (fflag) {
-			tst_resm(TPASS, "Functionality of mknod(%s, "
-				 "%#o, 0) successful",
-				 node_name, MODE_RWX);
-		}
-
-		/* Remove the node for the next go `round */
-		if (unlink(node_name) == -1) {
-			tst_resm(TWARN,
-				 "unlink(%s) failed, errno:%d %s",
-				 node_name, errno, strerror(errno));
-		}
-	}
-
-	/* Change the directory back to temporary directory */
-	SAFE_CHDIR(cleanup, "..");
-
-	/*
-	 * Invoke cleanup() to delete the test directories created
-	 * in the setup() and exit main().
-	 */
-	cleanup();
-
-	tst_exit();
+	SAFE_UNLINK(TEMP_NODE);
 }
 
-/*
- * setup(void) - performs all ONE TIME setup for this test.
- *	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory used to hold test directories created
- *	and change the directory to it.
- *	Verify that pid of process executing the test is root.
- *	Create a test directory on temporary directory and set the ownership
- *	of test directory to nobody user.
- *	Set the effective uid/gid of the process to that of nobody user.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	free_gid = tst_get_free_gid(nobody_gid);
 
-	/* fix permissions on the tmpdir */
-	if (chmod(".", 0711) != 0) {
-		tst_brkm(TBROK, cleanup, "chmod() failed");
-	}
-
-	/* Save the real user id of the test process */
-	save_myuid = getuid();
-
-	/* Save the process id of the test process */
-	mypid = getpid();
-
-	/* Get the node name to be created in the test */
-	sprintf(node_name, TNODE, mypid);
-
-	/* Get the uid/gid of guest user - nobody */
-	if ((user1 = getpwnam(LTPUSER)) == NULL) {
-		tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER);
-	}
-	user1_uid = user1->pw_uid;
-	group1_gid = user1->pw_gid;
-
-	/* Get effective group id of the test process */
-	group2_gid = getegid();
-
-	/*
-	 * Create a test directory under temporary directory with the
-	 * specified mode permissions, with uid/gid set to that of guest
-	 * user and the test process.
-	 */
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_CHOWN(cleanup, DIR_TEMP, user1_uid, group2_gid);
-
-	/*
-	 * Verify that test directory created with expected permission modes
-	 * and ownerships.
-	 */
-	SAFE_STAT(cleanup, DIR_TEMP, &buf);
-
-	/* Verify modes of test directory */
-	if (buf.st_mode & S_ISGID) {
-		tst_brkm(TBROK, cleanup,
-			 "%s: Incorrect modes, setgid bit set", DIR_TEMP);
-	}
-
-	/* Verify group ID */
-	if (buf.st_gid != group2_gid) {
-		tst_brkm(TBROK, cleanup, "%s: Incorrect group", DIR_TEMP);
-	}
-
-	/*
-	 * Set the effective group id and user id of the test process
-	 * to that of guest user.
-	 */
-	SAFE_SETGID(cleanup, group1_gid);
-	if (setreuid(-1, user1_uid) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "Unable to set process uid to that of ltp user");
-	}
-
-	/* Save the real group ID of the current process */
-	mygid = getgid();
-
-	/* Change directory to DIR_TEMP */
-	SAFE_CHDIR(cleanup, DIR_TEMP);
+	SAFE_MKDIR(TEMP_DIR, MODE_RWX);
+	SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
+	SAFE_SETGID(nobody_gid);
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Restore the real/effective user id of the process changed during
- *	setup().
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Restore the effective uid of the process changed in the
-	 * setup().
-	 */
-	if (setreuid(-1, save_myuid) < 0) {
-		tst_brkm(TBROK, NULL,
-			 "resetting process real/effective uid failed");
-	}
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};

-- 
2.49.0


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

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

* Re: [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-14 20:09 ` [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
@ 2025-04-22 10:52   ` Petr Vorel
  2025-04-22 12:09     ` Ricardo B. Marlière via ltp
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2025-04-22 10:52 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo,

> Fix the following warnings:

> 	Alignment should match open parenthesis
> 	Please don't use multiple blank lines

I'm not sure how you invoke checkpatch.pl.
Could you please use LTP embedded version via:

$ make check-mknod01

Or, to see what it does use V=1

$ make check-mknod01 V=1

> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
>  testcases/kernel/syscalls/mknod/mknod01.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

> diff --git a/testcases/kernel/syscalls/mknod/mknod01.c b/testcases/kernel/syscalls/mknod/mknod01.c
> index fe0a1cfa6a473f9c2b2a55493f830f13b86560a8..39e402ee412de39c7929dcae65fdf3e302de9b45 100644
> --- a/testcases/kernel/syscalls/mknod/mknod01.c
> +++ b/testcases/kernel/syscalls/mknod/mknod01.c
> @@ -26,7 +26,6 @@ static int tcases[] = {
>  	S_IFREG | 06700,
>  };

> -

This is not reported by our checkpatch.pl and it would be useful. I'm not sure
if you want to bother to look which from these --ignore
CONST_STRUCT,VOLATILE,SPLIT_STRING,FILE_PATH_CHANGES should be removed (or which
one is missing, maybe our checkpatch.pl is outdated).

>  static void run(unsigned int i)
>  {
>  	dev_t dev = 0;
> @@ -35,8 +34,8 @@ static void run(unsigned int i)
>  		dev = makedev(1, 3);

>  	TST_EXP_PASS(mknod(PATH, tcases[i], dev),
> -				"mknod(PATH, %o, %ld)",
> -				tcases[i], dev);
> +		     "mknod(PATH, %o, %ld)",
> +		     tcases[i], dev);

I'm not sure, if this is worth to fix (our checkpatch.pl setup does not report it).

But what would be worth to fix is 32 bit compatibility error on dev_t dev:

$ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig CFLAGS=-m32 LDFLAGS=-m32 ./configure # see INSTALL
...

mknod01.c:37:22: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 6 has type ‘dev_t’ {aka ‘long long unsigned int’} [-Wformat=]
   37 |                      "mknod(PATH, %o, %ld)",
      |                      ^~~~~~~~~~~~~~~~~~~~~~
../../../../include/tst_test_macros.h:42:32: note: in definition of macro ‘TST_FMT_’
   42 | #define TST_FMT_(FMT, _1, ...) FMT, ##__VA_ARGS__
      |                                ^~~
../../../../include/tst_test_macros.h:46:26: note: in expansion of macro ‘TST_2_’
   46 |                 TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__))
      |                          ^~~~~~
../../../../include/tst_test_macros.h:210:25: note: in expansion of macro ‘TST_MSG_’
  210 |                         TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
      |                         ^~~~~~~~
mknod01.c:36:9: note: in expansion of macro ‘TST_EXP_PASS’
   36 |         TST_EXP_PASS(mknod(PATH, tcases[i], dev),
      |         ^~~~~~~~~~~~
mknod01.c:37:41: note: format string is defined here
   37 |                      "mknod(PATH, %o, %ld)",
      |                                       ~~^
      |                                         |
      |                                         long int
      |                                       %lld

(It should be solved by PRIuMAX and casting to (uintmax_t), but we usually just
cast to (long long) and use just %lld. Whatever you prefer.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-22 10:52   ` Petr Vorel
@ 2025-04-22 12:09     ` Ricardo B. Marlière via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-22 12:09 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Linux Test Project

Hello Petr!

On Tue Apr 22, 2025 at 7:52 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
>> Fix the following warnings:
>
>> 	Alignment should match open parenthesis
>> 	Please don't use multiple blank lines
>
> I'm not sure how you invoke checkpatch.pl.
> Could you please use LTP embedded version via:
>
> $ make check-mknod01
>
> Or, to see what it does use V=1
>
> $ make check-mknod01 V=1
>
>> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
>> ---
>>  testcases/kernel/syscalls/mknod/mknod01.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>
>> diff --git a/testcases/kernel/syscalls/mknod/mknod01.c b/testcases/kernel/syscalls/mknod/mknod01.c
>> index fe0a1cfa6a473f9c2b2a55493f830f13b86560a8..39e402ee412de39c7929dcae65fdf3e302de9b45 100644
>> --- a/testcases/kernel/syscalls/mknod/mknod01.c
>> +++ b/testcases/kernel/syscalls/mknod/mknod01.c
>> @@ -26,7 +26,6 @@ static int tcases[] = {
>>  	S_IFREG | 06700,
>>  };
>
>> -
>
> This is not reported by our checkpatch.pl and it would be useful. I'm not sure
> if you want to bother to look which from these --ignore
> CONST_STRUCT,VOLATILE,SPLIT_STRING,FILE_PATH_CHANGES should be removed (or which
> one is missing, maybe our checkpatch.pl is outdated).
>

Thanks for pointing this out, I got these warnings by passing `--strict`
option to checkpatch.pl. Also, I removed FILE_PATH_CHANGES from that
list but I don't remember now why.

>>  static void run(unsigned int i)
>>  {
>>  	dev_t dev = 0;
>> @@ -35,8 +34,8 @@ static void run(unsigned int i)
>>  		dev = makedev(1, 3);
>
>>  	TST_EXP_PASS(mknod(PATH, tcases[i], dev),
>> -				"mknod(PATH, %o, %ld)",
>> -				tcases[i], dev);
>> +		     "mknod(PATH, %o, %ld)",
>> +		     tcases[i], dev);
>
> I'm not sure, if this is worth to fix (our checkpatch.pl setup does not report it).
>

Indeed, its a purely aesthetic patch.

> But what would be worth to fix is 32 bit compatibility error on dev_t dev:
>
> $ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig CFLAGS=-m32 LDFLAGS=-m32 ./configure # see INSTALL
> ...
>
> mknod01.c:37:22: warning: format ‘%ld’ expects argument of type ‘long int’, but argument 6 has type ‘dev_t’ {aka ‘long long unsigned int’} [-Wformat=]
>    37 |                      "mknod(PATH, %o, %ld)",
>       |                      ^~~~~~~~~~~~~~~~~~~~~~
> ../../../../include/tst_test_macros.h:42:32: note: in definition of macro ‘TST_FMT_’
>    42 | #define TST_FMT_(FMT, _1, ...) FMT, ##__VA_ARGS__
>       |                                ^~~
> ../../../../include/tst_test_macros.h:46:26: note: in expansion of macro ‘TST_2_’
>    46 |                 TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__))
>       |                          ^~~~~~
> ../../../../include/tst_test_macros.h:210:25: note: in expansion of macro ‘TST_MSG_’
>   210 |                         TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
>       |                         ^~~~~~~~
> mknod01.c:36:9: note: in expansion of macro ‘TST_EXP_PASS’
>    36 |         TST_EXP_PASS(mknod(PATH, tcases[i], dev),
>       |         ^~~~~~~~~~~~
> mknod01.c:37:41: note: format string is defined here
>    37 |                      "mknod(PATH, %o, %ld)",
>       |                                       ~~^
>       |                                         |
>       |                                         long int
>       |                                       %lld
>
> (It should be solved by PRIuMAX and casting to (uintmax_t), but we usually just
> cast to (long long) and use just %lld. Whatever you prefer.
>

Nice, I'll add that :)

Thank you,
-	Ricardo.


> Kind regards,
> Petr


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

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

* Re: [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
  2025-04-14 20:09 ` [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-04-22 13:06   ` Petr Vorel
  2025-05-15  2:49     ` Li Wang via ltp
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2025-04-22 13:06 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo, all,

...
> +++ b/testcases/kernel/syscalls/mknod/mknod02.c
> @@ -20,7 +20,7 @@
>  #define MODE_SGID	02000

>  #define TEMP_DIR "testdir"
> -#define TEMP_NODE "testnode"
> +#define TEMP_NODE TEMP_DIR "/testnode"

>  static struct stat buf;
>  static struct passwd *user_nobody;
> @@ -37,14 +37,12 @@ static void setup(void)

>  static void run(void)
>  {
> -	SAFE_CHDIR(TEMP_DIR);
>  	TST_EXP_PASS(mknod(TEMP_NODE, MODE1, 0), "mknod(%s, %o, 0)", TEMP_NODE, MODE1);

>  	SAFE_STAT(TEMP_NODE, &buf);
>  	TST_EXP_EQ_LI(buf.st_gid, 0);

>  	SAFE_UNLINK(TEMP_NODE);
> -	SAFE_CHDIR("..");

I'm trying to figure out why the original test used SAFE_CHDIR().
IMHO mknod() should not be affected when called from an upper directory.
@Avinesh @Li did I overlook something obvious?

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API
  2025-04-14 20:09 ` [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
@ 2025-04-22 14:02   ` Petr Vorel
  2025-04-22 14:32     ` Ricardo B. Marlière via ltp
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2025-04-22 14:02 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo,

> +++ b/testcases/kernel/syscalls/mknod/mknod03.c

> @@ -1,296 +1,64 @@
> +// SPDX-License-Identifier: GPL-2.0-only
Text below shows "or (at your option) any later version" => it should be GPLv2+.
// SPDX-License-Identifier: GPL-2.0-or-later

>  /*
> - *
> - *   Copyright (c) International Business Machines  Corp., 2001
> - *
> - *   This program is free software;  you can redistribute it and/or modify
> - *   it under the terms of the GNU General Public License as published by
> - *   the Free Software Foundation; either version 2 of the License, or
> - *   (at your option) any later version.
> - *
> - *   This program is distributed in the hope that it will be useful,
> - *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
> - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
> - *   the GNU General Public License for more details.
> - *
> - *   You should have received a copy of the GNU General Public License
> - *   along with this program;  if not, write to the Free Software
> - *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + * Copyright (c) International Business Machines Corp., 2001
> + *	07/2001 Ported by Wayne Boyer
> + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
>   */

...
> +/*\
> + * Verify that mknod(2) succeeds when used to create a filesystem node with
> + * set-group-ID bit set on a directory with set-group-ID bit set. The node
> + * created should have set-group-ID bit set and its gid should be equal to
> + * the "nobody" gid.
>   */
...
> -#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
> -#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
> -#define DIR_TEMP	"testdir_3"
> -#define TNODE		"tnode_%d"
...
> +#define MODE_RWX 0777
> +#define MODE_SGID 2777

The test fails on my VM (last minute change?):
mknod03.c:33: TFAIL: buf.st_mode & S_ISGID (0) != S_ISGID (1024)
mknod03.c:38: TFAIL: buf.st_gid (65534) != free_gid (4)

Why? S_ISGID is *not* 2000 but 02000 (octal number, 1535 in decimal).
I actually find (S_ISGID | 0777) you had in v2 more readable, but maybe it's
just me who needs to look up setuid bits (unlike typical rwx permission bits).

> -char *TCID = "mknod03";
> -int TST_TOTAL = 1;
> -char node_name[PATH_MAX];	/* buffer to hold node name created */
> +#define TEMP_DIR "testdir"
> +#define TEMP_NODE TEMP_DIR "/testnode"

...
> +static void run(void)
>  {
...
> +	struct stat buf;

> +	SAFE_STAT(TEMP_DIR, &buf);
I would keep this first SAFE_STAT() in the setup() as it was in the original
code. We put things in the setup which are not related to the testing and thus
it's a waste of time to repeat them, e.g. on repeated run:
# ./mknod03 -i2000

> +	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
Also this original test should quit - use tst_brk(TBROK).

NOTE: after Cyril's change [1] is merged, it will not need to be tst_brk(TBROK),
but it makes sense to use TBROK (instead of TFAIL) in the test setup anyway.

The rest LGTM.

Kind regards,
Petr

[1] https://patchwork.ozlabs.org/project/ltp/patch/20250404143423.16268-1-chrubis@suse.cz/

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

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

* Re: [LTP] [PATCH v3 4/8] syscalls/mknod04: Convert to new API
  2025-04-14 20:09 ` [LTP] [PATCH v3 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-04-22 14:06   ` Petr Vorel
  0 siblings, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2025-04-22 14:06 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo,

> -#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
> -#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
...
> +#define MODE_RWX 0777
> +#define MODE_SGID 2777
Also here and in mknod05.c it should be 02777 or S_ISGID.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API
  2025-04-22 14:02   ` Petr Vorel
@ 2025-04-22 14:32     ` Ricardo B. Marlière via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-22 14:32 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Linux Test Project

On Tue Apr 22, 2025 at 11:02 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
>> +++ b/testcases/kernel/syscalls/mknod/mknod03.c
>
>> @@ -1,296 +1,64 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
> Text below shows "or (at your option) any later version" => it should be GPLv2+.
> // SPDX-License-Identifier: GPL-2.0-or-later
>
>>  /*
>> - *
>> - *   Copyright (c) International Business Machines  Corp., 2001
>> - *
>> - *   This program is free software;  you can redistribute it and/or modify
>> - *   it under the terms of the GNU General Public License as published by
>> - *   the Free Software Foundation; either version 2 of the License, or
>> - *   (at your option) any later version.
>> - *
>> - *   This program is distributed in the hope that it will be useful,
>> - *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
>> - *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
>> - *   the GNU General Public License for more details.
>> - *
>> - *   You should have received a copy of the GNU General Public License
>> - *   along with this program;  if not, write to the Free Software
>> - *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>> + * Copyright (c) International Business Machines Corp., 2001
>> + *	07/2001 Ported by Wayne Boyer
>> + * Copyright (c) 2025 SUSE LLC Ricardo B. Marlière <rbm@suse.com>
>>   */
>
> ...
>> +/*\
>> + * Verify that mknod(2) succeeds when used to create a filesystem node with
>> + * set-group-ID bit set on a directory with set-group-ID bit set. The node
>> + * created should have set-group-ID bit set and its gid should be equal to
>> + * the "nobody" gid.
>>   */
> ...
>> -#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
>> -#define MODE_SGID       S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
>> -#define DIR_TEMP	"testdir_3"
>> -#define TNODE		"tnode_%d"
> ...
>> +#define MODE_RWX 0777
>> +#define MODE_SGID 2777
>
> The test fails on my VM (last minute change?):

Oof, yes that was indeed the last part I touched...

> mknod03.c:33: TFAIL: buf.st_mode & S_ISGID (0) != S_ISGID (1024)
> mknod03.c:38: TFAIL: buf.st_gid (65534) != free_gid (4)
>
> Why? S_ISGID is *not* 2000 but 02000 (octal number, 1535 in decimal).
> I actually find (S_ISGID | 0777) you had in v2 more readable, but maybe it's
> just me who needs to look up setuid bits (unlike typical rwx permission bits).
>

Agreed, I'll keep the octals only for permission modes. Good call :)

>> -char *TCID = "mknod03";
>> -int TST_TOTAL = 1;
>> -char node_name[PATH_MAX];	/* buffer to hold node name created */
>> +#define TEMP_DIR "testdir"
>> +#define TEMP_NODE TEMP_DIR "/testnode"
>
> ...
>> +static void run(void)
>>  {
> ...
>> +	struct stat buf;
>
>> +	SAFE_STAT(TEMP_DIR, &buf);
> I would keep this first SAFE_STAT() in the setup() as it was in the original
> code. We put things in the setup which are not related to the testing and thus
> it's a waste of time to repeat them, e.g. on repeated run:
> # ./mknod03 -i2000
>

Ack.

>> +	TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
> Also this original test should quit - use tst_brk(TBROK).
>
> NOTE: after Cyril's change [1] is merged, it will not need to be tst_brk(TBROK),
> but it makes sense to use TBROK (instead of TFAIL) in the test setup anyway.

I'll take a look!

>
> The rest LGTM.
>

Thanks for reviewing,
-	Ricardo.


> Kind regards,
> Petr
>
> [1] https://patchwork.ozlabs.org/project/ltp/patch/20250404143423.16268-1-chrubis@suse.cz/


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

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

* Re: [LTP] [PATCH v3 5/8] syscalls/mknod05: Convert to new API
  2025-04-14 20:09 ` [LTP] [PATCH v3 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
@ 2025-04-25 15:30   ` Cyril Hrubis
  2025-04-25 16:26     ` Ricardo B. Marlière via ltp
  0 siblings, 1 reply; 18+ messages in thread
From: Cyril Hrubis @ 2025-04-25 15:30 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi!
> -struct stat buf;		/* struct. to hold stat(2) o/p contents */
> -struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
> +#define MODE_RWX 0777
> +#define MODE_SGID 2777
                     ^
		     There is 0 missing here.


And the test fail because of that because the mode is not interpreted as
octal number. I guess that this could be fixed before the push.

Other than this it looks fine. With that bit fixed:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH v3 5/8] syscalls/mknod05: Convert to new API
  2025-04-25 15:30   ` Cyril Hrubis
@ 2025-04-25 16:26     ` Ricardo B. Marlière via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 16:26 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: Linux Test Project

Hey hey!

On Fri Apr 25, 2025 at 12:30 PM -03, Cyril Hrubis wrote:
> Hi!
>> -struct stat buf;		/* struct. to hold stat(2) o/p contents */
>> -struct passwd *user1;		/* struct. to hold getpwnam(3) o/p contents */
>> +#define MODE_RWX 0777
>> +#define MODE_SGID 2777
>                      ^
> 		     There is 0 missing here.
>
>
> And the test fail because of that because the mode is not interpreted as
> octal number. I guess that this could be fixed before the push.
>
> Other than this it looks fine. With that bit fixed:
>
> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

Thanks for the review and sorry for the mess on the modes. I'll send a
new revision!

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

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

* Re: [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
  2025-04-22 13:06   ` Petr Vorel
@ 2025-05-15  2:49     ` Li Wang via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Li Wang via ltp @ 2025-05-15  2:49 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Linux Test Project, Ricardo B. Marlière

On Tue, Apr 22, 2025 at 9:06 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Ricardo, all,
>
> ...
> > +++ b/testcases/kernel/syscalls/mknod/mknod02.c
> > @@ -20,7 +20,7 @@
> >  #define MODE_SGID    02000
>
> >  #define TEMP_DIR "testdir"
> > -#define TEMP_NODE "testnode"
> > +#define TEMP_NODE TEMP_DIR "/testnode"
>
> >  static struct stat buf;
> >  static struct passwd *user_nobody;
> > @@ -37,14 +37,12 @@ static void setup(void)
>
> >  static void run(void)
> >  {
> > -     SAFE_CHDIR(TEMP_DIR);
> >       TST_EXP_PASS(mknod(TEMP_NODE, MODE1, 0), "mknod(%s, %o, 0)", TEMP_NODE, MODE1);
>
> >       SAFE_STAT(TEMP_NODE, &buf);
> >       TST_EXP_EQ_LI(buf.st_gid, 0);
>
> >       SAFE_UNLINK(TEMP_NODE);
> > -     SAFE_CHDIR("..");
>
> I'm trying to figure out why the original test used SAFE_CHDIR().

I guess that was simply added just by the new API conversion. It's
safe to remove it

> IMHO mknod() should not be affected when called from an upper directory.
> @Avinesh @Li did I overlook something obvious?

No, you're not overlooking anything obvious. mknod() doesn't care
about the directory you're in, as long as the pathname is correct.

And sorry for the late, I definitely missed this email :).

-- 
Regards,
Li Wang


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

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

end of thread, other threads:[~2025-05-15  2:50 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-14 20:09 [LTP] [PATCH v3 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
2025-04-22 10:52   ` Petr Vorel
2025-04-22 12:09     ` Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
2025-04-22 13:06   ` Petr Vorel
2025-05-15  2:49     ` Li Wang via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
2025-04-22 14:02   ` Petr Vorel
2025-04-22 14:32     ` Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
2025-04-22 14:06   ` Petr Vorel
2025-04-14 20:09 ` [LTP] [PATCH v3 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
2025-04-25 15:30   ` Cyril Hrubis
2025-04-25 16:26     ` Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
2025-04-14 20:09 ` [LTP] [PATCH v3 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox