From patchwork Fri Apr 25 18:06:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= X-Patchwork-Id: 2077447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=Ee4wja6h; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=g+mpDsK6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Zkgmj4vlbz1yMm for ; Sat, 26 Apr 2025 04:07:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1745604485; h=date : mime-version : message-id : references : in-reply-to : to : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : cc : content-type : content-transfer-encoding : sender : from; bh=MdroALtKBD3H3ubuQMxEnDlNnSfN7aKy3AEHOdiHN+Q=; b=Ee4wja6hNU9hy9aQOTZmFBosBtstQ3YEpfN78UZltG6uOmfHZtS+r/9mkEKWSxgUuB26Y Js3zSrynNqseoKzccx3hTNbjqiPeTH8p3nkS5Qcwml2zjkw2syu6Xfn7a7rjjuL7ddt4f2c blJfexjzahe7KlI/xda7deAGHtAbn44= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0F5463CBA5F for ; Fri, 25 Apr 2025 20:08:05 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id EBF7C3CBAA2 for ; Fri, 25 Apr 2025 20:06:23 +0200 (CEST) Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 25AA36005DC for ; Fri, 25 Apr 2025 20:06:23 +0200 (CEST) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-acacb8743a7so424612266b.1 for ; Fri, 25 Apr 2025 11:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1745604382; x=1746209182; darn=lists.linux.it; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tho9vI9rSl2BfAV1QNFEmZLl10rX1T6Sl7trhHs5SpY=; b=g+mpDsK6EfO8OObQv7rdj14bibK5hl2OfJ/08QsJT71/e3p8DYmlcBMYBXPZDCstzu rCoc9/b5SargFeYmcuLMvuS4yBvb/299u6ZB7VX28HCOcviUbZXTL04+QSD2ijq16LS3 erF7zHVry8P837H7IXuwPaem9SctV+70P3NGvJi2xW9C9Rfk9oDAUg+ywK2ApZFMBDCT Dg6mYKV1gibPlFaoNNZ5Cm4OTjzdSkPx24WG1fF/kGmSZFz8JI7612holepSSmO9dSy4 JUualgNe1qVmGXXNfGaWOK39UgHQjmYARRJGg7es5H49g+m8ro7B0eSQ60WDnqfi03NE MrFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745604382; x=1746209182; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tho9vI9rSl2BfAV1QNFEmZLl10rX1T6Sl7trhHs5SpY=; b=nVzz7gpcEb1lYDAFmD+fo9pFUZIp+2GOpHJZ2CcIKBVfiCqhYEneLR2IPtsvnfEKLq fytuhZr5M6ffr/aU5wKWlQSoK+uJrKNTZMCu7OO8S6zNtvKJE/OuE4O9iprCSxuPYzSC TV10Qc+oDzsIjZMz8wRy2ZJ8s0pSrTCoUtskO/dJXP2Hl1L17RYgFOjATa+MKY2Dtpee HSbrLWb5g3mkzHx5tvd2efQ6lFdpLnTJCGQegBHe7U0U8AXh6UER4mh+RRrnzDn+Vpy0 IZxN2i0L/8rgA3kND6uJ6eMPFz3ULachcZgnh5U+xV6Gq8NGbi2Koz1bxSPqH9cgKcbS T9cg== X-Gm-Message-State: AOJu0YwuenTkRj0O29RSUKqFjh5flHfVput9jeVzN+gHqa4WKl071S6/ w14TfDh7ni5AITMgE1IpjZBAZfgWfhN209H0FvwvU1LnC5W9VLEYdEinNxm8DevpwP3NPMU3oOA s X-Gm-Gg: ASbGnctoy936m6TIF8LtkYn5JO3boXBCg1Vi/2OyrWe2uZO+LEYlC7YHy3drSVHuwks corguwCyHsv9AcdbCMMXMqcgwwK2qhvGm3ksXGqEplOn5BMMbjYmTxDkMdMutYzfFDUWGVF24dH IW6wy4sCwxSVSI4k9zkJPJy7oqvsP03r51ir6ttvKfAByCJ16xQp+qb/c00lWBQzOBf7vWiMo26 v6gFvMpcUdzZm5Rf4+n2Brn3GyPsOIKg9fA073bDYOgrmvRoTDdQCdfJcvWIoTMCSX+Fp8R0M73 o3Nad7yPJoeURUCf2YyQSeriWELydw== X-Google-Smtp-Source: AGHT+IGSJ341vcCn7l9WsSaNqRcFYxUwSO+lxA2VRV2b/5vGw2ZKa7vr2wkUzIlemA0mwCl/+qNP0A== X-Received: by 2002:a17:907:3ea8:b0:ac6:f5b5:36e0 with SMTP id a640c23a62f3a-ace5a44935cmr659110666b.19.1745604382067; Fri, 25 Apr 2025 11:06:22 -0700 (PDT) Received: from localhost ([179.228.213.210]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-309f77417d6sm1990750a91.4.2025.04.25.11.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 11:06:21 -0700 (PDT) Date: Fri, 25 Apr 2025 15:06:04 -0300 MIME-Version: 1.0 Message-Id: <20250425-conversions-mknod-v4-4-222e0d2e7ef1@suse.com> References: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> In-Reply-To: <20250425-conversions-mknod-v4-0-222e0d2e7ef1@suse.com> To: Linux Test Project X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=10924; i=rbm@suse.com; h=from:subject:message-id; bh=aR0UKKMmgd71mc7C/QYNnJZHpjZ9enpbvWA955sVbiA=; b=owEBbQKS/ZANAwAIAckLinxjhlimAcsmYgBoC88N4KiizCZOMGAqj9wezQh2KdZbEB2JhFhAC 7e4jpfmcE2JAjMEAAEIAB0WIQQDCo6eQk7jwGVXh+HJC4p8Y4ZYpgUCaAvPDQAKCRDJC4p8Y4ZY pqMFEACyhUkG6LzeXuyMrHos8whf32MGQcFHho5drOa0IlYymekROE7AQD7gtqjp9lnBfRlf2zz U1BQbzLf1p5nIp/22G7p0sbK/XFCMlSauH1nHdg/zPHcYuGyhfDj2vAVM1nXR0X1e1rZtWGS7OE tKwzCtkabuHHDaQ1sCvyAmutpeY2d+Nyzft7IyHlnOLfUIsiLSmWQDt/Cyo0qIFDHJfvehTlr4e zo6jq3i7V3kemzplw97aC2cBObJIe9FXkaXA8hKg8anZaX7jFQ+aJrH8Hxc+x7ZNTnOyjbuIWFF SowlZXf6oQbdFRuXDe2cxaHrgF4LzrN6aL6YzIRdmbAlXaDFS/SsDr2jC2WSzAzNYbN1NDglTIt DQEaWSmBO87x0CUpVnpGonCnidANjYeSNTsVEiT7KiFHfkOtI86sGIyiMZI0sEbyQ9Y12Nb6b7N 5o73uHLB7ZYnfj7H3UdU1fCdjPADMBaR/pZYE26gCuuKXNyhbHYHg3IY8PL4AeDjzEq9mf4yuVk BKbN79nUDZOzB5x6dL/eUL6TVUPhmuEvV3tM/bE3a9ZBNKsawLFP4vNYwVJPVjRUTnkpBwNzVEO Tec5+M8KpEjSbkCJWKcWmlS7wooE1B6/8xmveSGs45TKrIsMUmxyl8xCBXNDuVIbopBOJfuc5FU j2UK6Yd/cf7Bc6A== X-Developer-Key: i=rbm@suse.com; a=openpgp; fpr=030A8E9E424EE3C0655787E1C90B8A7C638658A6 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on in-5.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.7 at in-5.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v4 4/8] syscalls/mknod04: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re_via_ltp?= From: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Reply-To: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Cc: =?utf-8?q?Ricardo_B=2E_Marli=C3=A8re?= Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Ricardo B. Marlière Signed-off-by: Ricardo B. Marlière Reviewed-by: Andrea Cervesato --- 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 */ -/* - * 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: - * 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 -#include -#include -#include -#include -#include #include -#include -#include - -#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, +};