This is a note to let you know that I've just added the patch titled fs: tweak fsuidgid_has_mapping() to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: fs-tweak-fsuidgid_has_mapping.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Thu Jun 30 01:35:30 PM CEST 2022 From: Christian Brauner <brauner@xxxxxxxxxx> Date: Tue, 28 Jun 2022 14:16:11 +0200 Subject: fs: tweak fsuidgid_has_mapping() To: Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Christian Brauner <christian.brauner@xxxxxxxxxx>, stable@xxxxxxxxxxxxxxx Message-ID: <20220628121620.188722-4-brauner@xxxxxxxxxx> From: Christian Brauner <christian.brauner@xxxxxxxxxx> commit 476860b3eb4a50958243158861d5340066df5af2 upstream. If the caller's fs{g,u}id aren't mapped in the mount's idmapping we can return early and skip the check whether the mapped fs{g,u}id also have a mapping in the filesystem's idmapping. If the fs{g,u}id aren't mapped in the mount's idmapping they consequently can't be mapped in the filesystem's idmapping. So there's no point in checking that. Link: https://lore.kernel.org/r/20211123114227.3124056-4-brauner@xxxxxxxxxx (v1) Link: https://lore.kernel.org/r/20211130121032.3753852-4-brauner@xxxxxxxxxx (v2) Link: https://lore.kernel.org/r/20211203111707.3901969-4-brauner@xxxxxxxxxx Cc: Seth Forshee <sforshee@xxxxxxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> CC: linux-fsdevel@xxxxxxxxxxxxxxx Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx> Reviewed-by: Seth Forshee <sforshee@xxxxxxxxxxxxxxxx> Signed-off-by: Christian Brauner <christian.brauner@xxxxxxxxxx> Signed-off-by: Christian Brauner (Microsoft) <brauner@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- include/linux/fs.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1697,10 +1697,18 @@ static inline void inode_fsgid_set(struc static inline bool fsuidgid_has_mapping(struct super_block *sb, struct user_namespace *mnt_userns) { - struct user_namespace *s_user_ns = sb->s_user_ns; + struct user_namespace *fs_userns = sb->s_user_ns; + kuid_t kuid; + kgid_t kgid; - return kuid_has_mapping(s_user_ns, mapped_fsuid(mnt_userns)) && - kgid_has_mapping(s_user_ns, mapped_fsgid(mnt_userns)); + kuid = mapped_fsuid(mnt_userns); + if (!uid_valid(kuid)) + return false; + kgid = mapped_fsgid(mnt_userns); + if (!gid_valid(kgid)) + return false; + return kuid_has_mapping(fs_userns, kuid) && + kgid_has_mapping(fs_userns, kgid); } extern struct timespec64 current_time(struct inode *inode); Patches currently in stable-queue which might be from brauner@xxxxxxxxxx are queue-5.15/fs-account-for-group-membership.patch queue-5.15/fs-use-low-level-mapping-helpers.patch queue-5.15/fs-move-mapping-helpers.patch queue-5.15/fs-remove-unused-low-level-mapping-helpers.patch queue-5.15/fs-tweak-fsuidgid_has_mapping.patch queue-5.15/fs-add-i_user_ns-helper.patch queue-5.15/fs-add-is_idmapped_mnt-helper.patch queue-5.15/fs-support-mapped-mounts-of-mapped-filesystems.patch queue-5.15/fs-fix-acl-translation.patch queue-5.15/fs-port-higher-level-mapping-helpers.patch queue-5.15/docs-update-mapping-documentation.patch queue-5.15/fs-account-for-filesystem-mappings.patch