From patchwork Tue Aug 23 09:51:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1669249 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=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=uUWYOdYQ; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=O0OoGrDw; dkim-atps=neutral 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 4MBkyR3JsTz1ygF for ; Tue, 23 Aug 2022 19:51:27 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CE1D03CA2DC for ; Tue, 23 Aug 2022 11:51:23 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (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 D55663C0726 for ; Tue, 23 Aug 2022 11:51:21 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id 248C31A00CC4 for ; Tue, 23 Aug 2022 11:51:20 +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 118465BCC2 for ; Tue, 23 Aug 2022 09:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1661248280; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=54osBkdqyKD8t/biNKqcvf2TK7vUFgpmYRjEt4oCr3Q=; b=uUWYOdYQlqO96N+nUnNHULhYvrwW0lWHusejxKk9UL3OJq8thbW9OEJJnFlR1TMLj1fOnx yCe8O3CcP2MZKum3oHaH6087XzdtQWOfBAM82sL52PeYJ0hSAPIDl8ybY045uT4mB34POd y6gV26eS9hR3CIm2oL0MXdaI51541jc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1661248280; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=54osBkdqyKD8t/biNKqcvf2TK7vUFgpmYRjEt4oCr3Q=; b=O0OoGrDwM6P8QZvTyLl4cfZBnyYDoqf3DHPDoIg5p24EPiKRBFSZ9wPVhXpveUg0jPw5H8 bTJqCri6EJDvemCQ== 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 8727613AB7 for ; Tue, 23 Aug 2022 09:51:19 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ECNgEhejBGPxfQAAMHmgww (envelope-from ) for ; Tue, 23 Aug 2022 09:51:19 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 23 Aug 2022 15:21:16 +0530 Message-Id: <20220823095116.369-1-akumar@suse.de> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH] setegid02.c: Rewrite using new LTP 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" Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/setegid/setegid02.c | 90 +++++-------------- 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/testcases/kernel/syscalls/setegid/setegid02.c b/testcases/kernel/syscalls/setegid/setegid02.c index 7c60a9cf5..66a8a07fb 100644 --- a/testcases/kernel/syscalls/setegid/setegid02.c +++ b/testcases/kernel/syscalls/setegid/setegid02.c @@ -1,87 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2014 Fujitsu Ltd. * Author: Zeng Linggang - * - * 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. - * - * 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. + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * DESCRIPTION - * The calling process is not privileged and euid is not appropriate, - * EPERM should return. + +/*\ + * [Description] + * + * Verify that setegid() fails with EPERM when the calling process is not + * privileged and egid does not match the current real group ID, + * current effective group ID, or current saved set-group-ID. */ -#include #include -#include "test.h" -#include "safe_macros.h" - -char *TCID = "setegid02"; -int TST_TOTAL = 1; -static void setup(void); -static void setegid_verify(void); -static void cleanup(void); +#include "tst_test.h" static struct passwd *ltpuser; -int main(int argc, char *argv[]) -{ - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - setegid_verify(); - } - - cleanup(); - tst_exit(); -} - static void setup(void) { - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); - - SAFE_SETEUID(cleanup, ltpuser->pw_uid); + ltpuser = SAFE_GETPWNAM("nobody"); + SAFE_SETEUID(ltpuser->pw_uid); } static void setegid_verify(void) { - TEST(setegid(ltpuser->pw_gid)); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "setegid(%d) succeeded unexpectedly", - ltpuser->pw_gid); - return; - } - - if (TEST_ERRNO == EPERM) { - tst_resm(TPASS | TTERRNO, "setegid failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "setegid failed unexpectedly; expected: %d - %s", - EPERM, strerror(EPERM)); - } + TST_EXP_FAIL(setegid(ltpuser->pw_gid), + EPERM, + "setegid(%d)", + ltpuser->pw_gid); } -static void cleanup(void) -{ -} +static struct tst_test test = { + .setup = setup, + .test_all = setegid_verify, + .needs_root = 1 +};