From patchwork Fri Sep 3 15:48:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524401 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=erSGSqri; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=t5Eg/JFn; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1Mfz2g8Cz9sPf for ; Sat, 4 Sep 2021 01:49:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AE52E3C98E0 for ; Fri, 3 Sep 2021 17:49:20 +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 RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id AA6273C2862 for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 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 8DB8260106C for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E1B7D226F0 for ; Fri, 3 Sep 2021 15:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684129; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HMDE7wgnvmiJRxvFuF3tAlgheGdFeoCoulNsFQjLAzk=; b=erSGSqriphdWMI219fPiLee88SeK3Wi1kHT8KNoETo2ZjVuc6Up4R1DCd/bt9j0yuvwBuf j5+oxm60j2gUCPgNdZd+MwIjTRVCo0irQDJDmFWU5MBOFuKUq4aytErqlWTPtMZLGiQmgo ciNX7dUFQC39RtQd/cxzruCdw8zp91s= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684129; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HMDE7wgnvmiJRxvFuF3tAlgheGdFeoCoulNsFQjLAzk=; b=t5Eg/JFngBBdLE0IHI3oE1wulgJ5VdDdllI8hscQcx3GoampYoMmEUeo8fBoqjrXPFz39j EE47tJLaNYTdl4Bg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C303D13B86 for ; Fri, 3 Sep 2021 15:48:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ENeZLuFDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:49 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:42 +0200 Message-Id: <20210903154848.18705-2-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 1/7] chmod05, fchmod05: Use free GID instead of "bin" group 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" The bin user group does not exist on some systems which will cause test failure. Set test directory ownership to any unused GID instead. Signed-off-by: Martin Doucha --- testcases/kernel/syscalls/chmod/chmod05.c | 7 ++++--- testcases/kernel/syscalls/fchmod/fchmod05.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c index 6a6a0ae21..f5b9d51e7 100644 --- a/testcases/kernel/syscalls/chmod/chmod05.c +++ b/testcases/kernel/syscalls/chmod/chmod05.c @@ -37,6 +37,7 @@ #include #include "tst_test.h" +#include "tst_uid.h" #define MODE_RWX (mode_t)(S_IRWXU | S_IRWXG | S_IRWXO) #define DIR_MODE (mode_t)(S_ISVTX | S_ISGID | S_IFDIR) @@ -69,10 +70,10 @@ static void test_chmod(void) static void setup(void) { struct passwd *nobody_u; - struct group *bin_gr; + gid_t free_gid; nobody_u = SAFE_GETPWNAM("nobody"); - bin_gr = SAFE_GETGRNAM("bin"); + free_gid = tst_get_free_gid(nobody_u->pw_gid); /* * Create a test directory under temporary directory with specified @@ -83,7 +84,7 @@ static void setup(void) if (setgroups(1, &nobody_u->pw_gid) == -1) tst_brk(TBROK | TERRNO, "setgroups to nobody's gid failed"); - SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, bin_gr->gr_gid); + SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, free_gid); /* change to nobody:nobody */ SAFE_SETEGID(nobody_u->pw_gid); diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c index f75b9bf36..0c731d601 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod05.c +++ b/testcases/kernel/syscalls/fchmod/fchmod05.c @@ -20,6 +20,7 @@ #include #include "tst_test.h" +#include "tst_uid.h" #include "fchmod.h" #define PERMS_DIR 043777 @@ -50,10 +51,10 @@ static void verify_fchmod(void) static void setup(void) { struct passwd *ltpuser; - struct group *ltpgroup; + gid_t free_gid; ltpuser = SAFE_GETPWNAM("nobody"); - ltpgroup = SAFE_GETGRNAM("bin"); + free_gid = tst_get_free_gid(ltpuser->pw_gid); SAFE_MKDIR(TESTDIR, DIR_MODE); @@ -62,7 +63,7 @@ static void setup(void) tst_strerrno(TST_ERR)); } - SAFE_CHOWN(TESTDIR, ltpuser->pw_uid, ltpgroup->gr_gid); + SAFE_CHOWN(TESTDIR, ltpuser->pw_uid, free_gid); SAFE_SETEGID(ltpuser->pw_gid); SAFE_SETEUID(ltpuser->pw_uid); From patchwork Fri Sep 3 15:48:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=qsauB9T/; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=YvOk7qRx; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1Mfd331tz9sPf for ; Sat, 4 Sep 2021 01:49:13 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 537873C73AB for ; Fri, 3 Sep 2021 17:49:11 +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 RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A4BE33C27DB for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 9AB3E2010A0 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id EABB222728 for ; Fri, 3 Sep 2021 15:48:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684129; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q6Ndiga4VHgWireYjM6kSQwTql+J/c3KBMdDA56DhuI=; b=qsauB9T/u6YxCd2seFWcfeWHMqbGywqnyFUWO8wc45HLE39wCAOFpbftKgm1Z6qZPRBi24 vmAewc8d80yJ0fnsuaeR+wIx16+DmnvM6/Skn65QL1ZOyXCphOR6ImAwnLfALc0PfLXl1P +nJodk7dXvXh54CsKY6Anz8Fs28i134= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684129; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q6Ndiga4VHgWireYjM6kSQwTql+J/c3KBMdDA56DhuI=; b=YvOk7qRxEMLnwmsbsgn8Omxj87/8H1JnKNgGecy7ibrK06EXMRM+2PZ8uS25G23HC0lz+o TouQbje07rfzfoAg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D87D713B08 for ; Fri, 3 Sep 2021 15:48:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8PTmM+FDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:49 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:43 +0200 Message-Id: <20210903154848.18705-3-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 2/7] Simplify syscalls/mkdir02 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" mkdir02 does a lot of unnecessary fork()ing left over from the old version. The same test can be done with just user "nobody", one unused GID and no fork()ing at all. Signed-off-by: Martin Doucha --- testcases/kernel/syscalls/mkdir/mkdir02.c | 77 +++++++---------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/testcases/kernel/syscalls/mkdir/mkdir02.c b/testcases/kernel/syscalls/mkdir/mkdir02.c index f09e3c33d..2cb199c56 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir02.c +++ b/testcases/kernel/syscalls/mkdir/mkdir02.c @@ -9,85 +9,57 @@ * bit is set in the parent directory. */ -#include #include #include #include -#include -#include -#include #include "tst_test.h" +#include "tst_uid.h" #define TESTDIR1 "testdir1" #define TESTDIR2 "testdir1/testdir2" -static uid_t nobody_uid, bin_uid; -static gid_t nobody_gid, bin_gid; +static gid_t free_gid; static void verify_mkdir(void) { - struct stat buf1, buf2; - pid_t pid; + struct stat statbuf; int fail = 0; - pid = SAFE_FORK(); - if (pid == 0) { - SAFE_SETREGID(bin_gid, bin_gid); - SAFE_SETREUID(bin_uid, bin_uid); - SAFE_MKDIR(TESTDIR2, 0777); + SAFE_MKDIR(TESTDIR2, 0777); + SAFE_STAT(TESTDIR2, &statbuf); - SAFE_STAT(TESTDIR2, &buf2); - SAFE_STAT(TESTDIR1, &buf1); - - if (buf2.st_gid != buf1.st_gid) { - tst_res(TFAIL, - "New dir FAILED to inherit GID have %d expected %d", - buf2.st_gid, buf1.st_gid); - fail = 1; - } - - if (!(buf2.st_mode & S_ISGID)) { - tst_res(TFAIL, "New dir FAILED to inherit S_ISGID"); - fail = 1; - } - - if (!fail) - tst_res(TPASS, "New dir inherited GID and S_ISGID"); + if (statbuf.st_gid != free_gid) { + tst_res(TFAIL, + "New dir FAILED to inherit GID: has %d, expected %d", + statbuf.st_gid, free_gid); + fail = 1; + } - exit(0); + if (!(statbuf.st_mode & S_ISGID)) { + tst_res(TFAIL, "New dir FAILED to inherit S_ISGID"); + fail = 1; } - tst_reap_children(); + if (!fail) + tst_res(TPASS, "New dir inherited GID and S_ISGID"); + SAFE_RMDIR(TESTDIR2); } static void setup(void) { - struct passwd *pw; - struct stat buf; - pid_t pid; + struct passwd *pw = SAFE_GETPWNAM("nobody"); - pw = SAFE_GETPWNAM("nobody"); - nobody_uid = pw->pw_uid; - nobody_gid = pw->pw_gid; - pw = SAFE_GETPWNAM("bin"); - bin_uid = pw->pw_uid; - bin_gid = pw->pw_gid; + free_gid = tst_get_free_gid(pw->pw_gid); umask(0); + SAFE_MKDIR(TESTDIR1, 0777); + SAFE_CHMOD(TESTDIR1, 0777 | S_ISGID); + SAFE_CHOWN(TESTDIR1, getuid(), free_gid); - pid = SAFE_FORK(); - if (pid == 0) { - SAFE_SETREGID(nobody_gid, nobody_gid); - SAFE_SETREUID(nobody_uid, nobody_uid); - SAFE_MKDIR(TESTDIR1, 0777); - SAFE_STAT(TESTDIR1, &buf); - SAFE_CHMOD(TESTDIR1, buf.st_mode | S_ISGID); - exit(0); - } - - tst_reap_children(); + SAFE_SETREGID(pw->pw_gid, pw->pw_gid); + SAFE_SETREUID(pw->pw_uid, pw->pw_uid); } static struct tst_test test = { @@ -95,5 +67,4 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .test_all = verify_mkdir, - .forks_child = 1, }; From patchwork Fri Sep 3 15:48:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524402 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=zgaOvNJi; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=6vrUR0DD; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1Mg13NJ5z9sPf for ; Sat, 4 Sep 2021 01:49:33 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 84CDE3C98D3 for ; Fri, 3 Sep 2021 17:49:30 +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 RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A8DA83C2836 for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 8D37E200072 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0B5F52272C for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M09ad+WAj4Gas/6XUdSUQhXecAyoA5Dndhq7o1oEUi8=; b=zgaOvNJizSJ7P+fMmPGSClYh4fSOdu7Wio0rILEJd89M5atPU38s35W8Ozw9a2hjfUoFhX eP7azByULUNktn00COXsfkwDW0JM+AmAfoQ7mwXBttWxgxM4kMvR2o0CSDq5rJqbqbTg// iiaOCWnMLypkZ+fzmiQCsmy+o7dwk3M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M09ad+WAj4Gas/6XUdSUQhXecAyoA5Dndhq7o1oEUi8=; b=6vrUR0DDmNPAEsgHNfK+r2IKYOdgELZ++eWbpyl3JCB2AhseXp4nIg9+MXt6AIkI/imZiy 5/I6UKpCh0mdvmBQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EF7AB13B86 for ; Fri, 3 Sep 2021 15:48:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GGiMOeFDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:49 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:44 +0200 Message-Id: <20210903154848.18705-4-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 3/7] Add user/group ID lookup helper functions 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" Signed-off-by: Martin Doucha --- include/tst_safe_macros.h | 6 +++ include/tst_uid.h | 17 +++++++ lib/tst_uid.c | 100 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h index 6fd618597..0238a5de7 100644 --- a/include/tst_safe_macros.h +++ b/include/tst_safe_macros.h @@ -625,4 +625,10 @@ int safe_sysinfo(const char *file, const int lineno, struct sysinfo *info); #define SAFE_SYSINFO(info) \ safe_sysinfo(__FILE__, __LINE__, (info)) +struct passwd *safe_getpwent(const char *file, const int lineno); +#define SAFE_GETPWENT() safe_getpwent(__FILE__, __LINE__) + +struct group *safe_getgrent(const char *file, const int lineno); +#define SAFE_GETGRENT() safe_getgrent(__FILE__, __LINE__) + #endif /* SAFE_MACROS_H__ */ diff --git a/include/tst_uid.h b/include/tst_uid.h index 7135a9cad..a3bacf64a 100644 --- a/include/tst_uid.h +++ b/include/tst_uid.h @@ -15,4 +15,21 @@ gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip); #define tst_get_free_gid(skip) tst_get_free_gid_(__FILE__, __LINE__, (skip)) +/* + * Get a specific number of unique existing non-root user or group IDs. + * Multiple calls will return additional results, if any. Both functions call + * SAFE_GETPWENT() and SAFE_GETGRENT() respectively. + * Call endpwent()/endgrent() after the last use of these functions. + * Call setpwent()/setgrent() to read user/group IDs from the beginning again. + */ +int tst_get_uids_(const char *file, const int lineno, unsigned int count, + uid_t *buf); +#define tst_get_uids(count, buf) \ + tst_get_uids_(__FILE__, __LINE__, (count), (buf)) + +int tst_get_gids_(const char *file, const int lineno, unsigned int count, + gid_t *buf); +#define tst_get_gids(count, buf) \ + tst_get_gids_(__FILE__, __LINE__, (count), (buf)) + #endif /* TST_UID_H_ */ diff --git a/lib/tst_uid.c b/lib/tst_uid.c index dd719d312..915a5bc34 100644 --- a/lib/tst_uid.c +++ b/lib/tst_uid.c @@ -3,8 +3,10 @@ * Copyright (c) 2021 Linux Test Project */ +#define _XOPEN_SOURCE 500 #include #include +#include #include #define TST_NO_DEFAULT_MAIN @@ -36,3 +38,101 @@ gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip) tst_brk_(file, lineno, TBROK, "No free group ID found"); return (gid_t)-1; } + +struct passwd *safe_getpwent(const char *file, const int lineno) +{ + struct passwd *ret; + + errno = 0; + ret = getpwent(); + + if (!ret) { + if (errno) { + tst_brk_(file, lineno, TBROK | TERRNO, + "getpwent() failed"); + } else { + tst_brk_(file, lineno, TBROK, + "getpwent() failed: end of file"); + } + } + + return ret; +} + +struct group *safe_getgrent(const char *file, const int lineno) +{ + struct group *ret; + + errno = 0; + ret = getgrent(); + + if (!ret) { + if (errno) { + tst_brk_(file, lineno, TBROK | TERRNO, + "getgrent() failed"); + } else { + tst_brk_(file, lineno, TBROK, + "getgrent() failed: end of file"); + } + } + + return ret; +} + +int tst_get_uids_(const char *file, const int lineno, unsigned int count, + uid_t *buf) +{ + struct passwd *pw; + unsigned int i, j; + + for (i = 0; i < count;) { + pw = safe_getpwent(file, lineno); + + if (!pw) + return -1; + + if (!pw->pw_uid) + continue; + + for (j = 0; j < i; j++) { + if (buf[j] == pw->pw_uid) + break; + } + + if (j < i) + continue; + + buf[i++] = pw->pw_uid; + } + + return 0; +} + +int tst_get_gids_(const char *file, const int lineno, unsigned int count, + gid_t *buf) +{ + struct group *gr; + unsigned int i, j; + + for (i = 0; i < count;) { + gr = safe_getgrent(file, lineno); + + if (!gr) + return -1; + + if (!gr->gr_gid) + continue; + + for (j = 0; j < i; j++) { + if (buf[j] == gr->gr_gid) + break; + } + + if (j < i) + continue; + + buf[i++] = gr->gr_gid; + } + + return 0; +} From patchwork Fri Sep 3 15:48:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524399 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=wMLRWcPJ; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ZHqIV2uf; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1MfT2wy8z9sR4 for ; Sat, 4 Sep 2021 01:49:05 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 731C93C982B for ; Fri, 3 Sep 2021 17:49:02 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 89E563C2820 for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id A3DFF1001355 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 216F5203F2 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6hAYbz5VMYNKQQ95FMox+ozqZFw1DnXOz46ht3VGHd4=; b=wMLRWcPJf4wmnDFRRaTfVXjDrnkWCZNK4iB99WLdNEFRLR5rI0l8pEndBYVe27hTlVz9VO AXXhx4AHe1+YzLnDXsX+5fpCe1nzB7eSiSrPhEHWyQjjbm6K1jY6kmKj3Y+WLWXZ8KRL+P cMiGU3dF+IhOaAgTVUk6caZWDI4tpVo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6hAYbz5VMYNKQQ95FMox+ozqZFw1DnXOz46ht3VGHd4=; b=ZHqIV2uf/4frPTOUK/EMxEufgSgyQqJtl6jVghWeo7opfiqEv4x3j3XwfP7aLTTGVSgd76 /xOukWPaJgcQjbBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0E9F313B08 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8C62AuJDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:50 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:45 +0200 Message-Id: <20210903154848.18705-5-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 4/7] syscalls/kill05: Use any two unprivileged users 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" Usernames such as "bin" may not exist on some systems. Find and use any two unprivileged user IDs for the test instead of specific named users. Includes minor code style cleanup in wait_for_flag(). Signed-off-by: Martin Doucha --- testcases/kernel/syscalls/kill/kill05.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/testcases/kernel/syscalls/kill/kill05.c b/testcases/kernel/syscalls/kill/kill05.c index e694126f6..1dfdda58f 100644 --- a/testcases/kernel/syscalls/kill/kill05.c +++ b/testcases/kernel/syscalls/kill/kill05.c @@ -17,15 +17,18 @@ * This test must be run as root. */ +#define _XOPEN_SOURCE 500 #include +#include #include #include #include "tst_test.h" #include "libnewipc.h" #include "tst_safe_sysv_ipc.h" #include "tst_safe_macros.h" +#include "tst_uid.h" -static uid_t nobody_uid, bin_uid; +static uid_t test_users[2]; static int *flag; static int shm_id = -1; static key_t shm_key; @@ -35,8 +38,8 @@ static void wait_for_flag(int value) while (1) { if (*flag == value) break; - else - usleep(100); + + usleep(100); } } @@ -47,14 +50,14 @@ static void do_master_child(void) *flag = 0; pid1 = SAFE_FORK(); if (pid1 == 0) { - SAFE_SETREUID(nobody_uid, nobody_uid); + SAFE_SETREUID(test_users[0], test_users[0]); *flag = 1; wait_for_flag(2); exit(0); } - SAFE_SETREUID(bin_uid, bin_uid); + SAFE_SETREUID(test_users[1], test_users[1]); wait_for_flag(1); TEST(kill(pid1, SIGKILL)); @@ -85,17 +88,11 @@ static void verify_kill(void) static void setup(void) { - struct passwd *pw; - shm_key = GETIPCKEY(); shm_id = SAFE_SHMGET(shm_key, getpagesize(), 0666 | IPC_CREAT); flag = SAFE_SHMAT(shm_id, 0, 0); - - pw = SAFE_GETPWNAM("nobody"); - nobody_uid = pw->pw_uid; - - pw = SAFE_GETPWNAM("bin"); - bin_uid = pw->pw_uid; + tst_get_uids(2, test_users); + endpwent(); } static void cleanup(void) From patchwork Fri Sep 3 15:48:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=uBdt62IE; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8cHHiaQX; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1Mg96bMxz9sR4 for ; Sat, 4 Sep 2021 01:49:41 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6C1303C2822 for ; Fri, 3 Sep 2021 17:49:39 +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 RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A8D8C3C2822 for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 8EA61201097 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 323BE2272F for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X3U8eVNvbNhUoOpQ5eYXge9j4XMciUFQAQQ0CeIvMbU=; b=uBdt62IEUyF+niBxacEGJZEHOVmyyPy77ob5L8ZN7ZOBLfClPqT71YhURQNpvKsbczp7dQ KK7sxKnZPS90ncXvGXR5GuQfNLFS7P3I4m34tkr2QkE+fMSGZhf+gGev0unXTfDIgaLuIe e+smx5f+iEIpc/AGWQa6McnnBLzJUlM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X3U8eVNvbNhUoOpQ5eYXge9j4XMciUFQAQQ0CeIvMbU=; b=8cHHiaQXLOus93rZYMrreSgfn1I3Mg7rDtPeqIDr27WiFrknqhqkh5F4M0GFASqt2DvXrh vtQKnAdF5d7YQcAw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 224C113B86 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +I2BB+JDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:50 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:46 +0200 Message-Id: <20210903154848.18705-6-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 5/7] syscalls/mkdir04: Simplify test and use any existing users 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" mkdir04 does not need to fork() in setup(). Usernames such as "bin" may not exist on some systems. Find and use any two unprivileged users instead of specific named users. Signed-off-by: Martin Doucha --- testcases/kernel/syscalls/mkdir/mkdir04.c | 30 ++++++----------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/testcases/kernel/syscalls/mkdir/mkdir04.c b/testcases/kernel/syscalls/mkdir/mkdir04.c index 87512a4be..3880611d7 100644 --- a/testcases/kernel/syscalls/mkdir/mkdir04.c +++ b/testcases/kernel/syscalls/mkdir/mkdir04.c @@ -7,20 +7,16 @@ * user with restrictive permissions and that the errno is set to EACCESS. */ +#define _XOPEN_SOURCE 500 #include -#include #include #include -#include -#include -#include #include "tst_test.h" +#include "tst_uid.h" #define TESTDIR "testdir" #define TESTSUBDIR "testdir/testdir" -static uid_t nobody_uid, bin_uid; - static void verify_mkdir(void) { if (mkdir(TESTSUBDIR, 0777) != -1) { @@ -39,24 +35,15 @@ static void verify_mkdir(void) static void setup(void) { - struct passwd *pw; - pid_t pid; - - pw = SAFE_GETPWNAM("nobody"); - nobody_uid = pw->pw_uid; - pw = SAFE_GETPWNAM("bin"); - bin_uid = pw->pw_uid; + uid_t test_users[2]; - pid = SAFE_FORK(); - if (pid == 0) { - SAFE_SETREUID(nobody_uid, nobody_uid); - SAFE_MKDIR(TESTDIR, 0700); - exit(0); - } + tst_get_uids(2, test_users); + endpwent(); - tst_reap_children(); + SAFE_MKDIR(TESTDIR, 0700); + SAFE_CHOWN(TESTDIR, test_users[0], getgid()); - SAFE_SETREUID(bin_uid, bin_uid); + SAFE_SETREUID(test_users[1], test_users[1]); } static struct tst_test test = { @@ -64,5 +51,4 @@ static struct tst_test test = { .needs_tmpdir = 1, .needs_root = 1, .setup = setup, - .forks_child = 1, }; From patchwork Fri Sep 3 15:48:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=riI10zQH; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=GHdDdUmA; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1MfK00l1z9sPf for ; Sat, 4 Sep 2021 01:48:56 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 45DC93C2862 for ; Fri, 3 Sep 2021 17:48:53 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 659F13C27DB for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id AEB47601F58 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 498E3203F5 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d8cAGuS/A3CPHtm+PO4dVNlPFKnyt3HHSo40nD1gTh8=; b=riI10zQHmwXpUtuaOcK+gpT5aYE4Sm+z6dJ8RoqJCIroC6p6yOws0w9ngfHQ9TcEBEgZrn yNHSHMnjAG2SccPTbHCuCNKFB23JZmYGGnuYXh71trx0B010Kd0cb/91H+MPq9NvmoJHPF 3qbj3XSNXbsAe6MqhrxOKpq54SoNW24= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d8cAGuS/A3CPHtm+PO4dVNlPFKnyt3HHSo40nD1gTh8=; b=GHdDdUmAzJrc9qbjA1B51/1ZAzbWsd1Q3NvvEm40JR5K1TQnq/xJpIuWpvtJLNHzt0pZiT juVBeVKEXtZ/YcDQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 36C0513B08 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8IeADOJDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:50 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:47 +0200 Message-Id: <20210903154848.18705-7-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 6/7] syscalls/setregid02-04: Simplify GID handling 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" Signed-off-by: Martin Doucha --- .../kernel/syscalls/setregid/setregid02.c | 48 +++++++--------- .../kernel/syscalls/setregid/setregid03.c | 57 ++++++++----------- .../kernel/syscalls/setregid/setregid04.c | 42 +++++++------- 3 files changed, 61 insertions(+), 86 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index 310eb3a21..2174f81f9 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -19,12 +19,10 @@ #include "tst_test.h" #include "compat_tst_16.h" -static gid_t neg_one = -1; +static gid_t root_gid, nobody_gid, other_gid, neg_one = -1; static struct passwd *ltpuser; -static struct group ltpgroup, root, bin; - /* * The following structure contains all test data. Each structure in the array * is used for a separate test. The tests are executed in the for loop below. @@ -34,50 +32,41 @@ static struct tcase { gid_t *real_gid; gid_t *eff_gid; int exp_errno; - struct group *exp_real_usr; - struct group *exp_eff_usr; + gid_t *exp_real_usr; + gid_t *exp_eff_usr; char *test_msg; } tcases[] = { { - &neg_one, &root.gr_gid, EPERM, <pgroup, <pgroup, + &neg_one, &root_gid, EPERM, &nobody_gid, &nobody_gid, "After setregid(-1, root),"}, { - &neg_one, &bin.gr_gid, EPERM, <pgroup, <pgroup, + &neg_one, &other_gid, EPERM, &nobody_gid, &nobody_gid, "After setregid(-1, bin)"}, { - &root.gr_gid, &neg_one, EPERM, <pgroup, <pgroup, + &root_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid, "After setregid(root,-1),"}, { - &bin.gr_gid, &neg_one, EPERM, <pgroup, <pgroup, + &other_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid, "After setregid(bin, -1),"}, { - &root.gr_gid, &bin.gr_gid, EPERM, <pgroup, <pgroup, + &root_gid, &other_gid, EPERM, &nobody_gid, &nobody_gid, "After setregid(root, bin)"}, { - &bin.gr_gid, &root.gr_gid, EPERM, <pgroup, <pgroup, + &other_gid, &root_gid, EPERM, &nobody_gid, &nobody_gid, "After setregid(bin, root),"} }; -static struct group get_group_by_name(const char *name) +static gid_t get_group_by_name(const char *name) { struct group *ret = SAFE_GETGRNAM(name); GID16_CHECK(ret->gr_gid, setregid); - return *ret; -} - -static struct group get_group_by_gid(gid_t gid) -{ - struct group *ret = SAFE_GETGRGID(gid); - - GID16_CHECK(ret->gr_gid, setregid); - - return *ret; + return ret->gr_gid; } -void gid_verify(struct group *rg, struct group *eg, char *when) +void gid_verify(gid_t rg, gid_t eg, char *when) { - if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { + if ((getgid() != rg) || (getegid() != eg)) { tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", when, getgid(), getegid()); tst_res(TINFO, "Expected: real gid = %d; effective gid = %d", - rg->gr_gid, eg->gr_gid); + rg, eg); return; } @@ -107,7 +96,7 @@ static void run(unsigned int n) "setregid(%d, %d) did not fail (ret: %ld) as expected (ret: -1).", *tc->real_gid, *tc->eff_gid, TST_RET); } - gid_verify(tc->exp_real_usr, tc->exp_eff_usr, tc->test_msg); + gid_verify(*tc->exp_real_usr, *tc->exp_eff_usr, tc->test_msg); } static void setup(void) @@ -117,9 +106,10 @@ static void setup(void) SAFE_SETGID(ltpuser->pw_gid); SAFE_SETUID(ltpuser->pw_uid); - root = get_group_by_name("root"); - ltpgroup = get_group_by_gid(ltpuser->pw_gid); - bin = get_group_by_name("bin"); + nobody_gid = ltpuser->pw_gid; + GID16_CHECK(nobody_gid, setregid); + root_gid = get_group_by_name("root"); + other_gid = get_group_by_name("bin"); } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c index e25a7ec72..35aa92b8e 100644 --- a/testcases/kernel/syscalls/setregid/setregid03.c +++ b/testcases/kernel/syscalls/setregid/setregid03.c @@ -16,72 +16,61 @@ static int fail = -1; static int pass; -static gid_t neg_one = -1; +static gid_t primary_gid, secondary_gid, neg_one = -1; -struct group nobody_gr, daemon_gr, root_gr, bin_gr; struct passwd nobody; struct tcase { gid_t *real_gid; gid_t *eff_gid; int *exp_ret; - struct group *exp_real_usr; - struct group *exp_eff_usr; + gid_t *exp_real_usr; + gid_t *exp_eff_usr; char *test_msg; } tcases[] = { { - &daemon_gr.gr_gid, &bin_gr.gr_gid, &pass, &daemon_gr, &bin_gr, + &primary_gid, &secondary_gid, &pass, &primary_gid, &secondary_gid, "After setregid(daemon, bin),"}, { - &neg_one, &daemon_gr.gr_gid, &pass, &daemon_gr, &daemon_gr, + &neg_one, &primary_gid, &pass, &primary_gid, &primary_gid, "After setregid(-1, daemon)"}, { - &neg_one, &bin_gr.gr_gid, &pass, &daemon_gr, &bin_gr, + &neg_one, &secondary_gid, &pass, &primary_gid, &secondary_gid, "After setregid(-1, bin),"}, { - &bin_gr.gr_gid, &neg_one, &pass, &bin_gr, &bin_gr, + &secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid, "After setregid(bin, -1),"}, { - &neg_one, &neg_one, &pass, &bin_gr, &bin_gr, + &neg_one, &neg_one, &pass, &secondary_gid, &secondary_gid, "After setregid(-1, -1),"}, { - &neg_one, &bin_gr.gr_gid, &pass, &bin_gr, &bin_gr, + &neg_one, &secondary_gid, &pass, &secondary_gid, &secondary_gid, "After setregid(-1, bin),"}, { - &bin_gr.gr_gid, &neg_one, &pass, &bin_gr, &bin_gr, + &secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid, "After setregid(bin, -1),"}, { - &bin_gr.gr_gid, &bin_gr.gr_gid, &pass, &bin_gr, &bin_gr, + &secondary_gid, &secondary_gid, &pass, &secondary_gid, &secondary_gid, "After setregid(bin, bin),"}, { - &daemon_gr.gr_gid, &neg_one, &fail, &bin_gr, &bin_gr, + &primary_gid, &neg_one, &fail, &secondary_gid, &secondary_gid, "After setregid(daemon, -1)"}, { - &neg_one, &daemon_gr.gr_gid, &fail, &bin_gr, &bin_gr, + &neg_one, &primary_gid, &fail, &secondary_gid, &secondary_gid, "After setregid(-1, daemon)"}, { - &daemon_gr.gr_gid, &daemon_gr.gr_gid, &fail, &bin_gr, &bin_gr, + &primary_gid, &primary_gid, &fail, &secondary_gid, &secondary_gid, "After setregid(daemon, daemon)"},}; -static struct group get_group_fallback(const char *gr1, const char *gr2) -{ - struct group *junk; - - junk = SAFE_GETGRNAM_FALLBACK(gr1, gr2); - GID16_CHECK(junk->gr_gid, setregid); - return *junk; -} - -static struct group get_group(const char *group) +static gid_t get_group(const char *group) { struct group *junk; junk = SAFE_GETGRNAM(group); GID16_CHECK(junk->gr_gid, setregid); - return *junk; + return junk->gr_gid; } static void setup(void) { nobody = *SAFE_GETPWNAM("nobody"); - nobody_gr = get_group_fallback("nobody", "nogroup"); - daemon_gr = get_group("daemon"); - bin_gr = get_group("bin"); + primary_gid = get_group("daemon"); + secondary_gid = get_group("bin"); /* set the appropriate ownership values */ - SAFE_SETREGID(daemon_gr.gr_gid, bin_gr.gr_gid); + SAFE_SETREGID(primary_gid, secondary_gid); SAFE_SETEUID(nobody.pw_uid); } @@ -109,13 +98,13 @@ static void test_failure(struct tcase *tc) *tc->real_gid, *tc->eff_gid); } -static void gid_verify(struct group *rg, struct group *eg, char *when) +static void gid_verify(gid_t rg, gid_t eg, char *when) { - if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { + if ((getgid() != rg) || (getegid() != eg)) { tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", when, getgid(), getegid()); tst_res(TINFO, "Expected: real gid = %d; effective gid = %d", - rg->gr_gid, eg->gr_gid); + rg, eg); } else { tst_res(TPASS, "real or effective gid was modified as expected"); @@ -134,7 +123,7 @@ static void run(unsigned int i) else test_failure(tc); - gid_verify(tc->exp_real_usr, tc->exp_eff_usr, tc->test_msg); + gid_verify(*tc->exp_real_usr, *tc->exp_eff_usr, tc->test_msg); } void run_all(void) diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c index 9490ae173..6b9e3f524 100644 --- a/testcases/kernel/syscalls/setregid/setregid04.c +++ b/testcases/kernel/syscalls/setregid/setregid04.c @@ -12,9 +12,7 @@ #include "tst_test.h" #include "compat_tst_16.h" -static gid_t neg_one = -1; - -static struct group nobody_gr, daemon_gr, root_gr, bin_gr; +static gid_t first_gid, second_gid, root_gid, neg_one = -1; /* * The following structure contains all test data. Each structure in the array @@ -24,45 +22,44 @@ static struct group nobody_gr, daemon_gr, root_gr, bin_gr; struct test_data_t { gid_t *real_gid; gid_t *eff_gid; - struct group *exp_real_usr; - struct group *exp_eff_usr; + gid_t *exp_real_usr; + gid_t *exp_eff_usr; const char *test_msg; } test_data[] = { { - &root_gr.gr_gid, &root_gr.gr_gid, &root_gr, &root_gr, + &root_gid, &root_gid, &root_gid, &root_gid, "After setregid(root, root),"}, { - &nobody_gr.gr_gid, &neg_one, &nobody_gr, &root_gr, + &first_gid, &neg_one, &first_gid, &root_gid, "After setregid(nobody, -1)"}, { - &root_gr.gr_gid, &neg_one, &root_gr, &root_gr, + &root_gid, &neg_one, &root_gid, &root_gid, "After setregid(root,-1),"}, { - &neg_one, &neg_one, &root_gr, &root_gr, + &neg_one, &neg_one, &root_gid, &root_gid, "After setregid(-1, -1),"}, { - &neg_one, &root_gr.gr_gid, &root_gr, &root_gr, + &neg_one, &root_gid, &root_gid, &root_gid, "After setregid(-1, root)"}, { - &root_gr.gr_gid, &neg_one, &root_gr, &root_gr, + &root_gid, &neg_one, &root_gid, &root_gid, "After setregid(root, -1),"}, { - &daemon_gr.gr_gid, &nobody_gr.gr_gid, &daemon_gr, &nobody_gr, + &second_gid, &first_gid, &second_gid, &first_gid, "After setregid(daemon, nobody)"}, { - &neg_one, &neg_one, &daemon_gr, &nobody_gr, + &neg_one, &neg_one, &second_gid, &first_gid, "After setregid(-1, -1)"}, { - &neg_one, &nobody_gr.gr_gid, &daemon_gr, &nobody_gr, + &neg_one, &first_gid, &second_gid, &first_gid, "After setregid(-1, nobody)"} }; -static void gid_verify(struct group *rg, struct group *eg, const char *when) +static void gid_verify(gid_t rg, gid_t eg, const char *when) { - if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) { + if ((getgid() != rg) || (getegid() != eg)) { tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d", when, getgid(), getegid()); tst_res(TINFO, "Expected: real gid = %d; effective gid = %d", - rg->gr_gid, eg->gr_gid); + rg, eg); } else { tst_res(TPASS, "real or effective gid was modified as expected"); } } - static void run(unsigned int i) { /* Set the real or effective group id */ @@ -74,16 +71,15 @@ static void run(unsigned int i) return; } - gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr, + gid_verify(*test_data[i].exp_real_usr, *test_data[i].exp_eff_usr, test_data[i].test_msg); } static void setup(void) { - root_gr = *SAFE_GETGRNAM("root"); - nobody_gr = *SAFE_GETGRNAM_FALLBACK("nobody", "nogroup"); - daemon_gr = *SAFE_GETGRNAM("daemon"); - bin_gr = *SAFE_GETGRNAM("bin"); + root_gid = SAFE_GETGRNAM("root")->gr_gid; + first_gid = SAFE_GETGRNAM_FALLBACK("nobody", "nogroup")->gr_gid; + second_gid = SAFE_GETGRNAM("daemon")->gr_gid; } static struct tst_test test = { From patchwork Fri Sep 3 15:48:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1524406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=hKEEPvQi; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=meTcv0Ms; dkim-atps=neutral Authentication-Results: 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H1MgX4c0Zz9sSn for ; Sat, 4 Sep 2021 01:50:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 62BB23C98CE for ; Fri, 3 Sep 2021 17:49:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id D59313C27DB for ; Fri, 3 Sep 2021 17:48:51 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id C32EA14012D2 for ; Fri, 3 Sep 2021 17:48:50 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6ABB4203F7 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y10UsmgL1LM3rb0kWFRpY2OuocjCdb5o8H2IEuRNbSA=; b=hKEEPvQiuuYmaNXZTX+znz3jDsJoilEGepht8+1fs1MK4tSz7a4bz2lyfhnh1GQ5Vn28fY 08iRfLF+GNTDBjA2+tFB8jMvE3QOZPbOqrpWHeG8yk/MIPEtz7y5DwpmCtBesXcrE9N84j psqGqnI3np/tjufM+FoTSU4KaIs9Vtc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1630684130; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y10UsmgL1LM3rb0kWFRpY2OuocjCdb5o8H2IEuRNbSA=; b=meTcv0Mspf4mhfYkqTN4+cE86iGekVnO+p0yS5e/y0/NZeVFecInCSzey7qqg1VIGYnZtN WuTyiJV+Aw2Ve+Cw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4CB8F13B86 for ; Fri, 3 Sep 2021 15:48:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oNvvEeJDMmHpXgAAMHmgww (envelope-from ) for ; Fri, 03 Sep 2021 15:48:50 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Fri, 3 Sep 2021 17:48:48 +0200 Message-Id: <20210903154848.18705-8-mdoucha@suse.cz> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210903154848.18705-1-mdoucha@suse.cz> References: <20210903154848.18705-1-mdoucha@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 7/7] syscalls/setregid02-04: Eliminate named group lookups 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" Group names like "bin" or "daemon" may not exist on some systems. Find and use any unprivieged group IDs instead of specific named groups. Signed-off-by: Martin Doucha --- .../kernel/syscalls/setregid/setregid02.c | 39 +++++++++-------- .../kernel/syscalls/setregid/setregid03.c | 43 +++++++++---------- .../kernel/syscalls/setregid/setregid04.c | 22 +++++++--- 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c index 2174f81f9..d7d5eaa24 100644 --- a/testcases/kernel/syscalls/setregid/setregid02.c +++ b/testcases/kernel/syscalls/setregid/setregid02.c @@ -17,6 +17,7 @@ #include #include "tst_test.h" +#include "tst_uid.h" #include "compat_tst_16.h" static gid_t root_gid, nobody_gid, other_gid, neg_one = -1; @@ -40,26 +41,17 @@ static struct tcase { &neg_one, &root_gid, EPERM, &nobody_gid, &nobody_gid, "After setregid(-1, root),"}, { &neg_one, &other_gid, EPERM, &nobody_gid, &nobody_gid, - "After setregid(-1, bin)"}, { + "After setregid(-1, other)"}, { &root_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid, "After setregid(root,-1),"}, { &other_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid, - "After setregid(bin, -1),"}, { + "After setregid(other, -1),"}, { &root_gid, &other_gid, EPERM, &nobody_gid, &nobody_gid, - "After setregid(root, bin)"}, { + "After setregid(root, other)"}, { &other_gid, &root_gid, EPERM, &nobody_gid, &nobody_gid, - "After setregid(bin, root),"} + "After setregid(other, root),"} }; -static gid_t get_group_by_name(const char *name) -{ - struct group *ret = SAFE_GETGRNAM(name); - - GID16_CHECK(ret->gr_gid, setregid); - - return ret->gr_gid; -} - void gid_verify(gid_t rg, gid_t eg, char *when) { if ((getgid() != rg) || (getegid() != eg)) { @@ -101,15 +93,26 @@ static void run(unsigned int n) static void setup(void) { + struct group *grp; + ltpuser = SAFE_GETPWNAM("nobody"); + nobody_gid = ltpuser->pw_gid; + root_gid = getgid(); + setgrent(); - SAFE_SETGID(ltpuser->pw_gid); - SAFE_SETUID(ltpuser->pw_uid); + do { + grp = SAFE_GETGRENT(); + } while (grp->gr_gid == root_gid || grp->gr_gid == nobody_gid); - nobody_gid = ltpuser->pw_gid; + other_gid = grp->gr_gid; + endgrent(); + + GID16_CHECK(root_gid, setregid); GID16_CHECK(nobody_gid, setregid); - root_gid = get_group_by_name("root"); - other_gid = get_group_by_name("bin"); + GID16_CHECK(other_gid, setregid); + + SAFE_SETGID(ltpuser->pw_gid); + SAFE_SETUID(ltpuser->pw_uid); } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c index 35aa92b8e..66667c6b2 100644 --- a/testcases/kernel/syscalls/setregid/setregid03.c +++ b/testcases/kernel/syscalls/setregid/setregid03.c @@ -9,9 +9,12 @@ * Test setregid() when executed by a non-root user. */ +#include +#include #include #include "tst_test.h" +#include "tst_uid.h" #include "compat_tst_16.h" static int fail = -1; @@ -30,44 +33,40 @@ struct tcase { } tcases[] = { { &primary_gid, &secondary_gid, &pass, &primary_gid, &secondary_gid, - "After setregid(daemon, bin),"}, { + "After setregid(primary, secondary),"}, { &neg_one, &primary_gid, &pass, &primary_gid, &primary_gid, - "After setregid(-1, daemon)"}, { + "After setregid(-1, primary)"}, { &neg_one, &secondary_gid, &pass, &primary_gid, &secondary_gid, - "After setregid(-1, bin),"}, { + "After setregid(-1, secondary),"}, { &secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid, - "After setregid(bin, -1),"}, { + "After setregid(secondary, -1),"}, { &neg_one, &neg_one, &pass, &secondary_gid, &secondary_gid, "After setregid(-1, -1),"}, { &neg_one, &secondary_gid, &pass, &secondary_gid, &secondary_gid, - "After setregid(-1, bin),"}, { + "After setregid(-1, secondary),"}, { &secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid, - "After setregid(bin, -1),"}, { + "After setregid(secondary, -1),"}, { &secondary_gid, &secondary_gid, &pass, &secondary_gid, &secondary_gid, - "After setregid(bin, bin),"}, { + "After setregid(secondary, secondary),"}, { &primary_gid, &neg_one, &fail, &secondary_gid, &secondary_gid, - "After setregid(daemon, -1)"}, { + "After setregid(primary, -1)"}, { &neg_one, &primary_gid, &fail, &secondary_gid, &secondary_gid, - "After setregid(-1, daemon)"}, { + "After setregid(-1, primary)"}, { &primary_gid, &primary_gid, &fail, &secondary_gid, &secondary_gid, - "After setregid(daemon, daemon)"},}; - - -static gid_t get_group(const char *group) -{ - struct group *junk; - - junk = SAFE_GETGRNAM(group); - GID16_CHECK(junk->gr_gid, setregid); - return junk->gr_gid; -} + "After setregid(primary, primary)"},}; static void setup(void) { + gid_t test_groups[2]; + nobody = *SAFE_GETPWNAM("nobody"); - primary_gid = get_group("daemon"); - secondary_gid = get_group("bin"); + tst_get_gids(2, test_groups); + primary_gid = test_groups[0]; + secondary_gid = test_groups[1]; + endgrent(); + GID16_CHECK(primary_gid, setregid); + GID16_CHECK(secondary_gid, setregid); /* set the appropriate ownership values */ SAFE_SETREGID(primary_gid, secondary_gid); diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c index 6b9e3f524..911dc0d01 100644 --- a/testcases/kernel/syscalls/setregid/setregid04.c +++ b/testcases/kernel/syscalls/setregid/setregid04.c @@ -9,7 +9,11 @@ * Test setregid() when executed by root. */ +#include +#include + #include "tst_test.h" +#include "tst_uid.h" #include "compat_tst_16.h" static gid_t first_gid, second_gid, root_gid, neg_one = -1; @@ -30,7 +34,7 @@ struct test_data_t { &root_gid, &root_gid, &root_gid, &root_gid, "After setregid(root, root),"}, { &first_gid, &neg_one, &first_gid, &root_gid, - "After setregid(nobody, -1)"}, { + "After setregid(first, -1)"}, { &root_gid, &neg_one, &root_gid, &root_gid, "After setregid(root,-1),"}, { &neg_one, &neg_one, &root_gid, &root_gid, @@ -40,11 +44,11 @@ struct test_data_t { &root_gid, &neg_one, &root_gid, &root_gid, "After setregid(root, -1),"}, { &second_gid, &first_gid, &second_gid, &first_gid, - "After setregid(daemon, nobody)"}, { + "After setregid(second, first)"}, { &neg_one, &neg_one, &second_gid, &first_gid, "After setregid(-1, -1)"}, { &neg_one, &first_gid, &second_gid, &first_gid, - "After setregid(-1, nobody)"} + "After setregid(-1, first)"} }; static void gid_verify(gid_t rg, gid_t eg, const char *when) @@ -77,9 +81,15 @@ static void run(unsigned int i) static void setup(void) { - root_gid = SAFE_GETGRNAM("root")->gr_gid; - first_gid = SAFE_GETGRNAM_FALLBACK("nobody", "nogroup")->gr_gid; - second_gid = SAFE_GETGRNAM("daemon")->gr_gid; + gid_t groups[3]; + + tst_get_gids(3, groups); + root_gid = getgid(); + + /* At most one of the groups may be equal to root_gid */ + first_gid = groups[0] != root_gid ? groups[0] : groups[2]; + second_gid = groups[1] != root_gid ? groups[1] : groups[2]; + endgrent(); } static struct tst_test test = {