Skip to content

Commit 1ab2996

Browse files
author
Christian Brauner
committed
exec: handle idmapped mounts
When executing a setuid binary the kernel will verify in bprm_fill_uid() that the inode has a mapping in the caller's user namespace before setting the callers uid and gid. Let bprm_fill_uid() handle idmapped mounts. If the inode is accessed through an idmapped mount it is mapped according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before. Link: https://lore.kernel.org/r/20210121131959.646623-24-christian.brauner@ubuntu.com Cc: Christoph Hellwig <hch@lst.de> Cc: David Howells <dhowells@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: James Morris <jamorris@linux.microsoft.com> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent 435ac62 commit 1ab2996

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎fs/exec.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
15801580
static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
15811581
{
15821582
/* Handle suid and sgid on files */
1583+
struct user_namespace *mnt_userns;
15831584
struct inode *inode;
15841585
unsigned int mode;
15851586
kuid_t uid;
@@ -1596,13 +1597,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)
15961597
if (!(mode & (S_ISUID|S_ISGID)))
15971598
return;
15981599

1600+
mnt_userns = file_mnt_user_ns(file);
1601+
15991602
/* Be careful if suid/sgid is set */
16001603
inode_lock(inode);
16011604

16021605
/* reload atomically mode/uid/gid now that lock held */
16031606
mode = inode->i_mode;
1604-
uid = inode->i_uid;
1605-
gid = inode->i_gid;
1607+
uid = i_uid_into_mnt(mnt_userns, inode);
1608+
gid = i_gid_into_mnt(mnt_userns, inode);
16061609
inode_unlock(inode);
16071610

16081611
/* We ignore suid/sgid if there are no mappings for them in the ns */

0 commit comments

Comments
 (0)