attr: add in_group_or_capable()
authorChristian Brauner <brauner@kernel.org>
Tue, 7 Mar 2023 18:59:18 +0000 (10:59 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Mar 2023 07:49:00 +0000 (08:49 +0100)
commit93395e1184eda8c3d2cdae201808221f3a1eb816
treedde88da0a9113a9437d119e5235a47c849114d2e
parent0123712492f6dda9b5fd815eaccef8c34bac4db1
attr: add in_group_or_capable()

commit 11c2a8700cdcabf9b639b7204a1e38e2a0b6798e upstream.

[backport to 5.15.y, prior to vfsgid_t]

In setattr_{copy,prepare}() we need to perform the same permission
checks to determine whether we need to drop the setgid bit or not.
Instead of open-coding it twice add a simple helper the encapsulates the
logic. We will reuse this helpers to make dropping the setgid bit during
write operations more consistent in a follow up patch.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Tested-by: Leah Rumancik <leah.rumancik@gmail.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/attr.c
fs/inode.c
fs/internal.h