From patchwork Fri Apr 15 11:02:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 561950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3C6AC4332F for ; Fri, 15 Apr 2022 10:03:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352102AbiDOKFt (ORCPT ); Fri, 15 Apr 2022 06:05:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352091AbiDOKFq (ORCPT ); Fri, 15 Apr 2022 06:05:46 -0400 Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 331F7BB0AA; Fri, 15 Apr 2022 03:03:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1650016996; i=@fujitsu.com; bh=umWvxw61hLIrbg/P5jUPIscneWN2fsBQmpr2GWuMT1w=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N9X5mnLhce+1t4S94dAZ23gA4neRsLoDqT9V4/dqE0sRcq8/eHi5rAcr/5ELDTNc6 tEYc5RwuuWPa8QbtTopuztzK6/zHn2Odf+CYNzzuBJN/jM8yvrdVTBva/eqCFbtxaC f+dEZVLXYEta9KFRIS84+DDgn/H0++ZIJMzbjv9B4UD9q+0loLgekmAqpJK88ZFML1 j2O0rimxUTCt4dDGYNqPyOfQZK/jOfXW9PAbSVmjk4TqFoiVJx6x/KiDs01jIMK8Qg Jvql/fFjm/Qgsmr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2cc Pmc6HfV/xnbb3Frg75SkmfXmWgXGofwSGxmTrDbyFGTo5ixX+bUsq4Bz6dGvSizFGYmGWsxFx YkAQ7iXxHkDAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-12.tower-587.messagelabs.com!1650016995!55935!1 X-Originating-IP: [62.60.8.84] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.85.8; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16905 invoked from network); 15 Apr 2022 10:03:15 -0000 Received: from unknown (HELO mailhost3.uk.fujitsu.com) (62.60.8.84) by server-12.tower-587.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Apr 2022 10:03:15 -0000 Received: from R01UKEXCASM126.r01.fujitsu.local ([10.183.43.178]) by mailhost3.uk.fujitsu.com (8.14.5/8.14.5) with ESMTP id 23FA3Fer019126 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Fri, 15 Apr 2022 11:03:15 +0100 Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Fri, 15 Apr 2022 11:03:10 +0100 From: Yang Xu To: , , CC: , , , , , , Yang Xu Subject: [PATCH v3 5/7] fs: Add new helper prepare_mode Date: Fri, 15 Apr 2022 19:02:21 +0800 Message-ID: <1650020543-24908-5-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1650020543-24908-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1650020543-24908-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 R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org As Christian Brauner suggested, add a new helper calls inode_sgid_strip() and does the umask stripping as well and then call it in all these places. This api is introduced to support strip file's S_ISGID mode on vfs instead of on underlying filesystem. Suggested-by: Christian Brauner (Microsoft) Signed-off-by: Yang Xu --- include/linux/fs.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 4a617aaab6f6..8c2f4cde974b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3458,6 +3458,15 @@ static inline bool dir_relax_shared(struct inode *inode) return !IS_DEADDIR(inode); } +static inline void prepare_mode(struct user_namespace *mnt_userns, + const struct inode *dir, umode_t *mode) +{ + inode_sgid_strip(mnt_userns, dir, mode); + + if (!IS_POSIXACL(dir)) + *mode &= ~current_umask(); +} + extern bool path_noexec(const struct path *path); extern void inode_nohighmem(struct inode *inode);