From patchwork Wed Sep 14 08:12:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1677674 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=D4dz4CfP; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSBNB55tzz1ynm for ; Wed, 14 Sep 2022 17:11:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 21E373CABD6 for ; Wed, 14 Sep 2022 09:11:49 +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 46FAC3CAAEF for ; Wed, 14 Sep 2022 09:11:46 +0200 (CEST) Received: from mail1.bemta37.messagelabs.com (mail1.bemta37.messagelabs.com [85.158.142.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id DBD8C1401246 for ; Wed, 14 Sep 2022 09:11:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1663139504; i=@fujitsu.com; bh=gJx8zQDvNQyneyaNvvFjBISaUiyHeUXtWphaeGbhRUA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=D4dz4CfPA1SjsxyI3pjlfGzTtnHMN3OUW+OS2za7YoyBRVgYXzDk7Ka+kW8nfickY x4Yc+Wiug7OfhivQNKpq4ILT3Nlqafy8PLbJKGJbxkUpURe85s/j1KLXbkr6TL1Lu3 dOqVkZ7617FGaHoDmN697qSWWPnm1f6MpgCsIWag5HCLAMEoQ5fhzWkQ+UIKj7DduH 66dP364Zsi7UU3G37x0isfqbfoLayXSISp0C4X55bwV101JA/Q8gNEih9AG2YNeknv 4gsYIqmElmfT9cCfDJIDgfGrWzSrifHbtegA/hYowP5mJO3JphDcNyPR+SM2/pdOei Nse66TOFAk4fA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDIsWRWlGSWpSXmKPExsViZ8OxWXdDnWK ywcpZvBavD39itJj+4iibxYrvOxgdmD02repk89j3ex2rx5kFR9gDmKNYM/OS8isSWDP6f59h LLgjXNF76jd7A+MWgS5GLg4hgY2MEjs+HmSEcBYzSbx4848ZwtnDKHFh2g2gDCcHm4CmxLPOB cwgtoiAhERHw1t2EJtZIFDizLEOVhBbWMBJouPhCbA4i4CqxN9975lAbF4BD4n1f++A9UoIKE hMefieGSIuKHFy5hMWiDkSEgdfvICqUZS41PGNEcKukGicfogJwlaTuHpuE/MERv5ZSNpnIWl fwMi0itE2qSgzPaMkNzEzR9fQwEDX0NAUSBvrGpoY6SVW6SbqpZbq5uUXlWToGuollhfrpRYX 6xVX5ibnpOjlpZZsYgQGcUpxet8Oxo37fukdYpTkYFIS5f3wVSFZiC8pP6UyI7E4I76oNCe1+ BCjDAeHkgTvjlrFZCHBotT01Iq0zBxgRMGkJTh4lER4J+UDpXmLCxJzizPTIVKnGI05rl65sp eZY9O+rgPMQix5+XmpUuK8j6uBSgVASjNK8+AGwSL9EqOslDAvIwMDgxBPQWpRbmYJqvwrRnE ORiVh3ikg9/Bk5pXA7XsFdAoT0ClG1vIgp5QkIqSkGpimPDO84tLfcj4ljdF5v42n7sfLcgeq r//4t4fNov9jLh9HxpYn0804mj1STq5mvdTj7Vls/OZiaADjg9eXDCZGamuzOMz/m8oU5MDQ+ fa5YoZWT23+fAfNaTN2dwUsY3go5B2f/5rJYxann9Gzv8GNAr9YXjSnb7+2P71bpjz70oTJ7W am960nH01iS7a8ejeIjfUok0yI4I+7YaeXPZmv+1vvCf+nVTJaR7tO3f9y3Gma8afTH1/Xf1t lwb+cY8HBkhzP7/Mv/gjkbgoznm5Q3HUls7hcwfzpa33D68ubV9g+4jZd/7+A2ceMW5lrc+Kj J98+5i3Z/Xb2FZtQ1dNHztp0/o01FVsnsFTuv7YSS3FGoqEWc1FxIgCADOO7bwMAAA== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-4.tower-732.messagelabs.com!1663139503!375384!1 X-Originating-IP: [62.60.8.179] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15263 invoked from network); 14 Sep 2022 07:11:44 -0000 Received: from unknown (HELO n03ukasimr04.n03.fujitsu.local) (62.60.8.179) by server-4.tower-732.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Sep 2022 07:11:44 -0000 Received: from n03ukasimr04.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTP id 9BEFF142; Wed, 14 Sep 2022 08:11:43 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTPS id 8E9CB7B; Wed, 14 Sep 2022 08:11:43 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 14 Sep 2022 08:11:41 +0100 From: Yang Xu To: Date: Wed, 14 Sep 2022 16:12:20 +0800 Message-ID: <1663143142-2283-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) 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 v4 1/3] syscalls/creat09: Add umask test condition 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: , Cc: brauner@kernel.org Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" A kernel patch set that fix setgid strip logic under umask(S_IXGRP) found by this case has been merged into 6.0-rc1 kernel[1]. I will add acl and umask test[2] in xfstests because there is more suitable to do this. Here I just only add umask test condition simply. [1]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=1639a49c [2]https://patchwork.kernel.org/project/fstests/list/?series=662984 Reviewed-by: Petr Vorel Signed-off-by: Yang Xu --- testcases/kernel/syscalls/creat/creat09.c | 30 +++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/creat/creat09.c b/testcases/kernel/syscalls/creat/creat09.c index bed7bddb0..d583cceca 100644 --- a/testcases/kernel/syscalls/creat/creat09.c +++ b/testcases/kernel/syscalls/creat/creat09.c @@ -28,6 +28,16 @@ * Date: Fri Jan 22 16:48:18 2021 -0800 * * xfs: fix up non-directory creation in SGID directories + * + * When use acl or umask, it still has bug. + * + * Fixed in: + * + * commit 1639a49ccdce58ea248841ed9b23babcce6dbb0b + * Author: Yang Xu + * Date: Thu July 14 14:11:27 2022 +0800 + * + * fs: move S_ISGID stripping into the vfs_*() helpers */ #include @@ -47,6 +57,14 @@ static gid_t free_gid; static int fd = -1; +static struct tcase { + const char *msg; + int mask; +} tcases[] = { + {"under umask(0) situation", 0}, + {"under umask(S_IXGRP) situation", S_IXGRP} +}; + static void setup(void) { struct stat buf; @@ -94,8 +112,14 @@ static void file_test(const char *name) tst_res(TPASS, "%s: Setgid bit not set", name); } -static void run(void) +static void run(unsigned int n) { + struct tcase *tc = &tcases[n]; + + umask(tc->mask); + tst_res(TINFO, "Testing setgid behaviour when creating file %s", + tc->msg); + fd = SAFE_CREAT(CREAT_FILE, MODE_SGID); SAFE_CLOSE(fd); file_test(CREAT_FILE); @@ -115,13 +139,14 @@ static void cleanup(void) } static struct tst_test test = { - .test_all = run, + .test = run, .setup = setup, .cleanup = cleanup, .needs_root = 1, .all_filesystems = 1, .mount_device = 1, .mntpoint = MNTPOINT, + .tcnt = ARRAY_SIZE(tcases), .skip_filesystems = (const char*[]) { "exfat", "ntfs", @@ -132,6 +157,7 @@ static struct tst_test test = { {"linux-git", "0fa3ecd87848"}, {"CVE", "2018-13405"}, {"linux-git", "01ea173e103e"}, + {"linux-git", "1639a49ccdce"}, {} }, }; From patchwork Wed Sep 14 08:12:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1677675 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=Z8j2eW+M; 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) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSBNQ1hcKz1ynm for ; Wed, 14 Sep 2022 17:12:06 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0CE513CABBF for ; Wed, 14 Sep 2022 09:12:00 +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 ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 515A83CABFA for ; Wed, 14 Sep 2022 09:11:50 +0200 (CEST) Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id B005E10011DD for ; Wed, 14 Sep 2022 09:11:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1663139508; i=@fujitsu.com; bh=7p51pjpi7/W9Swb03fiqfQak5ptTVW7NVlxgv1RWusk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Z8j2eW+M52UqnjN0LdB3ARR/0s/jc8kyMHpgTy68LOzqBb/Z+bzpOrYPy4SFCI9MB /RtGgVFafP7FNtFODWzs2RO1VA9e+eO8RBqPce/O0y+1GEpt+kkr1N6DOoGSUWJihE bA98ogq0Nc+YN1sFAWfaheJCbx/CDDD0w6ab3JZ2E9E/nUKevnEh5EsilEgBRo4Tl2 D2q3uAlOtoXVtgBrufXVIZ4sXpHv99Nf+qXjts3Itn0YA4svhgPpLbE2LdB0WMGGO2 KNFbRm1XCQ6yVtw+whjpDAFOTvCkGkjRYsWn6cR0BnbqOUI2Kc8Zw4tXmdwfE1Tf0F kWQ0HxLGTVkKQ== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDIsWRWlGSWpSXmKPExsViZ8ORpLulTjH ZYMFSRovXhz8xWkx/cZTNYsX3HYwOzB6bVnWyeez7vY7V48yCI+wBzFGsmXlJ+RUJrBmvvz1n KdjJV3F4s1EDYy9PFyMXh5DARkaJzRPusUE4S5gk5vTsY+5i5ARy9jBKtP73ALHZBDQlnnUuA IuLCEhIdDS8ZQexmQUCJc4c62AFsYUFHCTWv3vJBGKzCKhKXHpyHizOK+Ah8fnLNrB6CQEFiS kP34PN4RTwlDj0dRrULg+JV6ffsUHUC0qcnPmEBWK+hMTBFy+YIXoVJS51fGOEsCskGqcfYoK w1SSuntvEPIFRcBaS9llI2hcwMq1itEwqykzPKMlNzMzRNTQw0DU0NNU10bU01kus0k3USy3V LU8tLtE11EssL9ZLLS7WK67MTc5J0ctLLdnECAz0lGKW2B2MW/t+6h1ilORgUhLl/fBVIVmIL yk/pTIjsTgjvqg0J7X4EKMMB4eSBO+OWsVkIcGi1PTUirTMHGDUwaQlOHiURHgn5QOleYsLEn OLM9MhUqcYFaXEeR9XAyUEQBIZpXlwbbBIv8QoKyXMy8jAwCDEU5BalJtZgir/ilGcg1FJmHc KyHaezLwSuOmvgBYzAS02spYHWVySiJCSamBa/TYtr2Frqt36JQcT1S5bVbJPfvF+Q1/8B1H5 hjMfZjp3GWgaaCQb2D3uWrnz1ud1uavvxv4/zPsxVch/2ZynW6zaSqZf+tB9v0FmzcWdButmv f1XuSzpcuoGoQ2vfOb/SDpje9rohnU9S5bIJrt9v5MOzPrVK8j98/vUrHV3g3dWRZ/njr3zSX bdpoSw6rmFd++K2M0Mi3yp1PPvxpFJVyS1vtyWDy93erfrguPZh2dWeCj8ZPgwvyP4MsuGqOn P9bbuP1oRsYzhyj6x5aKGVTPndEf+NHXZMz8qxumBt6xv5GszjqSW41WGhx562FatSdS+1qZ4 dGJTYHvTfMfPD/yqQtrf7PdOeFul/7XooxJLcUaioRZzUXEiANKZ+VFvAwAA X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-4.tower-591.messagelabs.com!1663139507!235005!1 X-Originating-IP: [62.60.8.98] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 22062 invoked from network); 14 Sep 2022 07:11:48 -0000 Received: from unknown (HELO n03ukasimr03.n03.fujitsu.local) (62.60.8.98) by server-4.tower-591.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Sep 2022 07:11:48 -0000 Received: from n03ukasimr03.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTP id 986EC1AD; Wed, 14 Sep 2022 08:11:47 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTPS id 8CF4F1AC; Wed, 14 Sep 2022 08:11:47 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 14 Sep 2022 08:11:45 +0100 From: Yang Xu To: Date: Wed, 14 Sep 2022 16:12:21 +0800 Message-ID: <1663143142-2283-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1663143142-2283-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1663143142-2283-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) 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, T_SCC_BODY_TEXT_LINE 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 v4 2/3] tst_safe_file_at: Add SAFE_FSTATAT macro 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: , Cc: brauner@kernel.org Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu Reviewed-by: Cyril Hrubis --- include/tst_safe_file_at.h | 7 +++++++ lib/tst_safe_file_at.c | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h index e253198e6..082a5acd9 100644 --- a/include/tst_safe_file_at.h +++ b/include/tst_safe_file_at.h @@ -29,6 +29,9 @@ safe_fchownat(__FILE__, __LINE__, \ (dirfd), (path), (owner), (group), (flags)) +#define SAFE_FSTATAT(dirfd, path, statbuf, flags) \ + safe_fstatat(__FILE__, __LINE__, (dirfd), (path), (statbuf), (flags)) + const char *tst_decode_fd(const int fd) __attribute__((warn_unused_result)); @@ -67,4 +70,8 @@ int safe_fchownat(const char *const file, const int lineno, gid_t group, int flags) __attribute__ ((nonnull)); +int safe_fstatat(const char *const file, const int lineno, + const int dirfd, const char *const path, struct stat *statbuf, + int flags) + __attribute__ ((nonnull)); #endif diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c index 6370a68e5..f530dc349 100644 --- a/lib/tst_safe_file_at.c +++ b/lib/tst_safe_file_at.c @@ -215,3 +215,23 @@ int safe_fchownat(const char *const file, const int lineno, return rval; } + +int safe_fstatat(const char *const file, const int lineno, + const int dirfd, const char *const path, struct stat *statbuf, int flags) +{ + int rval; + + rval = fstatat(dirfd, path, statbuf, flags); + + if (rval == -1) { + tst_brk_(file, lineno, TBROK | TERRNO, + "fstatat(%d<%s>, '%s', %p, %d) failed", dirfd, + tst_decode_fd(dirfd), path, statbuf, flags); + } else if (rval) { + tst_brk_(file, lineno, TBROK | TERRNO, + "Invalid fstatat(%d<%s>, '%s', %p, %d) return value %d", + dirfd, tst_decode_fd(dirfd), path, statbuf, flags, rval); + } + + return rval; +} From patchwork Wed Sep 14 08:12:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu \\(Fujitsu\\)" X-Patchwork-Id: 1677676 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=bYmC/Fh3; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MSBNb5vgSz1ynm for ; Wed, 14 Sep 2022 17:12:15 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0A4313CABB7 for ; Wed, 14 Sep 2022 09:12:10 +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 02D683CAC07 for ; Wed, 14 Sep 2022 09:11:53 +0200 (CEST) Received: from mail1.bemta37.messagelabs.com (mail1.bemta37.messagelabs.com [85.158.142.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 1A1831A014AA for ; Wed, 14 Sep 2022 09:11:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1663139512; i=@fujitsu.com; bh=SrJERncJAMYv8zzrUURP3/0hPe36ZpeW44W13OPKI0s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bYmC/Fh3JtU2AmBSXYzsxdt3zhUdEwmKvilIzAnGoHMm5n45i2dyJMvoXJcyxO4WO ARtKiBGzmCtX2N2Y6fa9CxUpkpc7MrvjKPJeexVSowWdlcaTwcYoHCfPzFuUY9K4cm hP5ZHvV07k3aYeNJUvj2FEzqLES9/OYswixms2MFf7816EOzUaYuqvFq1KxoJdvrcT AKz9mwPjz8oCMvjIGNpFdTtB2bmB3ZLr9Bucc1H0+QGBE5N2ZBpDfwwET66oLdpDdw mMX4Gk6ue+GjRMx1zMDqmwszCoFC89K3h0+iah1VfPB6IO+Q20aRnVy/lQl4vndg0J CKV1iI9ISLIJg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrAIsWRWlGSWpSXmKPExsViZ8OxWXd7nWK ywd7TmhavD39itJj+4iibxYrvOxgdmD02repk89j3ex2rx5kFR9gDmKNYM/OS8isSWDPutTWx FqzQrTi1t42lgXG/WhcjF4eQwEZGiecrnzF2MXICOUuYJD4tCYFI7GGUuLhzCxNIgk1AU+JZ5 wJmEFtEQEKio+EtO4jNLBAoceZYByuILSyQLnHu/hewehYBVYmZnzrBangFPCTuLWlmA7ElBB Qkpjx8DzaHU8BT4tDXacwQiz0kXp1+xwZRLyhxcuYTFoj5EhIHX7xghuhVlLjU8Y0Rwq6QaJx +iAnCVpO4em4T8wRGwVlI2mchaV/AyLSK0SapKDM9oyQ3MTNH19DAQNfQ0FTX0kLXyNhYL7FK N1EvtVQ3L7+oJEPXUC+xvFgvtbhYr7gyNzknRS8vtWQTIzDgU4qTXu5gPL/vl94hRkkOJiVR3 g9fFZKF+JLyUyozEosz4otKc1KLDzHKcHAoSfDuqFVMFhIsSk1PrUjLzAFGH0xagoNHSYR3Uj 5Qmre4IDG3ODMdInWKUVFKnPdxNVBCACSRUZoH1waL+EuMslLCvIwMDAxCPAWpRbmZJajyrxj FORiVhHmngGznycwrgZv+CmgxE9BiI2t5kMUliQgpqQamRcFLGBom/ZFWZuMR9luy8m1Xa3Bm yBmVez+EPz/9OVtY4cYe7SNmwodeBF7I5faWYjTiae2Trru+Vcz2yoZlqQEPr5yZNW9phqPDq hC+PEW3om/XjpouPFM240fZ13VR5ZOEmK09HzcE/TZ8dZfp2KdSmdX7+mTdNHbdX9DLHpJ5Ls rSuXulz+p/3t/W7dPgUznvcs56147SJfGv3/A1OZbyKCq5hV/ftW7GgvdbhM4Eawf/5r/pu2L i3Yi3u0t8tCaIz5NafOvkr6nvczY6SRe0LXdNkLNX++p1l4VL9/vfvQeuWM3U+/wiveLAKr8p +QYnRC8wfV/dXZBbv+StnvVHvhr9R9H3ivMfPxBoVWIpzkg01GIuKk4EAILsX09zAwAA X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-6.tower-732.messagelabs.com!1663139511!373926!1 X-Originating-IP: [62.60.8.179] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17578 invoked from network); 14 Sep 2022 07:11:51 -0000 Received: from unknown (HELO n03ukasimr04.n03.fujitsu.local) (62.60.8.179) by server-6.tower-732.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Sep 2022 07:11:51 -0000 Received: from n03ukasimr04.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTP id 13BFB156; Wed, 14 Sep 2022 08:11:51 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTPS id 0642E142; Wed, 14 Sep 2022 08:11:51 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 14 Sep 2022 08:11:48 +0100 From: Yang Xu To: Date: Wed, 14 Sep 2022 16:12:22 +0800 Message-ID: <1663143142-2283-3-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1663143142-2283-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1663143142-2283-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) 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 v4 3/3] syscalls/openat: Add new regression test when using open(O_TMPFILE) under umask 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: , Cc: brauner@kernel.org Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- runtest/syscalls | 2 +- testcases/kernel/syscalls/openat/.gitignore | 1 + testcases/kernel/syscalls/openat/openat04.c | 181 ++++++++++++++++++++ 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/openat/openat04.c diff --git a/runtest/syscalls b/runtest/syscalls index 9d58e0aa1..cd38a4ddf 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -919,10 +919,10 @@ open12 open12 open13 open13 open14 open14 -#openat test cases openat01 openat01 openat02 openat02 openat03 openat03 +openat04 openat04 openat201 openat201 openat202 openat202 diff --git a/testcases/kernel/syscalls/openat/.gitignore b/testcases/kernel/syscalls/openat/.gitignore index 2928dae22..2d15872ab 100644 --- a/testcases/kernel/syscalls/openat/.gitignore +++ b/testcases/kernel/syscalls/openat/.gitignore @@ -2,3 +2,4 @@ /openat02 /openat02_child /openat03 +/openat04 diff --git a/testcases/kernel/syscalls/openat/openat04.c b/testcases/kernel/syscalls/openat/openat04.c new file mode 100644 index 000000000..1fbe51c60 --- /dev/null +++ b/testcases/kernel/syscalls/openat/openat04.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [Description] + * + * Check setgid strip logic whether works correctly when creating tmpfile under + * filesystem without POSIX ACL supported(by using noacl mount option). Test it + * with umask S_IXGRP and also check file mode whether has filtered S_IXGRP. + * + * Fixed in: + * + * commit ac6800e279a22b28f4fc21439843025a0d5bf03e + * Author: Yang Xu + * Date: Thu July 14 14:11:26 2022 +0800 + * + * fs: Add missing umask strip in vfs_tmpfile + * + * The most code is pasted form creat09.c. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "tst_uid.h" +#include "tst_safe_file_at.h" + +#define MODE_RWX 0777 +#define MODE_SGID (S_ISGID|0777) +#define MNTPOINT "mntpoint" +#define WORKDIR MNTPOINT "/testdir" +#define OPEN_FILE "open.tmp" + +static gid_t free_gid; +static int tmpfile_fd = -1, dir_fd = -1, mount_flag; +static struct passwd *ltpuser; + +static void do_mount(const char *source, const char *target, + const char *filesystemtype, unsigned long mountflags, + const void *data) +{ + TEST(mount(source, target, filesystemtype, mountflags, data)); + + if (TST_RET == -1 && TST_ERR == EINVAL) + tst_brk(TCONF, "Kernel does not support noacl feature"); + + if (TST_RET == -1) { + tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed", + source, target, filesystemtype, mountflags, data); + } + + if (TST_RET) + tst_brk(TBROK, "Invalid mount return value %ld", TST_RET); + + mount_flag = 1; +} + +static void open_tmpfile_supported(int dirfd) +{ + TEST(openat(dirfd, ".", O_TMPFILE | O_RDWR, S_IXGRP | S_ISGID)); + + if (TST_RET == -1) { + if (errno == ENOTSUP) + tst_brk(TCONF, "fs doesn't support O_TMPFILE"); + else + tst_brk(TBROK | TTERRNO, "openat(%d, O_TMPFILE) failed", dirfd); + } + + if (TST_RET < 0) + tst_brk(TBROK, "Invalid openat return value %ld", TST_RET); + + SAFE_CLOSE(TST_RET); +} + +static void setup(void) +{ + struct stat buf; + + ltpuser = SAFE_GETPWNAM("nobody"); + + do_mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "noacl"); + + tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)ltpuser->pw_uid, + (int)ltpuser->pw_gid); + free_gid = tst_get_free_gid(ltpuser->pw_gid); + + /* Create directories and set permissions */ + SAFE_MKDIR(WORKDIR, MODE_RWX); + dir_fd = SAFE_OPEN(WORKDIR, O_RDONLY, O_DIRECTORY); + open_tmpfile_supported(dir_fd); + + SAFE_CHOWN(WORKDIR, ltpuser->pw_uid, free_gid); + SAFE_CHMOD(WORKDIR, MODE_SGID); + SAFE_STAT(WORKDIR, &buf); + + if (!(buf.st_mode & S_ISGID)) + tst_brk(TBROK, "%s: Setgid bit not set", WORKDIR); + + if (buf.st_gid != free_gid) { + tst_brk(TBROK, "%s: Incorrect group, %u != %u", WORKDIR, + buf.st_gid, free_gid); + } + + /* Switch user */ + SAFE_SETGID(ltpuser->pw_gid); + SAFE_SETREUID(-1, ltpuser->pw_uid); +} + +static void file_test(int dfd, const char *path, int flags) +{ + struct stat buf; + + SAFE_FSTATAT(dfd, path, &buf, flags); + + TST_EXP_EQ_LI(buf.st_gid, free_gid); + + if (buf.st_mode & S_ISGID) + tst_res(TFAIL, "%s: Setgid bit is set", path); + else + tst_res(TPASS, "%s: Setgid bit not set", path); + + if (buf.st_mode & S_IXGRP) + tst_res(TFAIL, "%s: S_IXGRP bit is set", path); + else + tst_res(TPASS, "%s: S_IXGRP bit is not set", path); +} + +static void run(void) +{ + char path[PATH_MAX]; + + umask(S_IXGRP); + tmpfile_fd = SAFE_OPENAT(dir_fd, ".", O_TMPFILE | O_RDWR, MODE_SGID); + snprintf(path, PATH_MAX, "/proc/self/fd/%d", tmpfile_fd); + SAFE_LINKAT(AT_FDCWD, path, dir_fd, OPEN_FILE, AT_SYMLINK_FOLLOW); + file_test(dir_fd, OPEN_FILE, 0); + SAFE_CLOSE(tmpfile_fd); + /* Cleanup between loops */ + tst_purge_dir(WORKDIR); +} + +static void cleanup(void) +{ + SAFE_SETREUID(-1, 0); + + if (tmpfile_fd >= 0) + SAFE_CLOSE(tmpfile_fd); + if (dir_fd >= 0) + SAFE_CLOSE(dir_fd); + if (mount_flag && tst_umount(MNTPOINT)) + tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .all_filesystems = 1, + .format_device = 1, + .mntpoint = MNTPOINT, + .skip_filesystems = (const char*[]) { + "exfat", + "ntfs", + "vfat", + NULL + }, + .tags = (const struct tst_tag[]) { + {"linux-git", "ac6800e279a2"}, + {} + }, +};