From patchwork Thu Aug 11 06:11:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1665414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=fE4nxgcr; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2sai01Gy; 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4M3Gf21jNjz9sGG for ; Thu, 11 Aug 2022 16:11:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9F2A23C954B for ; Thu, 11 Aug 2022 08:11:16 +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 ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C10EF3C1BEA for ; Thu, 11 Aug 2022 08:11:14 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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 9D2161400B74 for ; Thu, 11 Aug 2022 08:11:13 +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 DADD437E87 for ; Thu, 11 Aug 2022 06:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1660198270; 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=IeQLamlC0H/YwhPvKmJOEgaf62dGX+zZnZCCpJJkLms=; b=fE4nxgcrYXg/vwkKDyJVEy5tK3OBsceTN01RMjOriODglJZ9GlBIeckqZAiLPhCxrvHKqQ 9GbvVFr1eU8EUWZx5xolcrBTHMVi3dAL6sFUv1KRzAkIMKsygBCGZsbjxKG3+uxxl6bV/V n9Oho67j8qEQR+RHJojwQrDvDe9KV1c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1660198270; 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=IeQLamlC0H/YwhPvKmJOEgaf62dGX+zZnZCCpJJkLms=; b=2sai01GymeazBivt5EvmtlTe4fOpPl4TW4MhFHZHlTLOCAXK8RYb5n7nnIY4zcSDYNtY4P MOej5hIlX2nptFAw== 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 5CF1613A9B for ; Thu, 11 Aug 2022 06:11:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ilFoCH6d9GKkGAAAMHmgww (envelope-from ) for ; Thu, 11 Aug 2022 06:11:10 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 11 Aug 2022 11:41:07 +0530 Message-Id: <20220811061107.30966-1-akumar@suse.de> X-Mailer: git-send-email 2.36.1 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, T_SCC_BODY_TEXT_LINE 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 v2] setuid03.c: using TST_EXP_FAIL() and SAFE_SETUID() macros 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" use TST_EXP_FAIL() with expected errno code, use SAFE_SETUID() in setup and turn comment into docparse Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/setuid/setuid03.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/testcases/kernel/syscalls/setuid/setuid03.c b/testcases/kernel/syscalls/setuid/setuid03.c index f2e007f8d..06934f142 100644 --- a/testcases/kernel/syscalls/setuid/setuid03.c +++ b/testcases/kernel/syscalls/setuid/setuid03.c @@ -1,9 +1,12 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) Linux Test Project, 2009-2022 */ -/* DESCRIPTION +/*\ + * [Description] + * * This test will switch to nobody user for correct error code collection. * Verify setuid returns errno EPERM when it switches to root_user. */ @@ -19,16 +22,7 @@ static void verify_setuid(void) { - TEST(SETUID(ROOT_USER)); - if (TST_RET != -1) { - tst_res(TFAIL | TTERRNO, "setuid() succeeded unexpectedly"); - return; - } - - if (TST_ERR == EPERM) - tst_res(TPASS, "setuid() returned errno EPERM"); - else - tst_res(TFAIL | TTERRNO, "setuid() returned unexpected errno"); + TST_EXP_FAIL(SETUID(ROOT_USER), EPERM); } static void setup(void) @@ -39,10 +33,7 @@ static void setup(void) pw = SAFE_GETPWNAM("nobody"); uid = pw->pw_uid; - if (SETUID(uid) == -1) { - tst_brk(TBROK, - "setuid() failed to set the effective uid to %d", uid); - } + SAFE_SETUID(uid); umask(0); }