* [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests
@ 2025-06-05 12:52 Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
` (7 more replies)
0 siblings, 8 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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 v5:
- Fixed missing S_IFIFO to mknod03 and mknod08
- Added missing statics to mknod08
- Use %ju instead of PRIuMAX in mknod01
- Link to v4: https://lore.kernel.org/r/20250425-conversions-mknod-v4-0-222e0d2e7ef1@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 | 313 ++++-------------------------
8 files changed, 262 insertions(+), 1489 deletions(-)
---
base-commit: 7cb9dd3c8f4e0d31d4de2053efe888f4f2da2b70
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] 23+ messages in thread
* [LTP] [PATCH v5 1/8] syscalls/mknod01: Fix checkpatch.pl warnings
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
` (6 subsequent siblings)
7 siblings, 0 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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’
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com>
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..801d2ef2a3394793c7cb4bbe63bc4fea15bb4ec3 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, %ju)",
+ 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] 23+ messages in thread
* [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 10:08 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
` (5 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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>
Reviewed-by: Andrea Cervesato <andrea.cervesato@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] 23+ messages in thread
* [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 10:34 ` Petr Vorel
2025-06-06 11:49 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
` (4 subsequent siblings)
7 siblings, 2 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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..00a6133f7a15c1dd9c9e67ba08315f218f16d0d6 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_FIFO_SGID (S_IFIFO | 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_FIFO_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_FIFO_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] 23+ messages in thread
* [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
` (2 preceding siblings ...)
2025-06-05 12:52 ` [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 10:48 ` Petr Vorel
` (2 more replies)
2025-06-05 12:52 ` [LTP] [PATCH v5 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
` (3 subsequent siblings)
7 siblings, 3 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 UTC (permalink / raw)
To: Linux Test Project; +Cc: Ricardo B. Marlière
From: Ricardo B. Marlière <rbm@suse.com>
Reviewed-by: Andrea Cervesato <andrea.cervesato@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] 23+ messages in thread
* [LTP] [PATCH v5 5/8] syscalls/mknod05: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
` (3 preceding siblings ...)
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 11:44 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
` (2 subsequent siblings)
7 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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] 23+ messages in thread
* [LTP] [PATCH v5 6/8] syscalls/mknod06: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
` (4 preceding siblings ...)
2025-06-05 12:52 ` [LTP] [PATCH v5 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 12:06 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
7 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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] 23+ messages in thread
* [LTP] [PATCH v5 7/8] syscalls/mknod07: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
` (5 preceding siblings ...)
2025-06-05 12:52 ` [LTP] [PATCH v5 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
2025-06-06 12:21 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 8/8] syscalls/mknod08: " Ricardo B. Marlière via ltp
7 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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] 23+ messages in thread
* [LTP] [PATCH v5 8/8] syscalls/mknod08: Convert to new API
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
` (6 preceding siblings ...)
2025-06-05 12:52 ` [LTP] [PATCH v5 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
@ 2025-06-05 12:52 ` Ricardo B. Marlière via ltp
7 siblings, 0 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-05 12:52 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/mknod08.c | 313 ++++--------------------------
1 file changed, 38 insertions(+), 275 deletions(-)
diff --git a/testcases/kernel/syscalls/mknod/mknod08.c b/testcases/kernel/syscalls/mknod/mknod08.c
index 8647fdebb4766151ffd91fd30083389e5def4850..75810e5703bbc55aea717a234b404ffaa86abe06 100644
--- a/testcases/kernel/syscalls/mknod/mknod08.c
+++ b/testcases/kernel/syscalls/mknod/mknod08.c
@@ -1,296 +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: 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
+#define MODE_FIFO_RWX (S_IFIFO | 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 */
+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;
- /*
- * 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_FIFO_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] 23+ messages in thread
* Re: [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR
2025-06-05 12:52 ` [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
@ 2025-06-06 10:08 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 10:08 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi all,
Yes, man mknod(2) notes:
the new node will inherit the group ownership from its parent directory
no matter what is cwd of the calling process.
Therefore I merged this obvious simplification (+ previous commit).
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
@ 2025-06-06 10:34 ` Petr Vorel
2025-06-06 11:49 ` Petr Vorel
1 sibling, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 10:34 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo, all,
...
> - /*
> - * 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");
> - }
+1 for avoiding restoring UID in cleanup (I also think that while setreuid(-1,
nobody_uid) in setup is a subject of testing thus needed, restoring UID is
indeed *not* needed. IMHO this is often done i real programs which gain root
in setuid, but that's not the case).
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
@ 2025-06-06 10:48 ` Petr Vorel
2025-06-06 11:05 ` Ricardo B. Marlière via ltp
2025-06-06 11:27 ` Petr Vorel
2 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 10:48 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo, all,
I was even thinking whether this test differs enough from mknod03.c to justify
it's existence (w/a S_ISGID is the only difference). But obviously kernel change
0fa3ecd87848 ("Fix up non-directory creation in SGID directories") and the need
to adapt it in LTP in fe002060de justifies it.
Thanks for the rewrite!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
2025-06-06 10:48 ` Petr Vorel
@ 2025-06-06 11:05 ` Ricardo B. Marlière via ltp
2025-06-06 11:27 ` Petr Vorel
2 siblings, 0 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-06 11:05 UTC (permalink / raw)
To: Ricardo B. Marlière, Linux Test Project
On Thu Jun 5, 2025 at 9:52 AM -03, Ricardo B. Marlière wrote:
> From: Ricardo B. Marlière <rbm@suse.com>
>
> Reviewed-by: Andrea Cervesato <andrea.cervesato@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)
I just realized I dropped S_IFIFO here aswell.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
2025-06-06 10:48 ` Petr Vorel
2025-06-06 11:05 ` Ricardo B. Marlière via ltp
@ 2025-06-06 11:27 ` Petr Vorel
2025-06-06 11:31 ` Ricardo B. Marlière via ltp
2 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 11:27 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
Similarly, to what I noted to mknod03.c in v4:
https://lore.kernel.org/ltp/20250605073231.GC1190804@pevik/
Originally here was also S_IFIFO (used for both mkdir() and mknod()). Although
the tests "works" IMHO we should use mknod() with S_IFIFO (and I believe it's
not needed for mkdir().
> -#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
> +#define MODE_RWX 0777
But you omit it.
> +#define MODE_SGID (S_ISGID | 0777)
...
> - /*
> - * 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);
I vote for following diff (no need to repost).
Kind regards,
Petr
+++ testcases/kernel/syscalls/mknod/mknod04.c
@@ -17,6 +17,7 @@
#include "tst_test.h"
#define MODE_RWX 0777
+#define MODE_FIFO (S_IFIFO | 0777)
#define MODE_SGID (S_ISGID | 0777)
#define TEMP_DIR "testdir"
@@ -29,7 +30,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-06 11:27 ` Petr Vorel
@ 2025-06-06 11:31 ` Ricardo B. Marlière via ltp
2025-06-06 13:59 ` Petr Vorel
0 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-06 11:31 UTC (permalink / raw)
To: Petr Vorel, Ricardo B. Marlière; +Cc: Linux Test Project
On Fri Jun 6, 2025 at 8:27 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
> ...
>> -#define MODE_RWX S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO
>
> Similarly, to what I noted to mknod03.c in v4:
> https://lore.kernel.org/ltp/20250605073231.GC1190804@pevik/
Exactly!
>
> Originally here was also S_IFIFO (used for both mkdir() and mknod()). Although
> the tests "works" IMHO we should use mknod() with S_IFIFO (and I believe it's
> not needed for mkdir().
>
>> -#define MODE_SGID S_IFIFO | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO
>
>> +#define MODE_RWX 0777
> But you omit it.
>
>> +#define MODE_SGID (S_ISGID | 0777)
> ...
>> - /*
>> - * 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);
>
> I vote for following diff (no need to repost).
Thanks!
>
> Kind regards,
> Petr
>
> +++ testcases/kernel/syscalls/mknod/mknod04.c
> @@ -17,6 +17,7 @@
> #include "tst_test.h"
>
> #define MODE_RWX 0777
> +#define MODE_FIFO (S_IFIFO | 0777)
> #define MODE_SGID (S_ISGID | 0777)
>
> #define TEMP_DIR "testdir"
> @@ -29,7 +30,7 @@ static void run(void)
> {
> struct stat buf;
>
> - SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
> + SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
>
> SAFE_STAT(TEMP_NODE, &buf);
> TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
Can you please also apply this one:
diff --git a/testcases/kernel/syscalls/mknod/mknod05.c b/testcases/kernel/syscalls/mknod/mknod05.c
index 4b7e9577266e..34611b57ee92 100644
--- a/testcases/kernel/syscalls/mknod/mknod05.c
+++ b/testcases/kernel/syscalls/mknod/mknod05.c
@@ -18,6 +18,7 @@
#define MODE_RWX 0777
#define MODE_SGID (S_ISGID | 0777)
+#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
#define TEMP_DIR "testdir"
#define TEMP_NODE TEMP_DIR "/testnode"
@@ -29,7 +30,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
Thanks a lot,
RBM
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 5/8] syscalls/mknod05: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
@ 2025-06-06 11:44 ` Petr Vorel
2025-06-06 11:45 ` Ricardo B. Marlière via ltp
0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 11:44 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
...
> -/*
> - * 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.
> - *
...
> +/*\
> + * 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
very nit: The original reader was not consistent when referring to setuid.
Mostly he used "set-group-ID" which is also used in man chmod(2) and in The
Linux Programming Interface book. Therefore I'll modify before merge:
s/set group-ID/set-group-ID/
> + * created should have set group-ID bit set and its gid should be equal to
> + * that of its parent directory.
> */
> -#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
And again, as I noted at mknod0[34].c here is constant used for mknod() uses
S_IFIFO.
> -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)
But you don't use it.
...
> + 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));
I vote for following diff (using a constant you defined also for mknod03.c).
No need to repost, I can change it before merge.
Kind regards,
Petr
+++ testcases/kernel/syscalls/mknod/mknod05.c
@@ -7,8 +7,8 @@
/*\
* 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
+ * 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.
*/
@@ -17,7 +17,7 @@
#include "tst_test.h"
#define MODE_RWX 0777
-#define MODE_SGID (S_ISGID | 0777)
+#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
#define TEMP_DIR "testdir"
#define TEMP_NODE TEMP_DIR "/testnode"
@@ -29,7 +29,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
@@ -48,7 +48,7 @@ static void setup(void)
SAFE_MKDIR(TEMP_DIR, MODE_RWX);
SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
- SAFE_CHMOD(TEMP_DIR, MODE_SGID);
+ SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
}
static struct tst_test test = {
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 5/8] syscalls/mknod05: Convert to new API
2025-06-06 11:44 ` Petr Vorel
@ 2025-06-06 11:45 ` Ricardo B. Marlière via ltp
0 siblings, 0 replies; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-06 11:45 UTC (permalink / raw)
To: Petr Vorel, Ricardo B. Marlière; +Cc: Linux Test Project
On Fri Jun 6, 2025 at 8:44 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
> ...
>> -/*
>> - * 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.
>> - *
> ...
>> +/*\
>> + * 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
> very nit: The original reader was not consistent when referring to setuid.
> Mostly he used "set-group-ID" which is also used in man chmod(2) and in The
> Linux Programming Interface book. Therefore I'll modify before merge:
>
> s/set group-ID/set-group-ID/
>
>> + * created should have set group-ID bit set and its gid should be equal to
>> + * that of its parent directory.
>> */
>
>> -#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
>
> And again, as I noted at mknod0[34].c here is constant used for mknod() uses
> S_IFIFO.
>
>> -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)
>
> But you don't use it.
>
> ...
>> + 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));
>
> I vote for following diff (using a constant you defined also for mknod03.c).
> No need to repost, I can change it before merge.
That would be perfect, thank you!
>
> Kind regards,
> Petr
>
> +++ testcases/kernel/syscalls/mknod/mknod05.c
> @@ -7,8 +7,8 @@
>
> /*\
> * 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
> + * 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.
> */
>
> @@ -17,7 +17,7 @@
> #include "tst_test.h"
>
> #define MODE_RWX 0777
> -#define MODE_SGID (S_ISGID | 0777)
> +#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
>
> #define TEMP_DIR "testdir"
> #define TEMP_NODE TEMP_DIR "/testnode"
> @@ -29,7 +29,7 @@ static void run(void)
> {
> struct stat buf;
>
> - SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
> + SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
>
> SAFE_STAT(TEMP_NODE, &buf);
> TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
> @@ -48,7 +48,7 @@ static void setup(void)
>
> SAFE_MKDIR(TEMP_DIR, MODE_RWX);
> SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
> - SAFE_CHMOD(TEMP_DIR, MODE_SGID);
> + SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
> }
>
> static struct tst_test test = {
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
2025-06-06 10:34 ` Petr Vorel
@ 2025-06-06 11:49 ` Petr Vorel
2025-06-06 11:57 ` Ricardo B. Marlière via ltp
1 sibling, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 11:49 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
> 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..00a6133f7a15c1dd9c9e67ba08315f218f16d0d6 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
nit: This should be v2+
// 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.
Because any later version.
It can be changed before merging.
Below is whole diff against the patchset I suggest.
Kind regards,
Petr
diff --git testcases/kernel/syscalls/mknod/mknod03.c testcases/kernel/syscalls/mknod/mknod03.c
index 00a6133f7a..8cb9be9287 100644
--- testcases/kernel/syscalls/mknod/mknod03.c
+++ testcases/kernel/syscalls/mknod/mknod03.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2001
* 07/2001 Ported by Wayne Boyer
diff --git testcases/kernel/syscalls/mknod/mknod04.c testcases/kernel/syscalls/mknod/mknod04.c
index ceb9565b4d..d96cb27b95 100644
--- testcases/kernel/syscalls/mknod/mknod04.c
+++ testcases/kernel/syscalls/mknod/mknod04.c
@@ -17,6 +17,7 @@
#include "tst_test.h"
#define MODE_RWX 0777
+#define MODE_FIFO (S_IFIFO | 0777)
#define MODE_SGID (S_ISGID | 0777)
#define TEMP_DIR "testdir"
@@ -29,7 +30,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
diff --git testcases/kernel/syscalls/mknod/mknod05.c testcases/kernel/syscalls/mknod/mknod05.c
index 4b7e957726..bfac9227b9 100644
--- testcases/kernel/syscalls/mknod/mknod05.c
+++ testcases/kernel/syscalls/mknod/mknod05.c
@@ -7,8 +7,8 @@
/*\
* 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
+ * 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.
*/
@@ -17,7 +17,7 @@
#include "tst_test.h"
#define MODE_RWX 0777
-#define MODE_SGID (S_ISGID | 0777)
+#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
#define TEMP_DIR "testdir"
#define TEMP_NODE TEMP_DIR "/testnode"
@@ -29,7 +29,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
@@ -48,7 +48,7 @@ static void setup(void)
SAFE_MKDIR(TEMP_DIR, MODE_RWX);
SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
- SAFE_CHMOD(TEMP_DIR, MODE_SGID);
+ SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
}
static struct tst_test test = {
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API
2025-06-06 11:49 ` Petr Vorel
@ 2025-06-06 11:57 ` Ricardo B. Marlière via ltp
2025-06-06 12:33 ` Petr Vorel
0 siblings, 1 reply; 23+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-06-06 11:57 UTC (permalink / raw)
To: Petr Vorel, Ricardo B. Marlière; +Cc: Linux Test Project
On Fri Jun 6, 2025 at 8:49 AM -03, Petr Vorel wrote:
> Hi Ricardo,
>
>> 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..00a6133f7a15c1dd9c9e67ba08315f218f16d0d6 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
> nit: This should be v2+
>
> // SPDX-License-Identifier: GPL-2.0-or-later
Weird, I have that as a snippet but must have copied from another file
on that occasion.
>> /*
>> - *
>> - * 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.
> Because any later version.
>
> It can be changed before merging.
>
> Below is whole diff against the patchset I suggest.
+1
>
> Kind regards,
> Petr
>
> diff --git testcases/kernel/syscalls/mknod/mknod03.c testcases/kernel/syscalls/mknod/mknod03.c
> index 00a6133f7a..8cb9be9287 100644
> --- testcases/kernel/syscalls/mknod/mknod03.c
> +++ testcases/kernel/syscalls/mknod/mknod03.c
> @@ -1,4 +1,4 @@
> -// SPDX-License-Identifier: GPL-2.0-only
> +// SPDX-License-Identifier: GPL-2.0-or-later
> /*
> * Copyright (c) International Business Machines Corp., 2001
> * 07/2001 Ported by Wayne Boyer
> diff --git testcases/kernel/syscalls/mknod/mknod04.c testcases/kernel/syscalls/mknod/mknod04.c
> index ceb9565b4d..d96cb27b95 100644
> --- testcases/kernel/syscalls/mknod/mknod04.c
> +++ testcases/kernel/syscalls/mknod/mknod04.c
> @@ -17,6 +17,7 @@
> #include "tst_test.h"
>
> #define MODE_RWX 0777
> +#define MODE_FIFO (S_IFIFO | 0777)
> #define MODE_SGID (S_ISGID | 0777)
>
> #define TEMP_DIR "testdir"
> @@ -29,7 +30,7 @@ static void run(void)
> {
> struct stat buf;
>
> - SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
> + SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
>
> SAFE_STAT(TEMP_NODE, &buf);
> TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
> diff --git testcases/kernel/syscalls/mknod/mknod05.c testcases/kernel/syscalls/mknod/mknod05.c
> index 4b7e957726..bfac9227b9 100644
> --- testcases/kernel/syscalls/mknod/mknod05.c
> +++ testcases/kernel/syscalls/mknod/mknod05.c
> @@ -7,8 +7,8 @@
>
> /*\
> * 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
> + * 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.
> */
>
> @@ -17,7 +17,7 @@
> #include "tst_test.h"
>
> #define MODE_RWX 0777
> -#define MODE_SGID (S_ISGID | 0777)
> +#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
>
> #define TEMP_DIR "testdir"
> #define TEMP_NODE TEMP_DIR "/testnode"
> @@ -29,7 +29,7 @@ static void run(void)
> {
> struct stat buf;
>
> - SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
> + SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
>
> SAFE_STAT(TEMP_NODE, &buf);
> TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
> @@ -48,7 +48,7 @@ static void setup(void)
>
> SAFE_MKDIR(TEMP_DIR, MODE_RWX);
> SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
> - SAFE_CHMOD(TEMP_DIR, MODE_SGID);
> + SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
> }
>
> static struct tst_test test = {
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 6/8] syscalls/mknod06: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
@ 2025-06-06 12:06 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 12:06 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
> +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 },
> };
Using some constants for path reused ("tnode_1" and "tnode") would be slightly
clearer, but it can stay as is.
...
> +static void setup(void)
> {
> + SAFE_MKNOD("tnode_1", MODE_FIFO_RWX, 0);
> + SAFE_MKNOD("tnode", MODE_FIFO_RWX, 0);
NOTE: if I were the original patch writer, I would really create an empty file,
not a named pipe:
fd = SAFE_OPEN("tnode", O_WRONLY | O_CREAT | O_TRUNC, 0644);
SAFE_CLOSE(fd);
But maybe there was a reason to create named pipe instead of a regular file.
...
> +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 },
> + {},
+1 for using Guarded buffers.
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 7/8] syscalls/mknod07: Convert to new API
2025-06-05 12:52 ` [LTP] [PATCH v5 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
@ 2025-06-06 12:21 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 12:21 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
> +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 },
I would slightly prefer to use designated initializers as it's more descriptive
and allows to avoid setting 0 or NULL:
{ .mode = FIFO_MODE, .exp_errno = ELOOP },
{ .pathname = TEMP_DIR "/tnode1", .mode = SOCKET_MODE, .exp_errno = EACCES },
But let's ignore it.
Thanks for the rewrite!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Kind regards,
Petr
> + { 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 },
> };
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API
2025-06-06 11:57 ` Ricardo B. Marlière via ltp
@ 2025-06-06 12:33 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 12:33 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
> On Fri Jun 6, 2025 at 8:49 AM -03, Petr Vorel wrote:
> > Hi Ricardo,
> >> 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..00a6133f7a15c1dd9c9e67ba08315f218f16d0d6 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
> > nit: This should be v2+
> > // SPDX-License-Identifier: GPL-2.0-or-later
> Weird, I have that as a snippet but must have copied from another file
> on that occasion.
Although the default license for new files is GPL-2.0-or-later,
unfortunately it can be taken as a default when rewriting the file.
We had a lovely lawsuits with some companies, that's why it's also good to pay
attention to the license.
Anyway, thank you for your work, merged with this change.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [LTP] [PATCH v5 4/8] syscalls/mknod04: Convert to new API
2025-06-06 11:31 ` Ricardo B. Marlière via ltp
@ 2025-06-06 13:59 ` Petr Vorel
0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2025-06-06 13:59 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Linux Test Project
Hi Ricardo,
> > +++ testcases/kernel/syscalls/mknod/mknod04.c
> > @@ -17,6 +17,7 @@
> > #include "tst_test.h"
> > #define MODE_RWX 0777
> > +#define MODE_FIFO (S_IFIFO | 0777)
> > #define MODE_SGID (S_ISGID | 0777)
> > #define TEMP_DIR "testdir"
> > @@ -29,7 +30,7 @@ static void run(void)
> > {
> > struct stat buf;
> > - SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
> > + SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
> > SAFE_STAT(TEMP_NODE, &buf);
> > TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
> Can you please also apply this one:
> diff --git a/testcases/kernel/syscalls/mknod/mknod05.c b/testcases/kernel/syscalls/mknod/mknod05.c
> index 4b7e9577266e..34611b57ee92 100644
> --- a/testcases/kernel/syscalls/mknod/mknod05.c
> +++ b/testcases/kernel/syscalls/mknod/mknod05.c
> @@ -18,6 +18,7 @@
> #define MODE_RWX 0777
> #define MODE_SGID (S_ISGID | 0777)
> +#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
> #define TEMP_DIR "testdir"
> #define TEMP_NODE TEMP_DIR "/testnode"
> @@ -29,7 +30,7 @@ static void run(void)
> {
> struct stat buf;
> - SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
> + SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
> SAFE_STAT(TEMP_NODE, &buf);
> TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
> Thanks a lot,
Sure. Yeah, both mknod[45].c should use also S_IFIFO for both mknod() and
chmod(). Changed both.
Merged the rest of the patchset, thank you for the rewrite!
As there were quite a lot of changes, here is the following diff for mknod[3-8].c.
Kind regards,
Petr
> RBM
diff --git testcases/kernel/syscalls/mknod/mknod03.c testcases/kernel/syscalls/mknod/mknod03.c
index 00a6133f7a..8cb9be9287 100644
--- testcases/kernel/syscalls/mknod/mknod03.c
+++ testcases/kernel/syscalls/mknod/mknod03.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-only
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2001
* 07/2001 Ported by Wayne Boyer
diff --git testcases/kernel/syscalls/mknod/mknod04.c testcases/kernel/syscalls/mknod/mknod04.c
index ceb9565b4d..441894b3b9 100644
--- testcases/kernel/syscalls/mknod/mknod04.c
+++ testcases/kernel/syscalls/mknod/mknod04.c
@@ -17,7 +17,8 @@
#include "tst_test.h"
#define MODE_RWX 0777
-#define MODE_SGID (S_ISGID | 0777)
+#define MODE_FIFO (S_IFIFO | 0777)
+#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
#define TEMP_DIR "testdir"
#define TEMP_NODE TEMP_DIR "/testnode"
@@ -29,7 +30,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_RWX, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, 0);
@@ -48,7 +49,7 @@ static void setup(void)
SAFE_MKDIR(TEMP_DIR, MODE_RWX);
SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
- SAFE_CHMOD(TEMP_DIR, MODE_SGID);
+ SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
SAFE_SETGID(nobody_gid);
SAFE_SETREUID(-1, nobody_uid);
diff --git testcases/kernel/syscalls/mknod/mknod05.c testcases/kernel/syscalls/mknod/mknod05.c
index 4b7e957726..bfac9227b9 100644
--- testcases/kernel/syscalls/mknod/mknod05.c
+++ testcases/kernel/syscalls/mknod/mknod05.c
@@ -7,8 +7,8 @@
/*\
* 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
+ * 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.
*/
@@ -17,7 +17,7 @@
#include "tst_test.h"
#define MODE_RWX 0777
-#define MODE_SGID (S_ISGID | 0777)
+#define MODE_FIFO_SGID (S_IFIFO | S_ISGID | 0777)
#define TEMP_DIR "testdir"
#define TEMP_NODE TEMP_DIR "/testnode"
@@ -29,7 +29,7 @@ static void run(void)
{
struct stat buf;
- SAFE_MKNOD(TEMP_NODE, MODE_SGID, 0);
+ SAFE_MKNOD(TEMP_NODE, MODE_FIFO_SGID, 0);
SAFE_STAT(TEMP_NODE, &buf);
TST_EXP_EQ_LI(buf.st_mode & S_ISGID, S_ISGID);
@@ -48,7 +48,7 @@ static void setup(void)
SAFE_MKDIR(TEMP_DIR, MODE_RWX);
SAFE_CHOWN(TEMP_DIR, nobody_uid, free_gid);
- SAFE_CHMOD(TEMP_DIR, MODE_SGID);
+ SAFE_CHMOD(TEMP_DIR, MODE_FIFO_SGID);
}
static struct tst_test test = {
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 23+ messages in thread
end of thread, other threads:[~2025-06-06 13:59 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 12:52 [LTP] [PATCH v5 0/8] syscalls/mknod: Refactor all tests Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 1/8] syscalls/mknod01: Fix checkpatch.pl warnings Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 2/8] syscalls/mknod02: Use relative path to avoid use of SAFE_CHDIR Ricardo B. Marlière via ltp
2025-06-06 10:08 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 3/8] syscalls/mknod03: Convert to new API Ricardo B. Marlière via ltp
2025-06-06 10:34 ` Petr Vorel
2025-06-06 11:49 ` Petr Vorel
2025-06-06 11:57 ` Ricardo B. Marlière via ltp
2025-06-06 12:33 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 4/8] syscalls/mknod04: " Ricardo B. Marlière via ltp
2025-06-06 10:48 ` Petr Vorel
2025-06-06 11:05 ` Ricardo B. Marlière via ltp
2025-06-06 11:27 ` Petr Vorel
2025-06-06 11:31 ` Ricardo B. Marlière via ltp
2025-06-06 13:59 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 5/8] syscalls/mknod05: " Ricardo B. Marlière via ltp
2025-06-06 11:44 ` Petr Vorel
2025-06-06 11:45 ` Ricardo B. Marlière via ltp
2025-06-05 12:52 ` [LTP] [PATCH v5 6/8] syscalls/mknod06: " Ricardo B. Marlière via ltp
2025-06-06 12:06 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 7/8] syscalls/mknod07: " Ricardo B. Marlière via ltp
2025-06-06 12:21 ` Petr Vorel
2025-06-05 12:52 ` [LTP] [PATCH v5 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