From patchwork Mon Aug 14 11:30:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1820987 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPXKv73wpz1yf2 for ; Mon, 14 Aug 2023 21:31:47 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0F01C3CD4D0 for ; Mon, 14 Aug 2023 13:31:46 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A2B243CCDD7 for ; Mon, 14 Aug 2023 13:31:31 +0200 (CEST) Received: from esa11.hc1455-7.c3s2.iphmx.com (esa11.hc1455-7.c3s2.iphmx.com [207.54.90.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 0E50E200960 for ; Mon, 14 Aug 2023 13:31:29 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10801"; a="107453385" X-IronPort-AV: E=Sophos;i="6.01,172,1684767600"; d="scan'208";a="107453385" Received: from unknown (HELO oym-r4.gw.nic.fujitsu.com) ([210.162.30.92]) by esa11.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 20:31:27 +0900 Received: from oym-m2.gw.nic.fujitsu.com (oym-nat-oym-m2.gw.nic.fujitsu.com [192.168.87.59]) by oym-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 4B571DE641 for ; Mon, 14 Aug 2023 20:31:24 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m2.gw.nic.fujitsu.com (Postfix) with ESMTP id 79870BF3C5 for ; Mon, 14 Aug 2023 20:31:23 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id E63876B803; Mon, 14 Aug 2023 20:31:22 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Mon, 14 Aug 2023 19:30:46 +0800 Message-Id: <1692012648-1970-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27812.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27812.006 X-TMASE-Result: 10--20.984900-10.000000 X-TMASE-MatchedRID: syh0yKfOqaTyq/cli2hvDU7nLUqYrlslFIuBIWrdOePEosIs7IJbkM+a lSM7Pep8j/bvtfhhXEtvp+b/wK4TT0m99yxxlnCoypiC33/79mcL//VMxXlyE8VlCE9ePslpEbx xHhRXg6L96UokutaAnH/2kt2fPfl2yerVBy1azTPZJrfdkZdZ1qj9/FPNtMXwGxcaNtdfmf0l/m i29q85l/29Pl68xfi0RNiIxTeXWS+InHjrjZy8lisIuzCLc2mNNmpKEeax85mEIBA870lREt93W 9FvgC9taz4PPTQqgvYT37J0rHCBEfhR9YlfgTUK194/5X9VfCxGmC2qcPUEPktYyuL5CqaxTbIv 25NGrv3RNGhNaHf3SGPKQgbIX4yu+/CYwUsia6FFrcjXqV+YAD92Og3IOZltMGqHura0AtGzhHc t+GcMBG5/m6vlvI+luGvA9nymq1lDQYe+1GQPNb0dPFETpBAHZgUJ0qWuzGc8zUakDfUiKxFEt9 7pQ+C82oaNzETwSs5dllc1XXqB23JjEpTLCKd7hdD+G7U5X/TvFrxMChrhqehMlzQE/9cKo8WMk QWv6iVfx6Zf83Do5eTCMddcL/gjkGUtrowrXLg= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/3] syscalls/setgroups01: 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- .../kernel/syscalls/setgroups/setgroups01.c | 210 ++---------------- 1 file changed, 23 insertions(+), 187 deletions(-) diff --git a/testcases/kernel/syscalls/setgroups/setgroups01.c b/testcases/kernel/syscalls/setgroups/setgroups01.c index fed7f8e5a..ca01997ae 100644 --- a/testcases/kernel/syscalls/setgroups/setgroups01.c +++ b/testcases/kernel/syscalls/setgroups/setgroups01.c @@ -1,202 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * Copyright (c) Linux Test Project, 2003-2023 * - * This program is free software; you can redistribute it and/or modify it - * under the terms of version 2 of the GNU General Public License as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it is - * free of the rightful claim of any third person regarding infringement - * or the like. Any license provided herein, whether implied or - * otherwise, applies only to this software file. Patent licenses, if - * any, provided herein do not apply to combinations of this program with - * other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * + * Author: William Roske + * CO-PILOT: Dave Fenner */ -/* $Id: setgroups01.c,v 1.7 2009/11/02 13:57:18 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : setgroups01 - * - * EXECUTED BY : root - * - * TEST TITLE : Basic test for setgroups(2) - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) setgroups(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the setgroups(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * setgroups(2). - * - * Setup: - * Setup signal handling. - * 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, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ - -#include -#include -#include -#include -#include -#include -#include "test.h" - -#include "compat_16.h" +/*\ + * [Description] + * + * Check the basic functionality of the setgroups() system call. + */ -void setup(); -void cleanup(); +#include "tst_test.h" +#include "compat_tst_16.h" -TCID_DEFINE(setgroups01); -int TST_TOTAL = 1; +static int len = NGROUPS; -int len = NGROUPS, ngrps = 0; -GID_T list[NGROUPS]; +static GID_T list[NGROUPS]; -int main(int ac, char **av) +static void verify_setgroups(void) { - int lc; - - /*************************************************************** - * parse standard options - ***************************************************************/ - tst_parse_opts(ac, av, NULL, NULL); - - /*************************************************************** - * perform global setup for test - ***************************************************************/ - setup(); - - /*************************************************************** - * check looping state if -c option given - ***************************************************************/ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call setgroups(2) - */ - TEST(SETGROUPS(cleanup, ngrps, list)); - - /* check return code */ - if (TEST_RETURN == -1) { - tst_resm(TFAIL, - "setgroups(%d, list) Failed, errno=%d : %s", - len, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - tst_resm(TPASS, - "setgroups(%d, list) returned %ld", - len, TEST_RETURN); - } - - } - - cleanup(); - tst_exit(); + TST_EXP_POSITIVE(SETGROUPS(1, list), "setgroups()"); } -/*************************************************************** - * setup() - performs all ONE TIME setup for this test. - ***************************************************************/ -void setup(void) +static void setup(void) { - - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - ngrps = GETGROUPS(cleanup, len, list); - if (ngrps == -1) { - tst_brkm(TBROK, cleanup, - "getgroups(%d, list) Failure. errno=%d : %s", - len, errno, strerror(errno)); - } + if (GETGROUPS(len, list) < 0) + tst_brk(TBROK | TERRNO, "getgroups() Failed"); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) -{ - -} +static struct tst_test test = { + .test_all = verify_setgroups, + .setup = setup, + .needs_root = 1, +}; From patchwork Mon Aug 14 11:30:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1820988 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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 (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPXL81dgSz1yf2 for ; Mon, 14 Aug 2023 21:32:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 37F093CD4C7 for ; Mon, 14 Aug 2023 13:31:58 +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 [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 31FA73CCDFA for ; Mon, 14 Aug 2023 13:31:36 +0200 (CEST) Received: from esa4.hc1455-7.c3s2.iphmx.com (esa4.hc1455-7.c3s2.iphmx.com [68.232.139.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id F146860080A for ; Mon, 14 Aug 2023 13:31:35 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10801"; a="128184976" X-IronPort-AV: E=Sophos;i="6.01,172,1684767600"; d="scan'208";a="128184976" Received: from unknown (HELO oym-r3.gw.nic.fujitsu.com) ([210.162.30.91]) by esa4.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 20:31:28 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id 8BFE2C53C0 for ; Mon, 14 Aug 2023 20:31:24 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id B27E6D8B3B for ; Mon, 14 Aug 2023 20:31:23 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 3B28E70B25; Mon, 14 Aug 2023 20:31:23 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Mon, 14 Aug 2023 19:30:47 +0800 Message-Id: <1692012648-1970-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1692012648-1970-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1692012648-1970-1-git-send-email-xuyang2018.jy@fujitsu.com> X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27812.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27812.006 X-TMASE-Result: 10--15.179000-10.000000 X-TMASE-MatchedRID: EnBx19Ky1wTyq/cli2hvDU7nLUqYrlslFIuBIWrdOePEosIs7IJbkIh+ mL+ciFCpbnRB47KLJ1QzLmfGY6iDkX5uUfhNvnKzOWUWxTQJdI8UZYubbUj2DLt4BAaULwAVJf5 otvavOZf9vT5evMX4tJhCh8+WImJUkto8AKCDbo7X3j/lf1V8LDYvC/PFFfSAUoXFjv/N8aLovg fcZYFfbTyZ7dOmU5ZqQOYg55Cp68FujdbubeNfIzz6L+U/pejxtOtXYgbXjdfG5dXdQTj2OFRG1 tpaU7lUOE2afT3WQTEj0rAExlIQHoq5N4VAmkR8/1dEgwtQ6NAyLlxWhS9T9jxzAG47ocHfhN0K b2jI1UnX1u63/F4Cq9EqY6Wu67PODHfyPZwXxjldhZyafgPiqx+KaaVwAG43JLfQYoCQHFZbK2q mKUaX1kQD9vOU9UhO3JT0Jb3lWGqFWCPo3rDAcOX5IyMNrotPPCIk0y3reGa6u7UV1z+eRqPFjJ EFr+olwXCBO/GKkVqOhzOa6g8KrS3dLEfP2qdxuJW3Xky9kxhgelZguODYJ7xGLJbITzr1eruGf NwFV44= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v3 2/3] syscalls/setgroups02: 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- .../kernel/syscalls/setgroups/setgroups02.c | 193 +++--------------- 1 file changed, 31 insertions(+), 162 deletions(-) diff --git a/testcases/kernel/syscalls/setgroups/setgroups02.c b/testcases/kernel/syscalls/setgroups/setgroups02.c index de23a4a7f..8cb0d1cfd 100644 --- a/testcases/kernel/syscalls/setgroups/setgroups02.c +++ b/testcases/kernel/syscalls/setgroups/setgroups02.c @@ -1,180 +1,49 @@ +// 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 + * Copyright (c) Linux Test Project, 2003-2023 + * 07/2001 Ported by Wayne Boyer */ -/* - * Test Name: setgroups02 - * - * Test Description: - * Verify that, only root process can invoke setgroups() system call to - * set the supplementary group IDs of the process. - * - * Expected Result: - * The call succeeds in setting all the supplementary group IDs of the - * calling process. The new group should be set in the process supplemental - * group list. - * - * Algorithm: - * Setup: - * Setup signal handling. - * 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 +/*\ + * [Description] * - * Usage: - * setgroups02 [-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. + * Check that only the root process can invoke setgroups() + * to set supplementary group IDs. * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS: - * This test should be run by 'super-user' (root) only. + * [Expected Result] * + * The call succeeds in setting all the supplementary group IDs + * of the calling process. The new group should be set in the + * process supplemental group list. */ -#include -#include -#include -#include -#include -#include - -#include "test.h" - -#include "compat_16.h" - -#define TESTUSER "nobody" - -TCID_DEFINE(setgroups02); -int TST_TOTAL = 1; /* Total number of test conditions */ -GID_T groups_list[NGROUPS]; /* Array to hold gids for getgroups() */ - -struct passwd *user_info; /* struct. to hold test user info */ -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) -{ - int lc, i; - int gidsetsize = 1; /* only one GID, the GID of TESTUSER */ - int PASS_FLAG = 0; /* used for checking group array */ - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call setgroups() to set supplimentary group IDs of - * the calling super-user process to gid of TESTUSER. - */ - TEST(SETGROUPS(cleanup, gidsetsize, groups_list)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "setgroups(%d, groups_list) Failed, " - "errno=%d : %s", gidsetsize, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } +#include - /* - * Call getgroups(2) to verify that - * setgroups(2) successfully set the - * supp. gids of TESTUSER. - */ - groups_list[0] = '\0'; - if (GETGROUPS(cleanup, gidsetsize, groups_list) < 0) { - tst_brkm(TFAIL, cleanup, "getgroups() Fails, " - "error=%d", errno); - } - for (i = 0; i < NGROUPS; i++) { - if (groups_list[i] == user_info->pw_gid) { - tst_resm(TPASS, - "Functionality of setgroups" - "(%d, groups_list) successful", - gidsetsize); - PASS_FLAG = 1; - } - } - if (PASS_FLAG == 0) { - tst_resm(TFAIL, "Supplimentary gid %d not set " - "for the process", user_info->pw_gid); - } - } +#include "tst_test.h" +#include "compat_tst_16.h" - cleanup(); - tst_exit(); -} +static GID_T *groups_get, *groups_set; -/* - * setup() - performs all ONE TIME setup for this test. - * - * Make sure the test process uid is root. - * Get the supplimentrary group id of test user from /etc/passwd file. - */ -void setup(void) +static void verify_setgroups(void) { + groups_set[0] = 42; - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + TST_EXP_PASS(SETGROUPS(1, groups_set)); - TEST_PAUSE; + TST_EXP_VAL(GETGROUPS(1, groups_get), 1); - /* Get the group id info. of TESTUSER from /etc/passwd */ - if ((user_info = getpwnam(TESTUSER)) == NULL) { - tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER); - } + TST_EXP_EQ_LI(groups_get[0], groups_set[0]); - if (!GID_SIZE_CHECK(user_info->pw_gid)) { - tst_brkm(TBROK, - cleanup, - "gid returned from getpwnam is too large for testing setgroups16"); - } - - groups_list[0] = user_info->pw_gid; + groups_get[0] = 0; } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - -} +static struct tst_test test = { + .test_all = verify_setgroups, + .bufs = (struct tst_buffers []) { + {&groups_get, .size = sizeof(GID_T)}, + {&groups_set, .size = sizeof(GID_T)}, + {}, + }, + .needs_root = 1, +}; From patchwork Mon Aug 14 11:30:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1820985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=) 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RPXKh0dDMz1yfg for ; Mon, 14 Aug 2023 21:31:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 422613CCE38 for ; Mon, 14 Aug 2023 13:31:33 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 93FF23C65F4 for ; Mon, 14 Aug 2023 13:31:30 +0200 (CEST) Received: from esa1.hc1455-7.c3s2.iphmx.com (esa1.hc1455-7.c3s2.iphmx.com [207.54.90.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id D2F2D20093E for ; Mon, 14 Aug 2023 13:31:29 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6600,9927,10801"; a="127921051" X-IronPort-AV: E=Sophos;i="6.01,172,1684767600"; d="scan'208";a="127921051" Received: from unknown (HELO yto-r3.gw.nic.fujitsu.com) ([218.44.52.219]) by esa1.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2023 20:31:27 +0900 Received: from yto-m1.gw.nic.fujitsu.com (yto-nat-yto-m1.gw.nic.fujitsu.com [192.168.83.64]) by yto-r3.gw.nic.fujitsu.com (Postfix) with ESMTP id A7760D501A for ; Mon, 14 Aug 2023 20:31:24 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id F2ABCCFAB1 for ; Mon, 14 Aug 2023 20:31:23 +0900 (JST) Received: from localhost.localdomain (unknown [10.167.215.131]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 77BD170B2E; Mon, 14 Aug 2023 20:31:23 +0900 (JST) From: Yang Xu To: ltp@lists.linux.it Date: Mon, 14 Aug 2023 19:30:48 +0800 Message-Id: <1692012648-1970-3-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1692012648-1970-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1692012648-1970-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-27812.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-27812.006 X-TMASE-Result: 10--14.939500-10.000000 X-TMASE-MatchedRID: UHPlrx36cywAzT8btdR146zGfgakLdjaCZa9cSpBObmkob0Y35+HFI3c eRXYSJoDIvrftAIhWmLP85tlrdTfE4+kj9iRsuif7TovvZPhLcB1zSnwpu89bft9kl8N0Ihcj3d ZSyALReJZZO2km095FRza9vQBPvMp2FMcgddyBa+RgPzABkqxIJ+Z30eyNnRTTPm/MsQarwOTwS +tHNykeFCEg9OsBDUFoWjx8y7f3ImcfX6Ug1yFMJUXYcPwQc2nOA3W7N7dBgnfc2Xd6VJ+yodG5 Deyz2OttFyW7k8xSBFS4pfvQyHLzGj+Msn9Q6VoqNtC2YatSIlpkBMYDn8FeE2q2vj1g2Nh4Wj9 iaClAkk4Bt3LKju+riXHp1pX6kfOCtNdSL7NMxQF7cpFXK76TReK/B+WKxKsvlNWrA7PGPyg6SD UFo25mqsislIb+lkwoWjx8y7f3InSJlb/fq4fiqz+FzWjUOLzfrTt+hmA5bKMltxkB8Rw01sraq YpRpfWRAP285T1SE41wOHlbbYzTQlEXXe75zyCi95/KnWCU3Q217sBakpdK33lj93joBiubWqU+ jtUG9Mqtq5d3cxkNUhQ9pL/1/Lzz4MJY7Stj4kI2VmCkd9zAn8dEvpWbRtSXBv9skmsTTI= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Virus-Scanned: clamav-milter 1.0.1 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v3 3/3] syscalls/setgroups03: 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1.merge setgroups04 to setgroups03 2.use safe_macro macro Signed-off-by: Yang Xu --- runtest/syscalls | 2 - .../kernel/syscalls/setgroups/.gitignore | 2 - .../kernel/syscalls/setgroups/setgroups03.c | 247 ++++-------------- .../kernel/syscalls/setgroups/setgroups04.c | 163 ------------ 4 files changed, 56 insertions(+), 358 deletions(-) delete mode 100644 testcases/kernel/syscalls/setgroups/setgroups04.c diff --git a/runtest/syscalls b/runtest/syscalls index 1028e45fc..119710d63 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1331,8 +1331,6 @@ setgroups02 setgroups02 setgroups02_16 setgroups02_16 setgroups03 setgroups03 setgroups03_16 setgroups03_16 -setgroups04 setgroups04 -setgroups04_16 setgroups04_16 sethostname01 sethostname01 sethostname02 sethostname02 diff --git a/testcases/kernel/syscalls/setgroups/.gitignore b/testcases/kernel/syscalls/setgroups/.gitignore index 0649a3425..9de928241 100644 --- a/testcases/kernel/syscalls/setgroups/.gitignore +++ b/testcases/kernel/syscalls/setgroups/.gitignore @@ -4,5 +4,3 @@ /setgroups02_16 /setgroups03 /setgroups03_16 -/setgroups04 -/setgroups04_16 diff --git a/testcases/kernel/syscalls/setgroups/setgroups03.c b/testcases/kernel/syscalls/setgroups/setgroups03.c index 490b06996..d0331b216 100644 --- a/testcases/kernel/syscalls/setgroups/setgroups03.c +++ b/testcases/kernel/syscalls/setgroups/setgroups03.c @@ -1,222 +1,87 @@ +// 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) Bull S.A. 2001 + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) Linux Test Project, 2003-2023 + * 07/2001 Ported by Wayne Boyer + * 05/2002 Ported by AndrĂ© Merlier */ -/* - * Test Name: setgroups03 - * - * Test Description: - * Verify that, - * 1. setgroups() fails with -1 and sets errno to EINVAL if the size - * argument value is > NGROUPS - * 2. setgroups() fails with -1 and sets errno to EPERM if the - * calling process is not super-user. +/*\ + * [Description] * - * Expected Result: - * setgroups() should fail with return value -1 and set expected errno. + * Test for EINVAL, EPERM, EFAULT errors. * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. + * - setgroups() fails with EINVAL if the size argument value is > NGROUPS. * - * 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 - * - * Usage: - * setgroups03 [-c n] [-e] [-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 executed by 'non-super-user' only. + * - setgroups() fails with EPERM if the calling process is not super-user. * + * - setgroups() fails with EFAULT if the list has an invalid address. */ -#include -#include -#include -#include -#include -#include -#include "test.h" +#include +#include -#include "compat_16.h" +#include "tst_test.h" +#include "compat_tst_16.h" #define TESTUSER "nobody" -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -TCID_DEFINE(setgroups03); -int TST_TOTAL = 2; - -GID_T *groups_list; /* Array to hold gids for getgroups() */ +static GID_T *glist1, *glist2, *glist3; +static struct passwd *user_info; -int setup1(); /* setup function to test error EPERM */ -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -struct test_case_t { /* test case struct. to hold ref. test cond's */ - size_t gsize_add; - int list; - char *desc; +static struct tcase { + int gsize; + GID_T **glist; int exp_errno; - int (*setupfunc) (); -} Test_cases[] = { - { - 1, 1, "Size is > sysconf(_SC_NGROUPS_MAX)", EINVAL, NULL}, { - 0, 2, "Permission denied, not super-user", EPERM, setup1} +} tcases[] = { + {NGROUPS + 1, &glist1, EINVAL}, + {NGROUPS, &glist2, EPERM}, + {NGROUPS, &glist3, EFAULT}, }; -int main(int ac, char **av) +static void verify_setgroups(unsigned int i) { - int lc; - int gidsetsize; /* total no. of groups */ - int i; - char *test_desc; /* test specific error message */ - int ngroups_max = sysconf(_SC_NGROUPS_MAX); /* max no. of groups in the current system */ - - tst_parse_opts(ac, av, NULL, NULL); - - groups_list = malloc(ngroups_max * sizeof(GID_T)); - if (groups_list == NULL) { - tst_brkm(TBROK, NULL, "malloc failed to alloc %zu errno " - " %d ", ngroups_max * sizeof(GID_T), errno); - } - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - if (Test_cases[i].setupfunc != NULL) { - Test_cases[i].setupfunc(); - } + struct tcase *tc = &tcases[i]; - gidsetsize = ngroups_max + Test_cases[i].gsize_add; - test_desc = Test_cases[i].desc; + if (tc->exp_errno == EPERM) + SAFE_SETEUID(user_info->pw_uid); - /* - * Call setgroups() to test different test conditions - * verify that it fails with -1 return value and - * sets appropriate errno. - */ - TEST(SETGROUPS(cleanup, gidsetsize, groups_list)); + TST_EXP_FAIL(SETGROUPS(tc->gsize, *tc->glist), tc->exp_errno, + "setgroups(%d, groups_list)", tc->gsize); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "setgroups(%d) returned %ld, " - "expected -1, errno=%d", gidsetsize, - TEST_RETURN, Test_cases[i].exp_errno); - continue; - } - - if (TEST_ERRNO == Test_cases[i].exp_errno) { - tst_resm(TPASS, - "setgroups(%d) fails, %s, errno=%d", - gidsetsize, test_desc, TEST_ERRNO); - } else { - tst_resm(TFAIL, "setgroups(%d) fails, %s, " - "errno=%d, expected errno=%d", - gidsetsize, test_desc, TEST_ERRNO, - Test_cases[i].exp_errno); - } - } - - } - - cleanup(); - - tst_exit(); + if (tc->exp_errno == EPERM) + SAFE_SETEUID(0); } -/* - * setup() - performs all ONE TIME setup for this test. - * - * Call individual test specific setup functions. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + glist1 = SAFE_MALLOC((NGROUPS + 1) * sizeof(GID_T)); - TEST_PAUSE; + user_info = SAFE_GETPWNAM(TESTUSER); + GID16_CHECK(user_info->pw_gid, getpwnam); + glist2 = (GID_T *)&(user_info->pw_gid); + glist3 = tst_get_bad_addr(NULL); } -/* - * setup1 - Setup function to test setgroups() which returns -1 - * and sets errno to EPERM. - * - * Get the user info. from /etc/passwd file. - * This function returns 0 on success. - */ -int setup1(void) +static void cleanup(void) { - struct passwd *user_info; /* struct. to hold test user info */ - -/* Switch to nobody user for correct error code collection */ - ltpuser = getpwnam(nobody_uid); - if (seteuid(ltpuser->pw_uid) == -1) { - tst_resm(TINFO, "setreuid failed to " - "to set the effective uid to %d", ltpuser->pw_uid); - perror("setreuid"); - } - - if ((user_info = getpwnam(TESTUSER)) == NULL) { - tst_brkm(TFAIL, cleanup, "getpwnam(2) of %s Failed", TESTUSER); - } - - if (!GID_SIZE_CHECK(user_info->pw_gid)) { - tst_brkm(TBROK, - cleanup, - "gid returned from getpwnam is too large for testing setgroups16"); - } - groups_list[0] = user_info->pw_gid; - return 0; + if (glist1) + free(glist1); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - -} +static struct tst_test test = { + .test = verify_setgroups, + .tcnt = ARRAY_SIZE(tcases), + .bufs = (struct tst_buffers []) { + {&glist1, .size = sizeof(GID_T)}, + {&glist2, .size = sizeof(GID_T)}, + {&glist3, .size = sizeof(GID_T)}, + {&user_info, .size = sizeof(struct passwd)}, + {}, + }, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, +}; diff --git a/testcases/kernel/syscalls/setgroups/setgroups04.c b/testcases/kernel/syscalls/setgroups/setgroups04.c deleted file mode 100644 index 971c86bd2..000000000 --- a/testcases/kernel/syscalls/setgroups/setgroups04.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) Bull S.A. 2001 - * 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 - */ - -/* - * Test Name: setgroups04 - * - * Test Description: - * Verify that, setgroups() fails with -1 and sets errno to EFAULT if the list has an invalid address. - * - * Expected Result: - * setgroups() should fail with return value -1 and set expected errno. - * - * Algorithm: - * Setup: - * Setup signal handling. - * 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 - * - * Usage: - * setgroups04 [-c n] [-e] [-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 - * 05/2002 Ported by André Merlier - * - * RESTRICTIONS: - * none. - * - */ -#include -#include -#include -#include -#include -#include - -#include "test.h" - -#include "compat_16.h" - -TCID_DEFINE(setgroups04); -int TST_TOTAL = 1; - -GID_T groups_list[NGROUPS]; - -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -#if !defined(UCLINUX) - -int main(int ac, char **av) -{ - int lc; - int gidsetsize; /* total no. of groups */ - char *test_desc; /* test specific error message */ - - tst_parse_opts(ac, av, NULL, NULL); - - /* Perform setup for test */ - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - gidsetsize = NGROUPS; - test_desc = "EFAULT"; - - /* - * Call setgroups() to test condition - * verify that it fails with -1 return value and - * sets appropriate errno. - */ - TEST(SETGROUPS(cleanup, gidsetsize, sbrk(0))); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "setgroups() returned %ld, " - "expected -1, errno=%d", TEST_RETURN, - EFAULT); - } else { - - if (TEST_ERRNO == EFAULT) { - tst_resm(TPASS, - "setgroups() fails with expected " - "error EFAULT errno:%d", TEST_ERRNO); - } else { - tst_resm(TFAIL, "setgroups() fails, %s, " - "errno=%d, expected errno=%d", - test_desc, TEST_ERRNO, EFAULT); - } - } - - } - - cleanup(); - tst_exit(); - -} - -#else - -int main(void) -{ - tst_resm(TINFO, "test is not available on uClinux"); - tst_exit(); -} - -#endif /* if !defined(UCLINUX) */ - -/* - * setup() - */ -void setup(void) -{ - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - -} - -/* - * cleanup() - */ -void cleanup(void) -{ - -}