From patchwork Thu Mar 31 09:28: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: 12796938 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 CB9AAC433F5 for ; Thu, 31 Mar 2022 09:29:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234004AbiCaJas (ORCPT ); Thu, 31 Mar 2022 05:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbiCaJai (ORCPT ); Thu, 31 Mar 2022 05:30:38 -0400 Received: from mail1.bemta36.messagelabs.com (mail1.bemta36.messagelabs.com [85.158.142.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05B22203A7D; Thu, 31 Mar 2022 02:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1648718888; i=@fujitsu.com; bh=11hHL51oJKIRRxJ2cKGm8qGia+vQkgT71xo8XfL1lYk=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=WZmObQvO69zpIC7M7M3usxpDbuHb1Z0wBMdsokqyEUoI0mSfhJJr7ieOg7y3YbyjG Dpvk2Vshf1uwiW3wyxPfGkInbB9KbsMBviDQlAeRSm27izwaqeXbp4joC4QxXBp6yg 48asTRlrFwynYBGgEOOH3xLft29bGjZcEkcI2uAirFCTSZ6K3p+lfvaEOziJxMzMol 9AafxkIZHBdBqo3w9WFnf9DLGKSFXJa0EIul+z2JchS5sorqr3RDX+wlxuxrjBJlH0 uWxjuqNPfMkZoTISgsdf20hdTnpTdhFtnKqXCIgzrv+V6rJFg6PgKLyBx8xUcUlHIY vS+rHNkFu8M1Q== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLIsWRWlGSWpSXmKPExsViZ8ORqKte4pp k8GaSgcXrw58YLbYcu8docfkJn8Xplr3sFnv2nmRxYPU4tUjCY9OqTjaPz5vkApijWDPzkvIr Elgz/lxeylIw373iw/NmpgbG+1ZdjFwcQgJbGCX2fL3HDOEsYJLo6fvCAuHsYZTY/WI5axcjJ webgKbEs84FzCC2iICLxLf9f9lAbGaBFImG802MILawgK/EwoWvgOo5OFgEVCVO9TmDhHkFPC Ra915mAbElBBQkpjx8zwwRF5Q4OfMJC8QYCYmDL14wQ9QoSlzq+MYIYVdIzJrVxgRhq0lcPbe JeQIj/ywk7bOQtC9gZFrFaJdUlJmeUZKbmJmja2hgoGtoaKprZqZrZGShl1ilm6iXWqqbnJpX UpQIlNZLLC/WSy0u1iuuzE3OSdHLSy3ZxAgM6ZRipyc7GF/3/dQ7xCjJwaQkyusU4JokxJeUn 1KZkVicEV9UmpNafIhRhoNDSYK3vgAoJ1iUmp5akZaZA4wvmLQEB4+SCG8oSJq3uCAxtzgzHS J1ilGX4++nv3uZhVjy8vNSpcR5ZxcCFQmAFGWU5sGNgMX6JUZZKWFeRgYGBiGegtSi3MwSVPl XjOIcjErCvFeLgKbwZOaVwG16BXQEE9ARdY8dQY4oSURISTUwhT2953lm+6yFNRF5614vl7aY u27zMTFF9892SS/jGk8/aTrM9UP/84eToRNij/mpKk7LW/9g8pofK+/VLJC7ck5lquK5+Ja97 3skZVne1WluK2L98viOYMJbj9+TEw4cDXvCetpXW+i/68qFlfJ/T17K2Zh6soVH6c2qQyt3L4 wRVc++eWPzY7abM8+0z4zJcHH7vUNKwKbdg1P8pS7ru2Of1rWdcpcO6QyXur+UoWm1q4DKn0P njzhns7lssmKynVE9V3pzVaf0nDr+k/Xrn16x/LD3ycrrmzdXtM6Wvzdn4ZsAsXBzFta5z+++ eOG/IjZHNX7dDOconcN58jqcDlc+sL7iaI97XjthtUZllYoSS3FGoqEWc1FxIgABoqgVcAMAA A== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-3.tower-545.messagelabs.com!1648718887!135975!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.85.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15602 invoked from network); 31 Mar 2022 09:28:07 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-3.tower-545.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 31 Mar 2022 09:28:07 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 065721001B8; Thu, 31 Mar 2022 10:28:07 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (unknown [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id B291B1001AE; Thu, 31 Mar 2022 10:28:06 +0100 (BST) 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; Thu, 31 Mar 2022 10:27:53 +0100 From: Yang Xu To: , , CC: , , Yang Xu Subject: [PATCH v1 1/2] idmapped-mounts: Add mknodat operation in setgid test Date: Thu, 31 Mar 2022 17:28:21 +0800 Message-ID: <1648718902-2319-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 R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since mknodat can create file, we should also check whether strip S_ISGID. Also add new helper caps_down_fsetid to drop CAP_FSETID because strip S_ISGID depond on this cap and keep other cap(ie CAP_MKNOD) because create character device needs it when using mknod. Only test mknod with character device in setgid_create function because the another two functions will hit EPERM error. Signed-off-by: Yang Xu Tested-by: Christian Brauner (Microsoft) Reviewed-by: Christian Brauner (Microsoft) --- src/idmapped-mounts/idmapped-mounts.c | 154 ++++++++++++++++++++++++-- 1 file changed, 147 insertions(+), 7 deletions(-) diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c index 4cf6c3bb..1e2f3904 100644 --- a/src/idmapped-mounts/idmapped-mounts.c +++ b/src/idmapped-mounts/idmapped-mounts.c @@ -241,6 +241,34 @@ static inline bool caps_supported(void) return ret; } +static int caps_down_fsetid(void) +{ + bool fret = false; +#ifdef HAVE_SYS_CAPABILITY_H + cap_t caps = NULL; + cap_value_t cap = CAP_FSETID; + int ret = -1; + + caps = cap_get_proc(); + if (!caps) + goto out; + + ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, 0); + if (ret) + goto out; + + ret = cap_set_proc(caps); + if (ret) + goto out; + + fret = true; + +out: + cap_free(caps); +#endif + return fret; +} + /* caps_down - lower all effective caps */ static int caps_down(void) { @@ -7805,8 +7833,8 @@ out_unmap: #endif /* HAVE_LIBURING_H */ /* The following tests are concerned with setgid inheritance. These can be - * filesystem type specific. For xfs, if a new file or directory is created - * within a setgid directory and irix_sgid_inhiert is set then inherit the + * filesystem type specific. For xfs, if a new file or directory or node is + * created within a setgid directory and irix_sgid_inhiert is set then inherit the * setgid bit if the caller is in the group of the directory. */ static int setgid_create(void) @@ -7863,15 +7891,41 @@ static int setgid_create(void) if (!is_setgid(t_dir1_fd, DIR1, 0)) die("failure: is_setgid"); + /* create a special file via mknodat() vfs_create */ + if (mknodat(t_dir1_fd, DIR1 "/" FILE1, S_IFREG | S_ISGID | 0755, 0)) + die("failure: mknodat"); + + if (!is_setgid(t_dir1_fd, DIR1 "/" FILE1, 0)) + die("failure: is_setgid"); + + /* create a character device via mknodat() vfs_mknod */ + if (mknodat(t_dir1_fd, CHRDEV1, S_IFCHR | S_ISGID | 0755, makedev(5, 1))) + die("failure: mknodat"); + + if (!is_setgid(t_dir1_fd, CHRDEV1, 0)) + die("failure: is_setgid"); + if (!expected_uid_gid(t_dir1_fd, FILE1, 0, 0, 0)) die("failure: check ownership"); + if (!expected_uid_gid(t_dir1_fd, DIR1 "/" FILE1, 0, 0, 0)) + die("failure: check ownership"); + + if (!expected_uid_gid(t_dir1_fd, CHRDEV1, 0, 0, 0)) + die("failure: check ownership"); + if (!expected_uid_gid(t_dir1_fd, DIR1, 0, 0, 0)) die("failure: check ownership"); if (unlinkat(t_dir1_fd, FILE1, 0)) die("failure: delete"); + if (unlinkat(t_dir1_fd, DIR1 "/" FILE1, 0)) + die("failure: delete"); + + if (unlinkat(t_dir1_fd, CHRDEV1, 0)) + die("failure: delete"); + if (unlinkat(t_dir1_fd, DIR1, AT_REMOVEDIR)) die("failure: delete"); @@ -7889,8 +7943,8 @@ static int setgid_create(void) if (!switch_ids(0, 10000)) die("failure: switch_ids"); - if (!caps_down()) - die("failure: caps_down"); + if (!caps_down_fsetid()) + die("failure: caps_down_fsetid"); /* create regular file via open() */ file1_fd = openat(t_dir1_fd, FILE1, O_CREAT | O_EXCL | O_CLOEXEC, S_IXGRP | S_ISGID); @@ -7917,6 +7971,19 @@ static int setgid_create(void) die("failure: is_setgid"); } + /* create a special file via mknodat() vfs_create */ + if (mknodat(t_dir1_fd, DIR1 "/" FILE1, S_IFREG | S_ISGID | 0755, 0)) + die("failure: mknodat"); + + if (is_setgid(t_dir1_fd, DIR1 "/" FILE1, 0)) + die("failure: is_setgid"); + + /* create a character device via mknodat() vfs_mknod */ + if (mknodat(t_dir1_fd, CHRDEV1, S_IFCHR | S_ISGID | 0755, makedev(5, 1))) + die("failure: mknodat"); + + if (is_setgid(t_dir1_fd, CHRDEV1, 0)) + die("failure: is_setgid"); /* * In setgid directories newly created files always inherit the * gid from the parent directory. Verify that the file is owned @@ -7933,6 +8000,24 @@ static int setgid_create(void) if (!expected_uid_gid(t_dir1_fd, DIR1, 0, 0, 0)) die("failure: check ownership"); + if (!expected_uid_gid(t_dir1_fd, DIR1 "/" FILE1, 0, 0, 0)) + die("failure: check ownership"); + + if (!expected_uid_gid(t_dir1_fd, CHRDEV1, 0, 0, 0)) + die("failure: check ownership"); + + if (unlinkat(t_dir1_fd, FILE1, 0)) + die("failure: delete"); + + if (unlinkat(t_dir1_fd, DIR1 "/" FILE1, 0)) + die("failure: delete"); + + if (unlinkat(t_dir1_fd, CHRDEV1, 0)) + die("failure: delete"); + + if (unlinkat(t_dir1_fd, DIR1, AT_REMOVEDIR)) + die("failure: delete"); + exit(EXIT_SUCCESS); } if (wait_for_pid(pid)) @@ -8051,6 +8136,12 @@ static int setgid_create_idmapped(void) if (!expected_uid_gid(open_tree_fd, DIR1, 0, 10000, 10000)) die("failure: check ownership"); + if (unlinkat(t_dir1_fd, FILE1, 0)) + die("failure: delete"); + + if (unlinkat(t_dir1_fd, DIR1, AT_REMOVEDIR)) + die("failure: delete"); + exit(EXIT_SUCCESS); } if (wait_for_pid(pid)) @@ -8149,15 +8240,26 @@ static int setgid_create_idmapped_in_userns(void) if (!is_setgid(open_tree_fd, DIR1, 0)) die("failure: is_setgid"); + /* create a special file via mknodat() vfs_create */ + if (mknodat(open_tree_fd, DIR1 "/" FILE1, S_IFREG | S_ISGID | 755, 0)) + die("failure: mknodat"); + + if (!is_setgid(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: is_setgid"); + if (!expected_uid_gid(open_tree_fd, FILE1, 0, 0, 0)) die("failure: check ownership"); if (!expected_uid_gid(open_tree_fd, DIR1, 0, 0, 0)) die("failure: check ownership"); + if (!expected_uid_gid(open_tree_fd, DIR1 "/" FILE1, 0, 0, 0)) + die("failure: check ownership"); + if (unlinkat(open_tree_fd, FILE1, 0)) die("failure: delete"); - + if (unlinkat(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: delete"); if (unlinkat(open_tree_fd, DIR1, AT_REMOVEDIR)) die("failure: delete"); @@ -8190,9 +8292,12 @@ static int setgid_create_idmapped_in_userns(void) exit(EXIT_SUCCESS); } - if (!switch_userns(attr.userns_fd, 0, 0, true)) + if (!switch_userns(attr.userns_fd, 0, 0, false)) die("failure: switch_userns"); + if (!caps_down_fsetid()) + die("failure: caps_down_fsetid"); + /* create regular file via open() */ file1_fd = openat(open_tree_fd, FILE1, O_CREAT | O_EXCL | O_CLOEXEC, S_IXGRP | S_ISGID); if (file1_fd < 0) @@ -8218,6 +8323,13 @@ static int setgid_create_idmapped_in_userns(void) die("failure: is_setgid"); } + /* create a special file via mknodat() vfs_create */ + if (mknodat(open_tree_fd, DIR1 "/" FILE1, S_IFREG | S_ISGID | 0755, 0)) + die("failure: mknodat"); + + if (is_setgid(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: is_setgid"); + /* * In setgid directories newly created files always inherit the * gid from the parent directory. Verify that the file is owned @@ -8234,9 +8346,15 @@ static int setgid_create_idmapped_in_userns(void) if (!expected_uid_gid(open_tree_fd, DIR1, 0, 0, 1000)) die("failure: check ownership"); + if (!expected_uid_gid(open_tree_fd, DIR1 "/" FILE1, 0, 0, 1000)) + die("failure: check ownership"); + if (unlinkat(open_tree_fd, FILE1, 0)) die("failure: delete"); + if (unlinkat(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: delete"); + if (unlinkat(open_tree_fd, DIR1, AT_REMOVEDIR)) die("failure: delete"); @@ -8266,9 +8384,12 @@ static int setgid_create_idmapped_in_userns(void) exit(EXIT_SUCCESS); } - if (!switch_userns(attr.userns_fd, 0, 1000, true)) + if (!switch_userns(attr.userns_fd, 0, 1000, false)) die("failure: switch_userns"); + if (!caps_down_fsetid()) + die("failure: caps_down_fsetid"); + /* create regular file via open() */ file1_fd = openat(open_tree_fd, FILE1, O_CREAT | O_EXCL | O_CLOEXEC, S_IXGRP | S_ISGID); if (file1_fd < 0) @@ -8295,12 +8416,31 @@ static int setgid_create_idmapped_in_userns(void) die("failure: is_setgid"); } + /* create a special file via mknodat() vfs_create */ + if (mknodat(open_tree_fd, DIR1 "/" FILE1, S_IFREG | S_ISGID | 0755, 0)) + die("failure: mknodat"); + + if (is_setgid(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: is_setgid"); + if (!expected_uid_gid(open_tree_fd, FILE1, 0, 0, 0)) die("failure: check ownership"); + if (!expected_uid_gid(open_tree_fd, DIR1 "/" FILE1, 0, 0, 0)) + die("failure: check ownership"); + if (!expected_uid_gid(open_tree_fd, DIR1, 0, 0, 0)) die("failure: check ownership"); + if (unlinkat(open_tree_fd, FILE1, 0)) + die("failure: delete"); + + if (unlinkat(open_tree_fd, DIR1 "/" FILE1, 0)) + die("failure: delete"); + + if (unlinkat(open_tree_fd, DIR1, AT_REMOVEDIR)) + die("failure: delete"); + exit(EXIT_SUCCESS); } if (wait_for_pid(pid)) From patchwork Thu Mar 31 09:28: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: 12796937 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 C2E39C433F5 for ; Thu, 31 Mar 2022 09:29:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232514AbiCaJaq (ORCPT ); Thu, 31 Mar 2022 05:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234159AbiCaJag (ORCPT ); Thu, 31 Mar 2022 05:30:36 -0400 Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4390203A63; Thu, 31 Mar 2022 02:28:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1648718888; i=@fujitsu.com; bh=Ws9HhmWwP1sg/MJi353iJBVOr7t8+QgQ8rvucPbJZgE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Dj1ROLcc6zW264WS/lCGttVW2wkgzvcUgWeG27Qq7o7TZYZXB86lxhiogVpvEQSH8 yp5m0esA8nHQ3WAbt6xRULH1qv3+eTfhwQYR7ptd9K5fo/GjWnxjS2E1jH9Da8tD+J i2eNo7FLBSe/34mwH0ytshQpqEUwnqIf/GXrbEUYSnthr4FU7xhh4rEAs+FKilBL4m PHFuMZeOXDeIdqLWZ4cZca62wWK39ltqnz+JJ4HVA3jsjJSfRjtP/HiEGpfb8b7rKi Ktmew8/0TDLmU0cXQqWBNgufnsYBtLYCfKd6YUPk7PIfBOVPTUuJmDi5SEF23HfSPV uH5DDdGYUkTYg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMIsWRWlGSWpSXmKPExsViZ8ORqKtR4pp ksGwyh8Xrw58YLbYcu8docfkJn8Xplr3sFnv2nmRxYPU4tUjCY9OqTjaPz5vkApijWDPzkvIr Elgzfs58zFiwk6Ni6vL7rA2MvexdjJwcQgJbGCVm/MiGsBcwSfzosehi5AKy9zBKrD9+iQUkw SagKfGscwEziC0i4CLxbf9fNhCbWSBFouF8E2MXIweHsICPxIQP1SBhFgFVibkdW5lAbF4BD4 krXVdYQWwJAQWJKQ/fg43hFPCU+LZpPTNIqxBQzbRbgRDlghInZz5hgZguIXHwxQtmiFZFiUs d3xgh7AqJWbPamCBsNYmr5zYxT2AUnIWkfRaS9gWMTKsYrZOKMtMzSnITM3N0DQ0MdA0NTXWN TXSNDC30Eqt0E/VSS3XLU4tLdI30EsuL9VKLi/WKK3OTc1L08lJLNjECwz6lWOnWDsYNq37qH WKU5GBSEuV1CnBNEuJLyk+pzEgszogvKs1JLT7EKMPBoSTBW18AlBMsSk1PrUjLzAHGIExago NHSYQ3FCTNW1yQmFucmQ6ROsWoKCXOO7sQKCEAksgozYNrg8X9JUZZKWFeRgYGBiGegtSi3Mw SVPlXjOIcjErCvFeLgKbwZOaVwE1/BbSYCWhx3WNHkMUliQgpqQam/nLuj6dyzmv9nbXl52Ym vduH1R/LyMncj7x4IKT2ofqfvfZvDkUsvhGx8orUsc0xHlHMvAoZlzXFH3R+vhb/T+nj1r2dn 5LNehdsTUmtSnl7qkXyPE+yyGnhRZkPX9gUzHRoT8//87vAiTEuQ1Bs8aT8Z6fW9xaci1g/cU LvNrE/7zI99VQW333uz9nn89617aTIp6SL+/zOGr/SmLF+RtwRXq3K9Z8YbvJsWO75LlJi8cS lCzS+3kqereF/a/HenjVPFiTv0YzhLVGdlViZ8lmvT/iD87mn7bN6vpa8CH7hMOFlmZ5Fdqa2 xf/rwnyb3p6N4udf8GSqSvfdhVs3559LWaHr6yWwZ+nfk/OPBSuxFGckGmoxFxUnAgCbulbVd gMAAA== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-32.tower-565.messagelabs.com!1648718887!166249!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.85.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14123 invoked from network); 31 Mar 2022 09:28:08 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-32.tower-565.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 31 Mar 2022 09:28:08 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 4E26B1001AE; Thu, 31 Mar 2022 10:28:07 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (unknown [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id BC0301001B1; Thu, 31 Mar 2022 10:28:06 +0100 (BST) 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; Thu, 31 Mar 2022 10:28:00 +0100 From: Yang Xu To: , , CC: , , Yang Xu Subject: [PATCH v1 2/2] idmapped-mounts: Add umask before test setgid_create Date: Thu, 31 Mar 2022 17:28:22 +0800 Message-ID: <1648718902-2319-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1648718902-2319-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1648718902-2319-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) X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Since stipping S_SIGID should check S_IXGRP, so umask it to check whether works well. Signed-off-by: Yang Xu Tested-by: Christian Brauner (Microsoft) Reviewed-by: Christian Brauner (Microsoft) --- If we enable acl on parent directory, then umask is useless, maybe we also add setfacl on parent directory because we may change the order about strip S_ISGID and posix_acl setup. Any idea? src/idmapped-mounts/idmapped-mounts.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c index 1e2f3904..30292426 100644 --- a/src/idmapped-mounts/idmapped-mounts.c +++ b/src/idmapped-mounts/idmapped-mounts.c @@ -7843,6 +7843,7 @@ static int setgid_create(void) int file1_fd = -EBADF; pid_t pid; + umask(S_IXGRP); if (!caps_supported()) return 0; @@ -8040,6 +8041,8 @@ static int setgid_create_idmapped(void) }; pid_t pid; + umask(S_IXGRP); + if (!caps_supported()) return 0; @@ -8166,6 +8169,7 @@ static int setgid_create_idmapped_in_userns(void) }; pid_t pid; + umask(S_IXGRP); if (!caps_supported()) return 0;