mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
inode: make init and permission helpers idmapped mount aware
The inode_owner_or_capable() helper determines whether the caller is the owner of the inode or is capable with respect to that inode. Allow it to handle idmapped mounts. If the inode is accessed through an idmapped mount it 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. Similarly, allow the inode_init_owner() helper to handle idmapped mounts. It initializes a new inode on idmapped mounts by mapping the fsuid and fsgid of the caller from the mount's user namespace. 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-7-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>
This commit is contained in:
@@ -1088,7 +1088,8 @@ int may_linkat(struct path *link)
|
||||
/* Source inode owner (or CAP_FOWNER) can hardlink all they like,
|
||||
* otherwise, it must be a safe source.
|
||||
*/
|
||||
if (safe_hardlink_source(inode) || inode_owner_or_capable(inode))
|
||||
if (safe_hardlink_source(inode) ||
|
||||
inode_owner_or_capable(&init_user_ns, inode))
|
||||
return 0;
|
||||
|
||||
audit_log_path_denied(AUDIT_ANOM_LINK, "linkat");
|
||||
@@ -2940,7 +2941,7 @@ static int may_open(const struct path *path, int acc_mode, int flag)
|
||||
}
|
||||
|
||||
/* O_NOATIME can only be set by the owner or superuser */
|
||||
if (flag & O_NOATIME && !inode_owner_or_capable(inode))
|
||||
if (flag & O_NOATIME && !inode_owner_or_capable(&init_user_ns, inode))
|
||||
return -EPERM;
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user