Skip to content

Commit 54b4e5d

Browse files
ebiedermgregkh
authored andcommitted
capabilities: Don't allow writing ambiguous v3 file capabilities
[ Upstream commit 95ebabd ] The v3 file capabilities have a uid field that records the filesystem uid of the root user of the user namespace the file capabilities are valid in. When someone is silly enough to have the same underlying uid as the root uid of multiple nested containers a v3 filesystem capability can be ambiguous. In the spirit of don't do that then, forbid writing a v3 filesystem capability if it is ambiguous. Fixes: 8db6c34 ("Introduce v3 namespaced file capabilities") Reviewed-by: Andrew G. Morgan <morgan@kernel.org> Reviewed-by: Serge Hallyn <serge@hallyn.com> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bf24c51 commit 54b4e5d

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎security/commoncap.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ int cap_convert_nscap(struct dentry *dentry, void **ivalue, size_t size)
500500
__u32 magic, nsmagic;
501501
struct inode *inode = d_backing_inode(dentry);
502502
struct user_namespace *task_ns = current_user_ns(),
503-
*fs_ns = inode->i_sb->s_user_ns;
503+
*fs_ns = inode->i_sb->s_user_ns,
504+
*ancestor;
504505
kuid_t rootid;
505506
size_t newsize;
506507

@@ -523,6 +524,15 @@ int cap_convert_nscap(struct dentry *dentry, void **ivalue, size_t size)
523524
if (nsrootid == -1)
524525
return -EINVAL;
525526

527+
/*
528+
* Do not allow allow adding a v3 filesystem capability xattr
529+
* if the rootid field is ambiguous.
530+
*/
531+
for (ancestor = task_ns->parent; ancestor; ancestor = ancestor->parent) {
532+
if (from_kuid(ancestor, rootid) == 0)
533+
return -EINVAL;
534+
}
535+
526536
newsize = sizeof(struct vfs_ns_cap_data);
527537
nscap = kmalloc(newsize, GFP_ATOMIC);
528538
if (!nscap)

0 commit comments

Comments
 (0)