From patchwork Mon Nov 5 23:50:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 150232 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231254ljp; Mon, 5 Nov 2018 15:51:10 -0800 (PST) X-Google-Smtp-Source: AJdET5ejirxhikYzUI0CZyB6UgMwhbSQS+eTM5/tpdwQpBm26Wqt5rt1SKFhoQlrE9Ymd043wWFu X-Received: by 2002:a50:ca47:: with SMTP id e7-v6mr19590749edi.56.1541461870463; Mon, 05 Nov 2018 15:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461870; cv=none; d=google.com; s=arc-20160816; b=uMCfj5u8e5zURJifsmnazfGXqacljql7PS4S0TTgzfhc9+tOB+YxMJS8CJF5YTok0l O58IzraIFU0xThd0WMuKuuwp3A8NU5QcHHh6cjHfK45gJyLV7pbSHjOx8ZoxKpjdrPsl 1zyKV960DyIeIHCt9OuQ7cQgZpq09zVHKxhkCcJPdPw75Cs6G3UYY70pdKJi4SIIsugR uCy2T4rsNgywmMvPJn2KzYbFjrnSjUzcUk8xWO41ICYGMJowR8rZZ8YqMZ/Km02xSnXT pQGAo3lYnjUchnHjo1WDOIgEOHVOX4WwsmLe85CpXCgY+69+IBrpIcC+ioROwOCoTGfe 3itQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=lNMuS7I0bnUn90Umtq6WIkaF/0/Rtlg6Lv/aeRLokoU=; b=pbaOAvWXKRAoJeV6e2/k8dcLzzI8DSdBx+krhp+mdbFwecZD4rzI/ecu3xLyQOpELV tR8BnK7HePoZW8ZnYXUpsrxD3GqYjY/JQWfj/zwLFJbMnaic9W7qPDtLs3YdSTNTMJtO VM3FfEXTCRXf0JO6o73FQsnaKoJpXz0pU06lyZ3+7Hj3KEF8Rfg42iYEJibIVdnfpGxG zB7uakpwl15EhghcwzVa+Rmo9puT2aGN7H0wylxwQhJdVif4Zw4b/Chb+chXGp+IQ9RW 5cgrpNnWB8wPz56Gq2J/NTxAhl5PSN6Kc7CX9JJckoDgqRioO5XnDEv31yATM8S+Nqqp eWlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b="TMmO/vtA"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=google.com Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id b12si430546edx.434.2018.11.05.15.51.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:51:10 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b="TMmO/vtA"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=google.com Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 194693E790E for ; Tue, 6 Nov 2018 00:51:10 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id EACB53E7844 for ; Tue, 6 Nov 2018 00:50:55 +0100 (CET) Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id CC8A5600864 for ; Tue, 6 Nov 2018 00:50:54 +0100 (CET) Received: by mail-pl1-x643.google.com with SMTP id g59-v6so5226822plb.10 for ; Mon, 05 Nov 2018 15:50:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zU8XyZL7u1AEj41rMw76j0le0mwfuRmLIfSkrFXb7RI=; b=TMmO/vtAjtxyQ77PsPA4KDWsaXdoXGAtMX/Q3fL/kSQdTizrTlP8zPRfb161k+Tzz4 r7pfFpzGlGxWiCZrKiDgOrWHLgg7t+/sRmEljXRD2DLg9hK4gQij30BtQbtghu+ZYB03 UibU79YtQV5rePfK14H8AfMaZWTBfrjBVf3edMMM4dv7VWXcZL7811qPAe24ympYgnok iFwXjghZcJSWR0qR27dd8LI/fiSJ/kucR4L5tHr8X2cjWViMU7UgCpfgGwpiHoP9/T92 Bc+bwWC3SJgYbP6e+EPm/NcqPsbbfty1HXUiN3duHLgGyyAniXbLMqEVA5JhXgmQFJdz chfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zU8XyZL7u1AEj41rMw76j0le0mwfuRmLIfSkrFXb7RI=; b=huvoU0agT/ECOpC0UhYNI0aDxfedLzkoDRkSx0bwfBSM4XJsJw1PRedy5T6HuPhUHC qw6eG+l/Sgvq4p0mwaTqsPf/NC7FS8Mo0d6VfPedEJKKLAqzkwvYLGmYt8BWwFiyyAwJ G4jP3BmLiOVqfP8Q45TxzEx2L9En0yiYrMRD4hOMVlFGersv6Sbtojk9ArC7ojm2FBvX YXUKjip1/jfcSH+O5DmtzYG7Z5sSRMoIpQKysCUhdq8dV37typQpi4enKJ/OihQc2NJC NAKGx6qXF2SUPqK3ty2fCLnNQXYzY9USmzUNBL0W/YIf1c8kBzTbJrfj3KLEBnWiXJ+B GwgQ== X-Gm-Message-State: AGRZ1gJNpaFTvgHt0fjtov3sBY7mDGVCwIwnUQWy90DoxlyCl/XLMyMn tFka/NJ06tWJwl8IGZe9j5Bxuz7wc6caPQ== X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr22979606plf.73.1541461852337; Mon, 05 Nov 2018 15:50:52 -0800 (PST) Received: from sspatil-workstation.mtv.corp.google.com ([2620:0:1000:1601:1a43:e60e:c432:d19c]) by smtp.gmail.com with ESMTPSA id c70-v6sm27133925pfg.97.2018.11.05.15.50.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:51 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:18 -0800 Message-Id: <20181105235019.254846-5-sspatil@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181105235019.254846-1-sspatil@google.com> References: <20181105235019.254846-1-sspatil@google.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-14.9 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: kernel-team@android.com, rpalethorpe@suse.com Subject: [LTP] [PATCH 4/5] syscalls/chmod05: Use new ltp library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Use SPDX-Licence-Identifier and delete dead comments / code while at it. Signed-off-by: Sandeep Patil --- testcases/kernel/syscalls/chmod/chmod05.c | 187 ++++------------------ 1 file changed, 33 insertions(+), 154 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c index 3cf4db5d0..c18a4778a 100644 --- a/testcases/kernel/syscalls/chmod/chmod05.c +++ b/testcases/kernel/syscalls/chmod/chmod05.c @@ -1,30 +1,12 @@ +/// SPDX-License-Identifier: GPL-2.0 /* - * * 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: chmod05 * * Test Description: -//wjh -//This test seems to be invalid see comments below -//The man page for chmod doesn't seem to indicate that the setgid bit can -//only be set by root * Verify that, chmod(2) will succeed to change the mode of a directory * but fails to set the setgid bit on it if invoked by non-root (uid != 0) * process with the following constraints, @@ -36,48 +18,6 @@ * chmod() should return value 0 on success and though succeeds to change * the mode of a directory but fails to set setgid bit on it. * - * 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: - * chmod05 [-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 - * 05/2002 Fixes by wjhuie and Ferhan Shareef - * changed conditional to check for valid tests only and - * in a more logically understandable way - * 07/2002 Additional fixes to #defines to allow comparisions to work. - * -Robbie Williamson - * - * RESTRICTIONS: - * This test should be run by root. - * */ #ifndef _GNU_SOURCE @@ -96,126 +36,65 @@ #include #include -#include "test.h" -#include "safe_macros.h" - -#define DEBUG 0 +#include "tst_test.h" #define MODE_RWX (mode_t)(S_IRWXU | S_IRWXG | S_IRWXO) #define DIR_MODE (mode_t)(S_ISVTX | S_ISGID | S_IFDIR) #define PERMS (mode_t)(MODE_RWX | DIR_MODE) #define TESTDIR "testdir" -char *TCID = "chmod05"; -int TST_TOTAL = 1; - -void setup(); /* Main setup function for test */ -void cleanup(); /* Main cleanup function for test */ - -int main(int ac, char **av) +void test_chmod(void) { struct stat stat_buf; /* stat struct */ - int lc; mode_t dir_mode; /* mode permissions set on test directory */ - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - TEST(chmod(TESTDIR, PERMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "chmod(%s, %#o) failed", - TESTDIR, PERMS); - continue; - } - /* - * Get the directory information using - * stat(2). - */ - if (stat(TESTDIR, &stat_buf) < 0) { - tst_brkm(TFAIL | TERRNO, cleanup, - "stat(%s) failed", TESTDIR); - } - dir_mode = stat_buf.st_mode; -#if DEBUG - printf("DIR_MODE = 0%03o\n", DIR_MODE); - printf("MODE_RWX = 0%03o\n", MODE_RWX); - printf("PERMS = 0%03o\n", PERMS); - printf("dir_mode = 0%03o\n", dir_mode); -#endif - if ((PERMS & ~S_ISGID) != dir_mode) - tst_resm(TFAIL, "%s: Incorrect modes 0%03o, " - "Expected 0%03o", TESTDIR, dir_mode, - PERMS & ~S_ISGID); - else - tst_resm(TPASS, - "Functionality of chmod(%s, %#o) successful", - TESTDIR, PERMS); + TEST(chmod(TESTDIR, PERMS)); + if (TST_RET == -1) { + tst_res(TFAIL, "chmod(%s, %#o) failed", TESTDIR, PERMS); } - cleanup(); - tst_exit(); + /* Get the directory information using stat(2) and compare with + * expected results. + */ + SAFE_STAT(TESTDIR, &stat_buf); + dir_mode = stat_buf.st_mode; + if ((PERMS & ~S_ISGID) != dir_mode) { + tst_res(TFAIL, "%s: Incorrect modes 0%03o, " + "Expected 0%03o", TESTDIR, dir_mode, + PERMS & ~S_ISGID); + } else { + tst_res(TPASS, "Functionality of chmod(%s, %#o) successful", + TESTDIR, PERMS); + } } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and cd to it. - * Create a test directory under temporary directory. -//wjh we are root so do we really need this kluged helper program? - * Invoke setuid to root program to modify group ownership - * on test directory. - */ void setup(void) { struct passwd *nobody_u; - struct group *bin_group; - - tst_require_root(); + struct group *bin_gr; - TEST_PAUSE; - - tst_tmpdir(); - - nobody_u = getpwnam("nobody"); - if (nobody_u == NULL) - tst_brkm(TBROK | TERRNO, cleanup, - "getpwnam(\"nobody\") failed"); - - bin_group = getgrnam("bin"); - if (bin_group == NULL) - tst_brkm(TBROK | TERRNO, cleanup, "getgrnam(\"bin\") failed"); + nobody_u = SAFE_GETPWNAM("nobody"); + bin_gr = SAFE_GETGRNAM("bin"); /* * Create a test directory under temporary directory with specified * mode permissions and change the gid of test directory to nobody's * gid. */ - SAFE_MKDIR(cleanup, TESTDIR, MODE_RWX); - + SAFE_MKDIR(TESTDIR, MODE_RWX); if (setgroups(1, &nobody_u->pw_gid) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "setgroups to nobody's gid failed"); + tst_brk(TBROK | TERRNO, "setgroups to nobody's gid failed"); - SAFE_CHOWN(cleanup, TESTDIR, nobody_u->pw_uid, bin_group->gr_gid); + SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, bin_group->gr_gid); /* change to nobody:nobody */ - if (setegid(nobody_u->pw_gid) == -1 || seteuid(nobody_u->pw_uid) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "Couldn't switch to nobody:nobody"); + SAGE_SETEGID(nobody_u->pw_gid); + SAFE_SETEUID(nobody_u->pw_uid); } -void cleanup(void) -{ - if (setegid(0) == -1) - tst_resm(TWARN | TERRNO, "setegid(0) failed"); - if (seteuid(0) == -1) - tst_resm(TWARN | TERRNO, "seteuid(0) failed"); - - tst_rmdir(); -} +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .setup = setup, + .test_all = test_chmod, +};