Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6866448rwr; Tue, 2 May 2023 06:39:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZCL7bohVWSgAR1QWEmcaSdfE+01bOCQ5jy+VM5sZXlsTQW/7wHyihvzEberqJoVSKr7Ga X-Received: by 2002:a05:6a20:be8a:b0:f2:f505:951 with SMTP id gf10-20020a056a20be8a00b000f2f5050951mr15288592pzb.13.1683034740088; Tue, 02 May 2023 06:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683034740; cv=none; d=google.com; s=arc-20160816; b=efaXWBIgdqowdzLJZsbdfKt5FOVOSqDUtI3ybfPEFcZDLIDNfa045mHqBbeByKMzsm fgWcYRxXuOaoiOZPGBy7CAgd9KfXvLZeJMOfmwMBjnPjmfKF4gyDWOX1I2NOqOY1lsg+ UXygXZUXKBhOZi6G4P5g92Su2R80/lKyoZ4eXvPdXfLfN7w/bnUSgo2yvByKeckNd8Zn s8GvAn3wVuCV1tG0ZRz6O1Gzl1Gq0BvKgxMHUig89796k/kznoIuPKFRaA3v491NxKsB ExA3mQgz7f80x8rHza79owlQpGDgtpMKhxaGcGTqziKLbxK9g9y0x0M0T0jCVUlVt7sl mLrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=CZIqgde6z1Ut+mU04TDhnaKFClBAv3FWq8ynBjhh/0k=; b=TFNfyjrS4Aod5LGEdc1i++OA57VmvFjP/7S+/drVkT04HI/AaCs2RTwZTCbkUaw6dg ioiAOn18HhtwQpRJoK78g5TqhkrrMToDXUxr1ImVjypTrjajcnp59lwA0/+17E3mfhr1 ehhuSUpYf5oCNlt28rImnqCzid5+XhiOha9sdR4lWPqAYuUcl1Ij4c3w3n6eYA6IwGT1 g8efnuwQ3K/KTmLrhqsULLQ3CH6KZLN0AMGFYt4i64DcfM1dfftTR0i1wwzouesmR/IU 6zxkRDxX3p02xv4WzA+vkF/5f43YlKgq7cTPHe993LBmDDW5VvoSGbHOGZ7wrlw9m5eE FjlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Uh/ft862"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a63d005000000b00513218b46b1si29993670pgf.385.2023.05.02.06.38.33; Tue, 02 May 2023 06:39:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Uh/ft862"; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234212AbjEBNg3 (ORCPT + 99 others); Tue, 2 May 2023 09:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234299AbjEBNg0 (ORCPT ); Tue, 2 May 2023 09:36:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DCFD6A5A for ; Tue, 2 May 2023 06:36:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C182462480 for ; Tue, 2 May 2023 13:36:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94D39C4339C; Tue, 2 May 2023 13:36:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683034574; bh=cREU9j+BYCVPtChZc46xMyHx5WzMy5qtAL1TmQg1vgU=; h=From:To:Cc:Subject:Date:From; b=Uh/ft862Wdbet1pnQFLpFUNyQ5lN9Fix2MTfuPtDqb/oNI+AwUJZ5VWaqwP9S34TC hHKjF1N0fx9EZnNCzYYaJLN8NFpGqqSRI6phVlN5HvtepXywK8ajm+uLlcN4yKV0gA TbFF4fiqLu55DZOw5hLzSpLxzUCI3Crbrwsw0v0bYX2WcguzrB804GQpJ206JFBgCT fiUJV5dn5Wn3vFlOiMrQUbpbPWmeOIkdBdO/dhgHI9pw6TGBVIMTZ2l7MCBUvBbeF/ aHi6Kwb2nfMBjBbP+7gYsT8HQoPPj1nYzh4fhCwk+pr/wV+WW5f9l+7RTb0hpIpbi7 ul/pDBtz2hllA== From: Christian Brauner To: Chuck Lever , Jeff Layton Cc: Christian Brauner , linux-nfs@vger.kernel.org, Sherry Yang Subject: [PATCH] nfsd: use vfs setgid helper Date: Tue, 2 May 2023 15:36:02 +0200 Message-Id: <20230502-agenda-regeln-04d2573bd0fd@brauner> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2712; i=brauner@kernel.org; h=from:subject:message-id; bh=cREU9j+BYCVPtChZc46xMyHx5WzMy5qtAL1TmQg1vgU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQECjyOftpsf/hxUXfloRgn6xcXs37XZj7ecZpnrcgjg3pR b0GnjlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIkYL2RkmPc7Q3fP/1UztH1ueQSa6W iFHtiR1FL32nzL/xXT4mNX/mL4XzrrrLq3zXoZ9bA3TALfF6dZTdmizH71xr3oxb4Vpuc5WAE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org We've aligned setgid behavior over multiple kernel releases. The details can be found in commit cf619f891971 ("Merge tag 'fs.ovl.setgid.v6.2' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping") and commit 426b4ca2d6a5 ("Merge tag 'fs.setgid.v6.0' of git://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux"). Consistent setgid stripping behavior is now encapsulated in the setattr_should_drop_sgid() helper which is used by all filesystems that strip setgid bits outside of vfs proper. Usually ATTR_KILL_SGID is raised in e.g., chown_common() and is subject to the setattr_should_drop_sgid() check to determine whether the setgid bit can be retained. Since nfsd is raising ATTR_KILL_SGID unconditionally it will cause notify_change() to strip it even if the caller had the necessary privileges to retain it. Ensure that nfsd only raises ATR_KILL_SGID if the caller lacks the necessary privileges to retain the setgid bit. Without this patch the setgid stripping tests in LTP will fail: > As you can see, the problem is S_ISGID (0002000) was dropped on a > non-group-executable file while chown was invoked by super-user, while [...] > fchown02.c:66: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700 [...] > chown02.c:57: TFAIL: testfile2: wrong mode permissions 0100700, expected 0102700 With this patch all tests pass. Reported-by: Sherry Yang Signed-off-by: Christian Brauner --- ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s chown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2fa ubuntu@imp1-vm:~/ltp-install$ sudo ./runltp -d /mnt -s fchown02 INFO: ltp-pan reported all tests PASS LTP Version: 20230127-112-gf41e8a2fa ubuntu@imp1-vm:~/src/git/xfstests$ sudo ./check -g perms FSTYP -- nfs PLATFORM -- Linux/x86_64 imp1-vm 6.3.0-nfs-setgid-3a3cfe624076 #20 SMP PREEMPT_DYNAMIC Tue May 2 12:35:51 UTC 2023 MKFS_OPTIONS -- 127.0.0.1:/nfsscratch MOUNT_OPTIONS -- -o vers=3,noacl 127.0.0.1:/nfsscratch /mnt/scratch Passed all 41 tests --- fs/nfsd/vfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c index bb9d47172162..c4ef24c5ffd0 100644 --- a/fs/nfsd/vfs.c +++ b/fs/nfsd/vfs.c @@ -388,7 +388,9 @@ nfsd_sanitize_attrs(struct inode *inode, struct iattr *iap) iap->ia_mode &= ~S_ISGID; } else { /* set ATTR_KILL_* bits and let VFS handle it */ - iap->ia_valid |= (ATTR_KILL_SUID | ATTR_KILL_SGID); + iap->ia_valid |= ATTR_KILL_SUID; + iap->ia_valid |= + setattr_should_drop_sgid(&nop_mnt_idmap, inode); } } } -- 2.34.1