Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests
@ 2025-04-25 18:06 Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
                   ` (8 more replies)
  0 siblings, 9 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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 v4:
- Fixed modes bits in all tests
- Removed unnecessary SAFE_STAT call in mknod03 (SAFE_CHMOD is enough)
- Fixed %ld warning in mknod01
- Rebased
- Link to v3: https://lore.kernel.org/r/20250414-conversions-mknod-v3-0-e08e7463bfaa@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 |   7 +-
 testcases/kernel/syscalls/mknod/mknod02.c |   4 +-
 testcases/kernel/syscalls/mknod/mknod03.c | 313 ++++-------------------------
 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(+), 1489 deletions(-)
---
base-commit: 037cb53e353abb571e52b52cbaa6b569ac28c50c
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 v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-06-03 11:08   ` Andrea Cervesato via ltp
  2025-06-05  7:26   ` Petr Vorel
  2025-04-25 18:06 ` [LTP] [PATCH v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
                   ` (7 subsequent siblings)
  8 siblings, 2 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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

Also, fix 32b compat mode warning:

mknod01.c:37:22: warning: format ‘%ld’ expects argument of type ‘long int’,
but argument 6 has type ‘dev_t’

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

diff --git a/testcases/kernel/syscalls/mknod/mknod01.c b/testcases/kernel/syscalls/mknod/mknod01.c
index fe0a1cfa6a473f9c2b2a55493f830f13b86560a8..0f0c17a5fd157e58359a586be2e268e42fa0eb0b 100644
--- a/testcases/kernel/syscalls/mknod/mknod01.c
+++ b/testcases/kernel/syscalls/mknod/mknod01.c
@@ -10,6 +10,8 @@
  * various modes.
  */
 
+#include <inttypes.h>
+#include <stdint.h>
 #include <sys/sysmacros.h>
 #include "tst_test.h"
 
@@ -26,7 +28,6 @@ static int tcases[] = {
 	S_IFREG | 06700,
 };
 
-
 static void run(unsigned int i)
 {
 	dev_t dev = 0;
@@ -35,8 +36,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, %" PRIuMAX ")",
+		     tcases[i], (uintmax_t)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 v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-05-20 12:46   ` Andrea Cervesato via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

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

Reviewed-by: Petr Vorel <pvorel@suse.cz>
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 v4 3/8] syscalls/mknod03: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-06-05  7:32   ` Petr Vorel
  2025-04-25 18:06 ` [LTP] [PATCH v4 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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 | 313 ++++--------------------------
 1 file changed, 39 insertions(+), 274 deletions(-)

diff --git a/testcases/kernel/syscalls/mknod/mknod03.c b/testcases/kernel/syscalls/mknod/mknod03.c
index 7ecadb5b37c3ab7eded90aa8a6d1e27f07236b1f..125a4c4e2b1f72b52423ea18037ce9407bb216a0 100644
--- a/testcases/kernel/syscalls/mknod/mknod03.c
+++ b/testcases/kernel/syscalls/mknod/mknod03.c
@@ -1,296 +1,61 @@
+// 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 (S_ISGID | 0777)
 
-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++) {
-
-		tst_count = 0;
+	struct stat buf;
 
-		/*
-		 *  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 v4 4/8] syscalls/mknod04: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (2 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-06-03 13:44   ` Andrea Cervesato via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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..ceb9565b4d2842b563637e882cedafb0e9731c01 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 (S_ISGID | 0777)
 
-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 v4 5/8] syscalls/mknod05: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (3 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 UTC (permalink / raw)
  To: Linux Test Project; +Cc: Ricardo B. Marlière

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

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
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..4b7e9577266eb8b2da63b0341e0da723b92ee653 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 (S_ISGID | 0777)
 
-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 v4 6/8] syscalls/mknod06: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (4 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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..a7b16111dbbc1a0085308c41ab78882ecd830f5a 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 (S_IFIFO | 0777)
 
-#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 v4 7/8] syscalls/mknod07: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (5 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-04-25 18:06 ` [LTP] [PATCH v4 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
  2025-06-04 14:36 ` [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Andrea Cervesato via ltp
  8 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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..76701a346b896e823b2451a23445eda24a974e8a 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 (S_IFIFO | 0444)
+#define SOCKET_MODE (S_IFSOCK | 0777)
+#define CHR_MODE (S_IFCHR | 0600)
+#define BLK_MODE (S_IFBLK | 0600)
 
-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 v4 8/8] syscalls/mknod08: Convert to new API
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (6 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
@ 2025-04-25 18:06 ` Ricardo B. Marlière via ltp
  2025-06-05  7:23   ` Petr Vorel
  2025-06-04 14:36 ` [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Andrea Cervesato via ltp
  8 siblings, 1 reply; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-04-25 18:06 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 v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
  2025-04-25 18:06 ` [LTP] [PATCH v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-05-20 12:46   ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Andrea Cervesato via ltp @ 2025-05-20 12:46 UTC (permalink / raw)
  To: Ricardo B. Marlière, Linux Test Project

Hi!

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

On 4/25/25 20:06, Ricardo B. Marlière via ltp wrote:
> From: Ricardo B. Marlière <rbm@suse.com>
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 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 = {
>

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

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

* Re: [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
@ 2025-06-03 11:08   ` Andrea Cervesato via ltp
  2025-06-05  7:26   ` Petr Vorel
  1 sibling, 0 replies; 18+ messages in thread
From: Andrea Cervesato via ltp @ 2025-06-03 11:08 UTC (permalink / raw)
  To: Ricardo B. Marlière, Linux Test Project

Hi!

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

%lu is enough. Otherwise, LGTM.

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

- Andrea

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

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

* Re: [LTP] [PATCH v4 4/8] syscalls/mknod04: Convert to new API
  2025-04-25 18:06 ` [LTP] [PATCH v4 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-06-03 13:44   ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Andrea Cervesato via ltp @ 2025-06-03 13:44 UTC (permalink / raw)
  To: Ricardo B. Marlière, Linux Test Project

Hi!

Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>

- andrea


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

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

* Re: [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests
  2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
                   ` (7 preceding siblings ...)
  2025-04-25 18:06 ` [LTP] [PATCH v4 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
@ 2025-06-04 14:36 ` Andrea Cervesato via ltp
  2025-06-04 14:37   ` Ricardo B. Marlière via ltp
  8 siblings, 1 reply; 18+ messages in thread
From: Andrea Cervesato via ltp @ 2025-06-04 14:36 UTC (permalink / raw)
  To: Ricardo B. Marlière, Linux Test Project

All patches look good to me. we should be able to merge them.

@Petr WDYT?


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

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

* Re: [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests
  2025-06-04 14:36 ` [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Andrea Cervesato via ltp
@ 2025-06-04 14:37   ` Ricardo B. Marlière via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-04 14:37 UTC (permalink / raw)
  To: Andrea Cervesato, Ricardo B. Marlière, Linux Test Project

On Wed Jun 4, 2025 at 11:36 AM -03, Andrea Cervesato wrote:
> All patches look good to me. we should be able to merge them.
>
> @Petr WDYT?

Cool, thanks for reviewing! :)

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

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

* Re: [LTP] [PATCH v4 8/8] syscalls/mknod08: Convert to new API
  2025-04-25 18:06 ` [LTP] [PATCH v4 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
@ 2025-06-05  7:23   ` Petr Vorel
  2025-06-05 12:53     ` Ricardo B. Marlière via ltp
  0 siblings, 1 reply; 18+ messages in thread
From: Petr Vorel @ 2025-06-05  7:23 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo,

...
> -/*
> - * 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.
...
> +/*\
> + * 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.
>   */

...
> -#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
> +#define MODE_RWX 0777

I'm not sure if that's omitted by accident or intentional, but I don't think
it's ok to drop S_IFIFO:

man mknod(2):

       The file type must be one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO,
       or S_IFSOCK to specify a regular file (which will be created
       empty), character special file, block special file, FIFO (named
       pipe), or UNIX domain socket, respectively.  (Zero file type is
       equivalent to type S_IFREG.)
=> we don't test on named pipe but on a regular file.

Could you please use the same approach as you use in mknod06.c?
#define MODE_FIFO_RWX (S_IFIFO | 0777)

...
> +uid_t nobody_uid;
> +gid_t nobody_gid, free_gid;

make check reports:

mknod08.c:24:7: warning: Symbol 'nobody_uid' has no prototype or library ('tst_') prefix. Should it be static?
mknod08.c:25:7: warning: Symbol 'nobody_gid' has no prototype or library ('tst_') prefix. Should it be static?
mknod08.c:25:19: warning: Symbol 'free_gid' has no prototype or library ('tst_') prefix. Should it be static?

With that fixed you can add:
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 v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
  2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
  2025-06-03 11:08   ` Andrea Cervesato via ltp
@ 2025-06-05  7:26   ` Petr Vorel
  1 sibling, 0 replies; 18+ messages in thread
From: Petr Vorel @ 2025-06-05  7:26 UTC (permalink / raw)
  To: Ricardo B. Marlière; +Cc: Linux Test Project

Hi Ricardo,

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

Kind regards,
Petr

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

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

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

Hi Ricardo, Andrea,

...
> +/*\
> + * 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 MODE_RWX 0777
> +#define MODE_SGID (S_ISGID | 0777)

And here also dropped S_IFIFO. Did I overlook a discussion that mknod() can be
called without S_IFIFO? (I don't think so).

And old tests use S_IFIFO also for mkdir(), but that is IMHO not needed.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH v4 8/8] syscalls/mknod08: Convert to new API
  2025-06-05  7:23   ` Petr Vorel
@ 2025-06-05 12:53     ` Ricardo B. Marlière via ltp
  0 siblings, 0 replies; 18+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:53 UTC (permalink / raw)
  To: Petr Vorel, Ricardo B. Marlière; +Cc: Linux Test Project

On Thu Jun 5, 2025 at 4:23 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
> ...
>> -/*
>> - * 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.
> ...
>> +/*\
>> + * 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.
>>   */
>
> ...
>> -#define MODE_RWX	S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
>> +#define MODE_RWX 0777
>
> I'm not sure if that's omitted by accident or intentional, but I don't think
> it's ok to drop S_IFIFO:
>
> man mknod(2):
>
>        The file type must be one of S_IFREG, S_IFCHR, S_IFBLK, S_IFIFO,
>        or S_IFSOCK to specify a regular file (which will be created
>        empty), character special file, block special file, FIFO (named
>        pipe), or UNIX domain socket, respectively.  (Zero file type is
>        equivalent to type S_IFREG.)
> => we don't test on named pipe but on a regular file.
>
> Could you please use the same approach as you use in mknod06.c?
> #define MODE_FIFO_RWX (S_IFIFO | 0777)

Ah sure thing, sorry about overlooking this.

>
> ...
>> +uid_t nobody_uid;
>> +gid_t nobody_gid, free_gid;
>
> make check reports:
>
> mknod08.c:24:7: warning: Symbol 'nobody_uid' has no prototype or library ('tst_') prefix. Should it be static?
> mknod08.c:25:7: warning: Symbol 'nobody_gid' has no prototype or library ('tst_') prefix. Should it be static?
> mknod08.c:25:19: warning: Symbol 'free_gid' has no prototype or library ('tst_') prefix. Should it be static?

oops, good catch

>
> With that fixed you can add:
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks for reviewing,
-	Ricardo.


>
> Kind regards,
> Petr


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

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

end of thread, other threads:[~2025-06-05 12:56 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-25 18:06 [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
2025-06-03 11:08   ` Andrea Cervesato via ltp
2025-06-05  7:26   ` Petr Vorel
2025-04-25 18:06 ` [LTP] [PATCH v4 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
2025-05-20 12:46   ` Andrea Cervesato via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
2025-06-05  7:32   ` Petr Vorel
2025-04-25 18:06 ` [LTP] [PATCH v4 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
2025-06-03 13:44   ` Andrea Cervesato via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
2025-04-25 18:06 ` [LTP] [PATCH v4 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
2025-06-05  7:23   ` Petr Vorel
2025-06-05 12:53     ` Ricardo B. Marlière via ltp
2025-06-04 14:36 ` [LTP] [PATCH v4 0/8] syscalls/mknod: Refactor all tests Andrea Cervesato via ltp
2025-06-04 14:37   ` 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