idmapped mounts
Subsystems (94)
v6 cover idmapped mounts
Hey everyone,
The only major change is the updated version of hch's pach to port xfs to support idmapped mounts. Thanks again to Christoph for doing that work.
(Otherwise Acked-bys and Reviewed-bys were added and the tree reordered
to decouple filesystem specific conversion from the vfs work so they can proceed independent.
For a full list of major changes between versions see the end of this cover letter. Please also note the large xfstests testsuite in patch 42 that has been kept as part of this series. It verifies correct vfs behavior with and without idmapped mounts including covering newer vfs features such as io_uring.
I currently still plan to target the v5.12 merge window.)
With this patchset we make it possible to attach idmappings to mounts, i.e. simply put different bind mounts can expose the same file or directory with different ownership.
Shifting of ownership on a per-mount basis handles a wide range of long standing use-cases. Here are just a few:
- Shifting of a subset of ownership-less filesystems (vfat) for use by multiple users, effectively allowing for DAC on such devices (systemd, Android, ...)
- Allow remapping uid/gid on external filesystems or paths (USB sticks, network filesystem, ...) to match the local system's user and groups. (David Howells intends to port AFS as a first candidate.)
- Shifting of a container rootfs or base image without having to mangle every file (runc, Docker, containerd, k8s, LXD, systemd ...)
- Sharing of data between host or privileged containers with unprivileged containers (runC, Docker, containerd, k8s, LXD, ...)
- Data sharing between multiple user namespaces with incompatible maps (LXD, k8s, ...)
There has been significant interest in this patchset as evidenced by user commenting on previous version of this patchset. They include containerd, ChromeOS, systemd, LXD and a range of others. There is already a patchset up for containerd, the default Kubernetes container runtime https://github.com/containerd/containerd/pull/4734
to make use of this. systemd intends to use it in their systemd-homed implementation for portable home directories. ChromeOS wants to make use of it to share data between the host and the Linux containers they run on Chrome- and Pixelbooks. There's also a few talks that of people who are going to make use of this. The most recent one was a CNCF webinar
https://www.cncf.io/wp-content/uploads/2020/12/Rootless-Containers-in-Gitpod.pdf
and upcoming talk during FOSDEM.
(Fwiw, for fun and since I wanted to do this for a long time I've ported
my home directory to be completely portable with a simple service file that now mounts my home directory on an ext4 formatted usb stick with an id mapping mapping all files to the random uid I'm assigned at login.)
Making it possible to share directories and mounts between users with different uids and gids is itself quite an important use-case in distributed systems environments. It's of course especially useful in general for portable usb sticks, sharing data between multiple users in, and sharing home directories between multiple users. The last example is now elegantly expressed in systemd's homed concept for portable home directories. As mentioned above, idmapped mounts also allow data from the host to be shared with unprivileged containers, between privileged and unprivileged containers simultaneously and in addition also between unprivileged containers with different idmappings whenever they are used to isolate one container completely from another container.
We have implemented and proposed multiple solutions to this before. This included the introduction of fsid mappings, a tiny filesystem I've authored with Seth Forshee that is currently carried in Ubuntu that has shown to be the wrong approach, and the conceptual hack of calling override creds directly in the vfs. In addition, to some of these solutions being hacky none of these solutions have covered all of the above use-cases.
Idmappings become a property of struct vfsmount instead of tying it to a process being inside of a user namespace which has been the case for all other proposed approaches. It also allows to pass down the user namespace into the filesystems which is a clean way instead of violating calling conventions by strapping the user namespace information that is a property of the mount to the caller's credentials or similar hacks. Each mount can have a separate idmapping and idmapped mounts can even be created in the initial user namespace unblocking a range of use-cases.
To this end the vfsmount struct gains a new struct user_namespace member. The idmapping of the user namespace becomes the idmapping of the mount. A caller that is privileged with respect to the user namespace of the superblock of the underlying filesystem can create an idmapped mount. In the future, we can enable unprivileged use-cases by checking whether the caller is privileged wrt to the user namespace that an already idmapped mount has been marked with, allowing them to change the idmapping. For now, keep things simple until the need arises. Note, that with syscall interception it is already possible to intercept idmapped mount requests from unprivileged containers and handle them in a sufficiently privileged container manager. Support for this is already available in LXD and will be available in runC where syscall interception is currently in the process of becoming part of the runtime
spec: https://github.com/opencontainers/runtime-spec/pull/1074.
The user namespace the mount will be marked with can be specified by passing a file descriptor refering to the user namespace as an argument to the new mount_setattr() syscall together with the new MOUNT_ATTR_IDMAP flag. By default vfsmounts are marked with the initial user namespace and no behavioral or performance changes are observed. All mapping operations are nops for the initial user namespace. When a file/inode is accessed through an idmapped mount the i_uid and i_gid of the inode will be remapped according to the user namespace the mount has been marked with.
In order to support idmapped mounts, filesystems need to be changed and mark themselves with the FS_ALLOW_IDMAP flag in fs_flags. The initial version contains fat, ext4, and xfs including a list of examples. But patches for other filesystems are actively worked on and will be sent out separately. We are here to see this through and there are multiple people involved in converting filesystems. So filesystem developers are not left alone with this and are provided with a large testsuite to verify that their port is correct.
There is a simple tool available at
https://github.com/brauner/mount-idmapped that allows to create idmapped mounts so people can play with this patch series. Here are a few illustrations:
1. Create a simple idmapped mount of another user's home directory
u1001@f2-vm:/$ sudo ./mount-idmapped --map-mount b:1000:1001:1 /home/ubuntu/ /mnt u1001@f2-vm:/$ ls -al /home/ubuntu/ total 28 drwxr-xr-x 2 ubuntu ubuntu 4096 Oct 28 22:07 . drwxr-xr-x 4 root root 4096 Oct 28 04:00 .. -rw------- 1 ubuntu ubuntu 3154 Oct 28 22:12 .bash_history -rw-r--r-- 1 ubuntu ubuntu 220 Feb 25 2020 .bash_logout -rw-r--r-- 1 ubuntu ubuntu 3771 Feb 25 2020 .bashrc -rw-r--r-- 1 ubuntu ubuntu 807 Feb 25 2020 .profile -rw-r--r-- 1 ubuntu ubuntu 0 Oct 16 16:11 .sudo_as_admin_successful -rw------- 1 ubuntu ubuntu 1144 Oct 28 00:43 .viminfo u1001@f2-vm:/$ ls -al /mnt/ total 28 drwxr-xr-x 2 u1001 u1001 4096 Oct 28 22:07 . drwxr-xr-x 29 root root 4096 Oct 28 22:01 .. -rw------- 1 u1001 u1001 3154 Oct 28 22:12 .bash_history -rw-r--r-- 1 u1001 u1001 220 Feb 25 2020 .bash_logout -rw-r--r-- 1 u1001 u1001 3771 Feb 25 2020 .bashrc -rw-r--r-- 1 u1001 u1001 807 Feb 25 2020 .profile -rw-r--r-- 1 u1001 u1001 0 Oct 16 16:11 .sudo_as_admin_successful -rw------- 1 u1001 u1001 1144 Oct 28 00:43 .viminfo u1001@f2-vm:/$ touch /mnt/my-file u1001@f2-vm:/$ setfacl -m u:1001:rwx /mnt/my-file u1001@f2-vm:/$ sudo setcap -n 1001 cap_net_raw+ep /mnt/my-file u1001@f2-vm:/$ ls -al /mnt/my-file -rw-rwxr--+ 1 u1001 u1001 0 Oct 28 22:14 /mnt/my-file u1001@f2-vm:/$ ls -al /home/ubuntu/my-file -rw-rwxr--+ 1 ubuntu ubuntu 0 Oct 28 22:14 /home/ubuntu/my-file u1001@f2-vm:/$ getfacl /mnt/my-file getfacl: Removing leading '/' from absolute path names # file: mnt/my-file # owner: u1001 # group: u1001 user::rw- user:u1001:rwx group::rw- mask::rwx other::r-- u1001@f2-vm:/$ getfacl /home/ubuntu/my-file getfacl: Removing leading '/' from absolute path names # file: home/ubuntu/my-file # owner: ubuntu # group: ubuntu user::rw- user:ubuntu:rwx group::rw- mask::rwx other::r--
2. Create mapping of the whole ext4 rootfs without a mapping for uid and gid 0
ubuntu@f2-vm:~$ sudo /mount-idmapped --map-mount b:1:1:65536 / /mnt/ ubuntu@f2-vm:~$ findmnt | grep mnt └─/mnt /dev/sda2 ext4 rw,relatime └─/mnt/mnt /dev/sda2 ext4 rw,relatime ubuntu@f2-vm:~$ sudo mkdir /AS-ROOT-CAN-CREATE ubuntu@f2-vm:~$ sudo mkdir /mnt/AS-ROOT-CANT-CREATE mkdir: cannot create directory ‘/mnt/AS-ROOT-CANT-CREATE’: Value too large for defined data type ubuntu@f2-vm:~$ mkdir /mnt/home/ubuntu/AS-USER-1000-CAN-CREATE
3. Create a vfat usb mount and expose to user 1001 and 5000
ubuntu@f2-vm:/$ sudo mount /dev/sdb /mnt ubuntu@f2-vm:/$ findmnt | grep mnt └─/mnt /dev/sdb vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro ubuntu@f2-vm:/$ ls -al /mnt total 12 drwxr-xr-x 2 root root 4096 Jan 1 1970 . drwxr-xr-x 34 root root 4096 Oct 28 22:24 .. -rwxr-xr-x 1 root root 4 Oct 28 03:44 aaa -rwxr-xr-x 1 root root 0 Oct 28 01:09 bbb ubuntu@f2-vm:/$ sudo /mount-idmapped --map-mount b:0:1001:1 /mnt /mnt-1001/ ubuntu@f2-vm:/$ ls -al /mnt-1001/ total 12 drwxr-xr-x 2 u1001 u1001 4096 Jan 1 1970 . drwxr-xr-x 34 root root 4096 Oct 28 22:24 .. -rwxr-xr-x 1 u1001 u1001 4 Oct 28 03:44 aaa -rwxr-xr-x 1 u1001 u1001 0 Oct 28 01:09 bbb ubuntu@f2-vm:/$ sudo /mount-idmapped --map-mount b:0:5000:1 /mnt /mnt-5000/ ubuntu@f2-vm:/$ ls -al /mnt-5000/ total 12 drwxr-xr-x 2 5000 5000 4096 Jan 1 1970 . drwxr-xr-x 34 root root 4096 Oct 28 22:24 .. -rwxr-xr-x 1 5000 5000 4 Oct 28 03:44 aaa -rwxr-xr-x 1 5000 5000 0 Oct 28 01:09 bbb
4. Create an idmapped rootfs mount for a container
root@f2-vm:~# ls -al /var/lib/lxc/f2/rootfs/
total 68
drwxr-xr-x 17 20000 20000 4096 Sep 24 07:48 .
drwxrwx--- 3 20000 20000 4096 Oct 16 19:26 ..
lrwxrwxrwx 1 20000 20000 7 Sep 24 07:43 bin -> usr/bin
drwxr-xr-x 2 20000 20000 4096 Apr 15 2020 boot
drwxr-xr-x 3 20000 20000 4096 Oct 16 19:26 dev
drwxr-xr-x 61 20000 20000 4096 Oct 16 19:26 etc
drwxr-xr-x 3 20000 20000 4096 Sep 24 07:45 home
lrwxrwxrwx 1 20000 20000 7 Sep 24 07:43 lib -> usr/lib
lrwxrwxrwx 1 20000 20000 9 Sep 24 07:43 lib32 -> usr/lib32
lrwxrwxrwx 1 20000 20000 9 Sep 24 07:43 lib64 -> usr/lib64
lrwxrwxrwx 1 20000 20000 10 Sep 24 07:43 libx32 -> usr/libx32
drwxr-xr-x 2 20000 20000 4096 Sep 24 07:43 media
drwxr-xr-x 2 20000 20000 4096 Sep 24 07:43 mnt
drwxr-xr-x 2 20000 20000 4096 Sep 24 07:43 opt
drwxr-xr-x 2 20000 20000 4096 Apr 15 2020 proc
drwx------ 2 20000 20000 4096 Sep 24 07:43 root
drwxr-xr-x 2 20000 20000 4096 Sep 24 07:45 run
lrwxrwxrwx 1 20000 20000 8 Sep 24 07:43 sbin -> usr/sbin
drwxr-xr-x 2 20000 20000 4096 Sep 24 07:43 srv
drwxr-xr-x 2 20000 20000 4096 Apr 15 2020 sys
drwxrwxrwt 2 20000 20000 4096 Sep 24 07:44 tmp
drwxr-xr-x 13 20000 20000 4096 Sep 24 07:43 usr
drwxr-xr-x 12 20000 20000 4096 Sep 24 07:44 var
root@f2-vm:~# /mount-idmapped --map-mount b:20000:10000:100000 /var/lib/lxc/f2/rootfs/ /mnt
root@f2-vm:~# ls -al /mnt
total 68
drwxr-xr-x 17 10000 10000 4096 Sep 24 07:48 .
drwxr-xr-x 34 root root 4096 Oct 28 22:24 ..
lrwxrwxrwx 1 10000 10000 7 Sep 24 07:43 bin -> usr/bin
drwxr-xr-x 2 10000 10000 4096 Apr 15 2020 boot
drwxr-xr-x 3 10000 10000 4096 Oct 16 19:26 dev
drwxr-xr-x 61 10000 10000 4096 Oct 16 19:26 etc
drwxr-xr-x 3 10000 10000 4096 Sep 24 07:45 home
lrwxrwxrwx 1 10000 10000 7 Sep 24 07:43 lib -> usr/lib
lrwxrwxrwx 1 10000 10000 9 Sep 24 07:43 lib32 -> usr/lib32
lrwxrwxrwx 1 10000 10000 9 Sep 24 07:43 lib64 -> usr/lib64
lrwxrwxrwx 1 10000 10000 10 Sep 24 07:43 libx32 -> usr/libx32
drwxr-xr-x 2 10000 10000 4096 Sep 24 07:43 media
drwxr-xr-x 2 10000 10000 4096 Sep 24 07:43 mnt
drwxr-xr-x 2 10000 10000 4096 Sep 24 07:43 opt
drwxr-xr-x 2 10000 10000 4096 Apr 15 2020 proc
drwx------ 2 10000 10000 4096 Sep 24 07:43 root
drwxr-xr-x 2 10000 10000 4096 Sep 24 07:45 run
lrwxrwxrwx 1 10000 10000 8 Sep 24 07:43 sbin -> usr/sbin
drwxr-xr-x 2 10000 10000 4096 Sep 24 07:43 srv
drwxr-xr-x 2 10000 10000 4096 Apr 15 2020 sys
drwxrwxrwt 2 10000 10000 4096 Sep 24 07:44 tmp
drwxr-xr-x 13 10000 10000 4096 Sep 24 07:43 usr
drwxr-xr-x 12 10000 10000 4096 Sep 24 07:44 var
root@f2-vm:~# lxc-start f2 # uses /mnt as rootfs
root@f2-vm:~# lxc-attach f2 -- cat /proc/1/uid_map
0 10000 10000
root@f2-vm:~# lxc-attach f2 -- cat /proc/1/gid_map
0 10000 10000
root@f2-vm:~# lxc-attach f2 -- ls -al /
total 52
drwxr-xr-x 17 root root 4096 Sep 24 07:48 .
drwxr-xr-x 17 root root 4096 Sep 24 07:48 ..
lrwxrwxrwx 1 root root 7 Sep 24 07:43 bin -> usr/bin
drwxr-xr-x 2 root root 4096 Apr 15 2020 boot
drwxr-xr-x 5 root root 500 Oct 28 23:39 dev
drwxr-xr-x 61 root root 4096 Oct 28 23:39 etc
drwxr-xr-x 3 root root 4096 Sep 24 07:45 home
lrwxrwxrwx 1 root root 7 Sep 24 07:43 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Sep 24 07:43 lib32 -> usr/lib32
lrwxrwxrwx 1 root root 9 Sep 24 07:43 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 Sep 24 07:43 libx32 -> usr/libx32
drwxr-xr-x 2 root root 4096 Sep 24 07:43 media
drwxr-xr-x 2 root root 4096 Sep 24 07:43 mnt
drwxr-xr-x 2 root root 4096 Sep 24 07:43 opt
dr-xr-xr-x 232 nobody nogroup 0 Oct 28 23:39 proc
drwx------ 2 root root 4096 Oct 28 23:41 root
drwxr-xr-x 12 root root 360 Oct 28 23:39 run
lrwxrwxrwx 1 root root 8 Sep 24 07:43 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Sep 24 07:43 srv
dr-xr-xr-x 13 nobody nogroup 0 Oct 28 23:39 sys
drwxrwxrwt 11 root root 4096 Oct 28 23:40 tmp
drwxr-xr-x 13 root root 4096 Sep 24 07:43 usr
drwxr-xr-x 12 root root 4096 Sep 24 07:44 var
root@f2-vm:~# lxc-attach f2 -- ls -al /my-file
-rw-r--r-- 1 root root 0 Oct 28 23:43 /my-file
root@f2-vm:~# ls -al /var/lib/lxc/f2/rootfs/my-file
-rw-r--r-- 1 20000 20000 0 Oct 28 23:43 /var/lib/lxc/f2/rootfs/my-fileI'd like to say thanks to:
Al for pointing me into the direction to avoid inode alias issues during lookup. David for various discussions around this. Christoph for porting xfs, providing good reviews and for being involved in the original idea. Tycho for helping with this series and on future patches to convert filesystems. Alban Crequy and the Kinvolk peeps located just a few streets away from me in Berlin for providing use-case discussions and writing patches for containerd. Stéphane for his invaluable input on many things and level head and enabling me to work on this. Amir for explaining and discussing aspects of overlayfs with me. I'd like to especially thank Seth Forshee. He provided a lot of good analysis, suggestions, and participated in short-notice discussions in both chat and video for some nitty-gritty technical details.
This series can be found and pulled from the three usual locations:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/log/?h=idmapped_mounts
https://github.com/brauner/linux/tree/idmapped_mounts
https://gitlab.com/brauner/linux/-/commits/idmapped_mounts
/* v5 */
- Adress Christoph's feedback.
- Use v5.11-rc3 as new base.
- Add Christoph's xfs port.
/* v4 */
- Split out several preparatory patches from the initial mount_setattr patch as requested by Christoph.
- Add new tests for file/directory creation in directories with the setgid bit set. Specifically, verify that the setgid bit is correctly ignored when creating a file with the setgid bit and the parent directory's i_gid isn't in_group_p() and the caller isn't capable_wrt_inode_uidgid() over the parent directory's inode when inode_init_owner() is called.
Conversely, verify that the setgid bit is set when creating a file with the setgid bit and the parent's i_gid is either in_group_p() or the caller is capable_wrt_inode_uidgid() over the parent directory's inode. In additiona, verify that the setgid bit is always inherited when creating directories.
Test all of this on regular mounts, idmapped mounts, and on idmapped mounts in user namespaces.
- Add new tests to verify that the i_gid of newly created files or directories is correctly set to the parent directory's i_gid when the parent directory has the setgid bit set.
- Use "mnt_userns" as the de facto name for a vfsmount's user namespace everywhere as suggested by Serge.
- Reuse existing propagation flags instead of introducing new ones as suggested by Christoph. (This is in line with Linus request to not introduce too many new flags as evidenced by prior discussions on other patchsets such as openat2().)
- Add first set of Acked-bys from Serge and Reviewed-bys from Christoph.
- Fix commit messages to reflect the fact that we modify existing vfs helpers but do not introduce new ones like we did in the first version. Some commit messages still implied we were adding new helpers.
- Reformat all commit messages to adhere to 73 char length limit and wrap all lines in commits at 80 chars whenever this doesn't hinder legibility.
- Simplify various codepaths with Christoph's suggestions.
/* v3 */
- The major change is the port of the test-suite from the kernel-internal selftests framework to xfstests as requested by Darrick and Christoph. The test-suite for xfstests is patch 38 in this series. It has been kept as part of this series even though it belongs to xfstests so it's easier to see what is tested and to keep it in-sync.
- Note, the test-suite now has been extended to cover io_uring and idmapped mounts. The IORING_REGISTER_PERSONALITY feature allows to register the caller's credentials with io_uring and returns an id associated with these credentials. This is useful for applications that wish to share a ring between separate users/processes. Callers can pass in the credential id in the sqe personality field. If set, that particular sqe will be issued with these credentials. The test-suite now tests that the openat* operations with different registered credentials work correctly and safely on regular mounts, on regular mounts inside user namespaces, on idmapped mounts, and on idmapped mounts inside user namespaces.
/* v2 */
- The major change is the rework requested by Christoph and others to adapt all relevant helpers and inode_operations methods to account for idmapped mounts instead of introducing new helpers and methods specific to idmapped mounts like we did before. We've also moved the overlayfs conversion to handle idmapped mounts into a separate patchset that will be sent out separately after the core changes landed. The converted filesytems in this series include fat and ext4. As per Christoph's request the vfs-wide config option to disable idmapped mounts has been removed. Instead the filesystems can decide whether or not they want to allow idmap mounts through a config option. These config options default to off. Having a config option allows us to gain some confidence in the patchset over multiple kernel releases.
- This version introduces a large test-suite to test current vfs behavior and idmapped mounts behavior. This test-suite is intended to grow over time.
- While while working on adapting this patchset to the requested changes, the runC and containerd crowd was nice enough to adapt containerd to this patchset to make use of idmapped mounts in one of the most widely used container runtimes:
https://github.com/containerd/containerd/pull/4734
The solution proposed here has it's origins in multiple discussions during Linux Plumbers 2017 during and after the end of the containers microconference.
To the best of my knowledge this involved Aleksa, Stéphane, Eric, David, James, and myself.The original idea or a variant thereof has been discussed, again to the best of my knowledge, after a Linux conference in St. Petersburg in Russia in 2017 between Christoph, Tycho, and myself.
We've taken the time to implement a working version of this solution over the last weeks to the best of my abilities. Tycho has signed up for this sligthly crazy endeavour as well and he has helped with the conversion of the xattr codepaths and will be involved with others in converting additional filesystems.
Thanks!
Christian
Christian Brauner (37):
mount: attach mappings to mounts
fs: add id translation helpers
fs: add file and path permissions helpers
capability: handle idmapped mounts
namei: make permission helpers idmapped mount aware
inode: make init and permission helpers idmapped mount aware
attr: handle idmapped mounts
acl: handle idmapped mounts
commoncap: handle idmapped mounts
stat: handle idmapped mounts
namei: handle idmapped mounts in may_*() helpers
namei: introduce struct renamedata
namei: prepare for idmapped mounts
open: handle idmapped mounts in do_truncate()
open: handle idmapped mounts
af_unix: handle idmapped mounts
utimes: handle idmapped mounts
fcntl: handle idmapped mounts
init: handle idmapped mounts
ioctl: handle idmapped mounts
would_dump: handle idmapped mounts
exec: handle idmapped mounts
fs: make helpers idmap mount aware
apparmor: handle idmapped mounts
ima: handle idmapped mounts
ecryptfs: do not mount on top of idmapped mounts
overlayfs: do not mount on top of idmapped mounts
namespace: take lock_mount_hash() directly when changing flags
mount: make {lock,unlock}_mount_hash() static
namespace: only take read lock in do_reconfigure_mnt()
fs: split out functions to hold writers
fs: add attr_flags_to_mnt_flags helper
fs: add mount_setattr()
fs: introduce MOUNT_ATTR_IDMAP
tests: add mount_setattr() selftests
fat: handle idmapped mounts
ext4: support idmapped mounts
Christoph Hellwig (1):
xfs: support idmapped mounts
Tycho Andersen (1):
xattr: handle idmapped mounts
Documentation/filesystems/locking.rst | 7 +- Documentation/filesystems/porting.rst | 2 + Documentation/filesystems/vfs.rst | 19 +- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/platforms/cell/spufs/inode.c | 5 +- arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + drivers/android/binderfs.c | 6 +- drivers/base/devtmpfs.c | 15 +- fs/9p/acl.c | 8 +- fs/9p/v9fs.h | 3 +- fs/9p/v9fs_vfs.h | 3 +- fs/9p/vfs_inode.c | 36 +- fs/9p/vfs_inode_dotl.c | 39 +- fs/9p/xattr.c | 1 + fs/adfs/adfs.h | 3 +- fs/adfs/inode.c | 5 +- fs/affs/affs.h | 24 +- fs/affs/inode.c | 7 +- fs/affs/namei.c | 15 +- fs/afs/dir.c | 34 +- fs/afs/inode.c | 9 +- fs/afs/internal.h | 7 +- fs/afs/security.c | 3 +- fs/afs/xattr.c | 2 + fs/attr.c | 126 +- fs/autofs/root.c | 17 +- fs/bad_inode.c | 36 +- fs/bfs/dir.c | 12 +- fs/btrfs/acl.c | 6 +- fs/btrfs/ctree.h | 3 +- fs/btrfs/inode.c | 46 +- fs/btrfs/ioctl.c | 27 +- fs/btrfs/tests/btrfs-tests.c | 2 +- fs/btrfs/xattr.c | 2 + fs/cachefiles/interface.c | 4 +- fs/cachefiles/namei.c | 21 +- fs/cachefiles/xattr.c | 29 +- fs/ceph/acl.c | 6 +- fs/ceph/dir.c | 23 +- fs/ceph/inode.c | 18 +- fs/ceph/super.h | 12 +- fs/ceph/xattr.c | 1 + fs/cifs/cifsfs.c | 5 +- fs/cifs/cifsfs.h | 25 +- fs/cifs/dir.c | 8 +- fs/cifs/inode.c | 26 +- fs/cifs/link.c | 3 +- fs/cifs/xattr.c | 1 + fs/coda/coda_linux.h | 8 +- fs/coda/dir.c | 18 +- fs/coda/inode.c | 9 +- fs/coda/pioctl.c | 6 +- fs/configfs/configfs_internal.h | 6 +- fs/configfs/dir.c | 3 +- fs/configfs/inode.c | 5 +- fs/configfs/symlink.c | 6 +- fs/coredump.c | 10 +- fs/crypto/policy.c | 2 +- fs/debugfs/inode.c | 9 +- fs/ecryptfs/crypto.c | 4 +- fs/ecryptfs/inode.c | 85 +- fs/ecryptfs/main.c | 6 + fs/ecryptfs/mmap.c | 4 +- fs/efivarfs/file.c | 2 +- fs/efivarfs/inode.c | 4 +- fs/erofs/inode.c | 7 +- fs/erofs/internal.h | 5 +- fs/exec.c | 12 +- fs/exfat/exfat_fs.h | 8 +- fs/exfat/file.c | 14 +- fs/exfat/namei.c | 14 +- fs/ext2/acl.c | 6 +- fs/ext2/acl.h | 3 +- fs/ext2/ext2.h | 5 +- fs/ext2/ialloc.c | 2 +- fs/ext2/inode.c | 15 +- fs/ext2/ioctl.c | 6 +- fs/ext2/namei.c | 22 +- fs/ext2/xattr_security.c | 1 + fs/ext2/xattr_trusted.c | 1 + fs/ext2/xattr_user.c | 1 + fs/ext4/acl.c | 5 +- fs/ext4/acl.h | 3 +- fs/ext4/ext4.h | 22 +- fs/ext4/ialloc.c | 7 +- fs/ext4/inode.c | 21 +- fs/ext4/ioctl.c | 20 +- fs/ext4/namei.c | 49 +- fs/ext4/super.c | 2 +- fs/ext4/xattr_hurd.c | 1 + fs/ext4/xattr_security.c | 1 + fs/ext4/xattr_trusted.c | 1 + fs/ext4/xattr_user.c | 1 + fs/f2fs/acl.c | 6 +- fs/f2fs/acl.h | 3 +- fs/f2fs/f2fs.h | 7 +- fs/f2fs/file.c | 36 +- fs/f2fs/namei.c | 23 +- fs/f2fs/xattr.c | 4 +- fs/fat/fat.h | 6 +- fs/fat/file.c | 24 +- fs/fat/namei_msdos.c | 12 +- fs/fat/namei_vfat.c | 15 +- fs/fcntl.c | 3 +- fs/fuse/acl.c | 3 +- fs/fuse/dir.c | 46 +- fs/fuse/fuse_i.h | 4 +- fs/fuse/xattr.c | 2 + fs/gfs2/acl.c | 5 +- fs/gfs2/acl.h | 3 +- fs/gfs2/file.c | 4 +- fs/gfs2/inode.c | 64 +- fs/gfs2/inode.h | 3 +- fs/gfs2/xattr.c | 1 + fs/hfs/attr.c | 1 + fs/hfs/dir.c | 13 +- fs/hfs/hfs_fs.h | 3 +- fs/hfs/inode.c | 8 +- fs/hfsplus/dir.c | 22 +- fs/hfsplus/hfsplus_fs.h | 5 +- fs/hfsplus/inode.c | 16 +- fs/hfsplus/ioctl.c | 2 +- fs/hfsplus/xattr.c | 1 + fs/hfsplus/xattr_security.c | 1 + fs/hfsplus/xattr_trusted.c | 1 + fs/hfsplus/xattr_user.c | 1 + fs/hostfs/hostfs_kern.c | 29 +- fs/hpfs/hpfs_fn.h | 2 +- fs/hpfs/inode.c | 7 +- fs/hpfs/namei.c | 20 +- fs/hugetlbfs/inode.c | 35 +- fs/init.c | 24 +- fs/inode.c | 44 +- fs/internal.h | 2 +- fs/jffs2/acl.c | 6 +- fs/jffs2/acl.h | 3 +- fs/jffs2/dir.c | 33 +- fs/jffs2/fs.c | 7 +- fs/jffs2/os-linux.h | 2 +- fs/jffs2/security.c | 1 + fs/jffs2/xattr_trusted.c | 1 + fs/jffs2/xattr_user.c | 1 + fs/jfs/acl.c | 5 +- fs/jfs/file.c | 9 +- fs/jfs/ioctl.c | 2 +- fs/jfs/jfs_acl.h | 3 +- fs/jfs/jfs_inode.c | 2 +- fs/jfs/jfs_inode.h | 2 +- fs/jfs/namei.c | 21 +- fs/jfs/xattr.c | 2 + fs/kernfs/dir.c | 6 +- fs/kernfs/inode.c | 19 +- fs/kernfs/kernfs-internal.h | 9 +- fs/libfs.c | 28 +- fs/minix/bitmap.c | 2 +- fs/minix/file.c | 7 +- fs/minix/inode.c | 6 +- fs/minix/minix.h | 3 +- fs/minix/namei.c | 24 +- fs/mount.h | 10 - fs/namei.c | 512 ++++-- fs/namespace.c | 480 +++++- fs/nfs/dir.c | 25 +- fs/nfs/inode.c | 9 +- fs/nfs/internal.h | 14 +- fs/nfs/namespace.c | 15 +- fs/nfs/nfs3_fs.h | 3 +- fs/nfs/nfs3acl.c | 3 +- fs/nfs/nfs4proc.c | 3 + fs/nfsd/nfs2acl.c | 6 +- fs/nfsd/nfs3acl.c | 6 +- fs/nfsd/nfs4acl.c | 5 +- fs/nfsd/nfs4recover.c | 6 +- fs/nfsd/nfsfh.c | 3 +- fs/nfsd/nfsproc.c | 2 +- fs/nfsd/vfs.c | 50 +- fs/nilfs2/inode.c | 14 +- fs/nilfs2/ioctl.c | 2 +- fs/nilfs2/namei.c | 19 +- fs/nilfs2/nilfs.h | 6 +- fs/notify/fanotify/fanotify_user.c | 2 +- fs/notify/inotify/inotify_user.c | 2 +- fs/ntfs/inode.c | 6 +- fs/ntfs/inode.h | 3 +- fs/ocfs2/acl.c | 6 +- fs/ocfs2/acl.h | 3 +- fs/ocfs2/dlmfs/dlmfs.c | 17 +- fs/ocfs2/file.c | 18 +- fs/ocfs2/file.h | 11 +- fs/ocfs2/ioctl.c | 2 +- fs/ocfs2/namei.c | 21 +- fs/ocfs2/refcounttree.c | 4 +- fs/ocfs2/xattr.c | 3 + fs/omfs/dir.c | 13 +- fs/omfs/file.c | 7 +- fs/omfs/inode.c | 2 +- fs/open.c | 35 +- fs/orangefs/acl.c | 6 +- fs/orangefs/inode.c | 20 +- fs/orangefs/namei.c | 12 +- fs/orangefs/orangefs-kernel.h | 13 +- fs/orangefs/xattr.c | 1 + fs/overlayfs/copy_up.c | 22 +- fs/overlayfs/dir.c | 31 +- fs/overlayfs/file.c | 6 +- fs/overlayfs/inode.c | 27 +- fs/overlayfs/overlayfs.h | 45 +- fs/overlayfs/super.c | 21 +- fs/overlayfs/util.c | 4 +- fs/posix_acl.c | 103 +- fs/proc/base.c | 28 +- fs/proc/fd.c | 5 +- fs/proc/fd.h | 3 +- fs/proc/generic.c | 12 +- fs/proc/internal.h | 6 +- fs/proc/proc_net.c | 5 +- fs/proc/proc_sysctl.c | 15 +- fs/proc/root.c | 5 +- fs/proc_namespace.c | 3 + fs/ramfs/file-nommu.c | 9 +- fs/ramfs/inode.c | 18 +- fs/reiserfs/acl.h | 3 +- fs/reiserfs/inode.c | 7 +- fs/reiserfs/ioctl.c | 4 +- fs/reiserfs/namei.c | 21 +- fs/reiserfs/reiserfs.h | 3 +- fs/reiserfs/xattr.c | 13 +- fs/reiserfs/xattr.h | 3 +- fs/reiserfs/xattr_acl.c | 8 +- fs/reiserfs/xattr_security.c | 3 +- fs/reiserfs/xattr_trusted.c | 3 +- fs/reiserfs/xattr_user.c | 3 +- fs/remap_range.c | 7 +- fs/stat.c | 26 +- fs/sysv/file.c | 7 +- fs/sysv/ialloc.c | 2 +- fs/sysv/itree.c | 6 +- fs/sysv/namei.c | 21 +- fs/sysv/sysv.h | 3 +- fs/tracefs/inode.c | 4 +- fs/ubifs/dir.c | 30 +- fs/ubifs/file.c | 5 +- fs/ubifs/ioctl.c | 2 +- fs/ubifs/ubifs.h | 5 +- fs/ubifs/xattr.c | 1 + fs/udf/file.c | 9 +- fs/udf/ialloc.c | 2 +- fs/udf/namei.c | 24 +- fs/udf/symlink.c | 7 +- fs/ufs/ialloc.c | 2 +- fs/ufs/inode.c | 7 +- fs/ufs/namei.c | 19 +- fs/ufs/ufs.h | 3 +- fs/utimes.c | 3 +- fs/vboxsf/dir.c | 12 +- fs/vboxsf/utils.c | 9 +- fs/vboxsf/vfsmod.h | 8 +- fs/verity/enable.c | 2 +- fs/xattr.c | 139 +- fs/xfs/xfs_acl.c | 5 +- fs/xfs/xfs_acl.h | 3 +- fs/xfs/xfs_file.c | 4 +- fs/xfs/xfs_inode.c | 26 +- fs/xfs/xfs_inode.h | 16 +- fs/xfs/xfs_ioctl.c | 35 +- fs/xfs/xfs_ioctl32.c | 6 +- fs/xfs/xfs_iops.c | 101 +- fs/xfs/xfs_iops.h | 3 +- fs/xfs/xfs_itable.c | 17 +- fs/xfs/xfs_itable.h | 1 + fs/xfs/xfs_qm.c | 3 +- fs/xfs/xfs_super.c | 2 +- fs/xfs/xfs_symlink.c | 5 +- fs/xfs/xfs_symlink.h | 5 +- fs/xfs/xfs_xattr.c | 7 +- fs/zonefs/super.c | 9 +- include/linux/capability.h | 14 +- include/linux/fs.h | 186 ++- include/linux/ima.h | 18 +- include/linux/lsm_hook_defs.h | 15 +- include/linux/lsm_hooks.h | 1 + include/linux/mount.h | 7 + include/linux/nfs_fs.h | 7 +- include/linux/posix_acl.h | 21 +- include/linux/posix_acl_xattr.h | 12 +- include/linux/security.h | 54 +- include/linux/syscalls.h | 4 + include/linux/xattr.h | 30 +- include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/mount.h | 16 + ipc/mqueue.c | 9 +- kernel/auditsc.c | 5 +- kernel/bpf/inode.c | 13 +- kernel/capability.c | 14 +- kernel/cgroup/cgroup.c | 2 +- kernel/sys.c | 2 +- mm/madvise.c | 5 +- mm/memcontrol.c | 2 +- mm/mincore.c | 5 +- mm/shmem.c | 50 +- net/socket.c | 6 +- net/unix/af_unix.c | 5 +- security/apparmor/apparmorfs.c | 3 +- security/apparmor/domain.c | 13 +- security/apparmor/file.c | 4 +- security/apparmor/lsm.c | 21 +- security/commoncap.c | 108 +- security/integrity/evm/evm_crypto.c | 11 +- security/integrity/evm/evm_main.c | 4 +- security/integrity/evm/evm_secfs.c | 2 +- security/integrity/ima/ima.h | 19 +- security/integrity/ima/ima_api.c | 10 +- security/integrity/ima/ima_appraise.c | 23 +- security/integrity/ima/ima_asymmetric_keys.c | 3 +- security/integrity/ima/ima_main.c | 37 +- security/integrity/ima/ima_policy.c | 20 +- security/integrity/ima/ima_queue_keys.c | 4 +- security/security.c | 25 +- security/selinux/hooks.c | 23 +- security/smack/smack_lsm.c | 22 +- tools/include/uapi/asm-generic/unistd.h | 4 +- tools/testing/selftests/Makefile | 1 + .../selftests/mount_setattr/.gitignore | 1 + .../testing/selftests/mount_setattr/Makefile | 7 + tools/testing/selftests/mount_setattr/config | 1 + .../mount_setattr/mount_setattr_test.c | 1424 +++++++++++++++++ 342 files changed, 4888 insertions(+), 1750 deletions(-) create mode 100644 tools/testing/selftests/mount_setattr/.gitignore create mode 100644 tools/testing/selftests/mount_setattr/Makefile create mode 100644 tools/testing/selftests/mount_setattr/config create mode 100644 tools/testing/selftests/mount_setattr/mount_setattr_test.c
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
Signature · 7 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 1/40 mount: attach mappings to mounts
In order to support per-mount idmappings vfsmounts are marked with user namespaces. The idmapping of the user namespace will be used to map the ids of vfs objects when they are accessed through that mount. By default all vfsmounts are marked with the initial user namespace. The initial user namespace is used to indicate that a mount is not idmapped. All operations behave as before.
Based on prior discussions we want to attach the whole user namespace and not just a dedicated idmapping struct. This allows us to reuse all the helpers that already exist for dealing with idmappings instead of introducing a whole new range of helpers. In addition, if we decide in the future that we are confident enough to enable unprivileged users to setup idmapped mounts the permission checking can take into account whether the caller is privileged in the user namespace the mount is currently marked with.
Later patches enforce that once a mount has been idmapped it can't be remapped. This keeps permission checking and life-cycle management simple. Users wanting to change the idmapped can always create a new detached mount with a different idmapping.
Add a new mnt_userns member to vfsmount and two simple helpers to retrieve the mnt_userns from vfsmounts and files.
The idea to attach user namespaces to vfsmounts has been floated around in various forms at Linux Plumbers in ~2018 with the original idea tracing back to a discussion in 2017 at a conference in St. Petersburg between Christoph, Tycho, and myself.
---
/* v2 */
patch introduced
- Christoph Hellwig <[email protected]>:
- Split internal implementation into separate patch and move syscall implementation later.
/* v3 */
- David Howells <[email protected]>:
- Remove MNT_IDMAPPED flag. We can simply check the pointer and use smp_load_acquire() in later patches.
- Tycho Andersen <[email protected]>:
- Use READ_ONCE() in mnt_user_ns().
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
- Christoph Hellwig <[email protected]>:
- Drop the READ_ONCE() from this patch. At this point in the series we don't allowing changing the vfsmount's userns. The infra to do that is only introduced as almost the last patch in the series and there we immediately use smp_load_acquire() and smp_store_release().
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Move file_mnt_user_ns() helper into this patch.
--- fs/namespace.c | 9 +++++++++ include/linux/fs.h | 6 ++++++ include/linux/mount.h | 6 ++++++ 3 files changed, 21 insertions(+)
fs/namespace.c +9 -0
@@ -210,6 +210,7 @@ static struct mount *alloc_vfsmnt(const char *name)INIT_HLIST_NODE (&mnt->mnt_mp_list);INIT_LIST_HEAD (&mnt->mnt_umounting);INIT_HLIST_HEAD (&mnt->mnt_stuck_children); + mnt->mnt.mnt_userns = &init_user_ns; }return mnt;
@@ -547,6 +548,11 @@ int sb_prepare_remount_readonly(struct super_block *sb)static void free_vfsmnt (struct mount *mnt) { +struct user_namespace *mnt_userns; + + mnt_userns =mnt_user_ns (&mnt->mnt); +if (mnt_userns != &init_user_ns) +put_user_ns (mnt_userns);kfree_const (mnt->mnt_devname);#ifdef CONFIG_SMP free_percpu (mnt->mnt_pcp);
@@ -1055,6 +1061,9 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root, mnt->mnt.mnt_flags &= ~(MNT_WRITE_HOLD |MNT_MARKED |MNT_INTERNAL );atomic_inc (&sb->s_active); + mnt->mnt.mnt_userns =mnt_user_ns (&old->mnt); +if (mnt->mnt.mnt_userns != &init_user_ns) + mnt->mnt.mnt_userns =get_user_ns (mnt->mnt.mnt_userns); mnt->mnt.mnt_sb = sb; mnt->mnt.mnt_root =dget (root); mnt->mnt_mountpoint = mnt->mnt.mnt_root;
include/linux/fs.h +6 -0
@@ -39,6 +39,7 @@#include <linux/fs_types.h> #include <linux/build_bug.h> #include <linux/stddef.h> +#include <linux/mount.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h>
@@ -2231,6 +2232,7 @@ struct file_system_type {#define FS_HAS_SUBTYPE 4#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ #define FS_DISALLOW_NOTIFY_PERM 16/* Disable fanotify permission events */ +#define FS_ALLOW_IDMAP 32/* FS has been updated to handle vfs idmappings. */ #define FS_THP_SUPPORT 8192/* Remove once all fs converted */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ int (*init_fs_context)(struct fs_context *);
@@ -2517,6 +2519,10 @@ struct filename { };static_assert (offsetof(struct filename , iname) %sizeof (long ) ==0 ); +static inline struct user_namespace *file_mnt_user_ns (struct file *file) +{ +return mnt_user_ns (file->f_path.mnt); +}extern long vfs_truncate (const struct path *,loff_t );extern int do_truncate (struct dentry *,loff_t start,unsigned int time_attrs,struct file *filp);
include/linux/mount.h +6 -0
@@ -72,8 +72,14 @@ struct vfsmount {struct dentry *mnt_root;/* root of the mounted tree */ struct super_block *mnt_sb;/* pointer to superblock */ int mnt_flags; +struct user_namespace *mnt_userns; } __randomize_layout; +static inline struct user_namespace *mnt_user_ns (const struct vfsmount *mnt) +{ +return mnt->mnt_userns; +} +struct file ;/* forward dec */ struct path ;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 2/40 fs: add id translation helpers
In reply to Christian BraunerAdd simple helpers to make it easy to map kuids into and from idmapped mounts. We provide simple wrappers that filesystems can use to e.g. initialize inodes similar to i_{uid,gid}_read() and i_{uid,gid}_write(). Accessing an inode through an idmapped mount maps the i_uid and i_gid of the inode to the mount's user namespace. If the fsids are used to initialize inodes they are unmapped according to the mount's user namespace. Passing the initial user namespace to these helpers makes them a nop and so any non-idmapped paths will not be impacted.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Get rid of the ifdefs and the config option that hid idmapped mounts.
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- include/linux/fs.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
include/linux/fs.h +47 -0
@@ -40,6 +40,7 @@#include <linux/build_bug.h> #include <linux/stddef.h> #include <linux/mount.h> +#include <linux/cred.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h>
@@ -1573,6 +1574,52 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid =make_kgid (inode->i_sb->s_user_ns, gid); } +static inline kuid_t kuid_into_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return make_kuid (mnt_userns,__kuid_val (kuid)); +} + +static inline kgid_t kgid_into_mnt (struct user_namespace *mnt_userns, +kgid_t kgid) +{ +return make_kgid (mnt_userns,__kgid_val (kgid)); +} + +static inline kuid_t i_uid_into_mnt (struct user_namespace *mnt_userns, +const struct inode *inode) +{ +return kuid_into_mnt (mnt_userns, inode->i_uid); +} + +static inline kgid_t i_gid_into_mnt (struct user_namespace *mnt_userns, +const struct inode *inode) +{ +return kgid_into_mnt (mnt_userns, inode->i_gid); +} + +static inline kuid_t kuid_from_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return KUIDT_INIT (from_kuid (mnt_userns, kuid)); +} + +static inline kgid_t kgid_from_mnt (struct user_namespace *mnt_userns, +kgid_t kgid) +{ +return KGIDT_INIT (from_kgid (mnt_userns, kgid)); +} + +static inline kuid_t fsuid_into_mnt (struct user_namespace *mnt_userns) +{ +return kuid_from_mnt (mnt_userns,current_fsuid ()); +} + +static inline kgid_t fsgid_into_mnt (struct user_namespace *mnt_userns) +{ +return kgid_from_mnt (mnt_userns,current_fsgid ()); +} +extern struct timespec64 current_time (struct inode *inode);/*
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 02/40] fs: add id translation helpers
Quoted 52 lines · Christian Brauner
Add simple helpers to make it easy to map kuids into and from idmapped mounts. We provide simple wrappers that filesystems can use to e.g. initialize inodes similar to i_{uid,gid}_read() and i_{uid,gid}_write(). Accessing an inode through an idmapped mount maps the
i_uidandi_gidof the inode to the mount's user namespace. If the fsids are used to initialize inodes they are unmapped according to the mount's user namespace. Passing the initial user namespace to these helpers makes them a nop and so any non-idmapped paths will not be impacted.Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Get rid of the ifdefs and the config option that hid idmapped mounts./* v3 */
unchanged/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent./* v5 */
unchanged
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
unchanged
base-commit:19c329f6808995b142b3966301f217c831e7cf31--- include/linux/fs.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)include/linux/fs.h +1
-0@@ -40,6 +40,7 @@#include <linux/build_bug.h> #include <linux/stddef.h> #include <linux/mount.h> +#include <linux/cred.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h>
include/linux/fs.h static inline void i_gid_write(struct inode *inode, gid_t gid) · line 1582
Quoted 9 lines
include/linux/fs.h +6
-0@@ -1573,6 +1574,52 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid =make_kgid (inode->i_sb->s_user_ns, gid); } +static inline kuid_t kuid_into_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return make_kuid (mnt_userns,__kuid_val (kuid)); +} +
Hi Christian,
I am having little trouble w.r.t function names and trying to figure out whether they are mapping id down or up.
For example, kuid_into_mnt() ultimately calls map_id_down(). That is, id visible inside user namespace is mapped to host
(if observer is in init_user_ns, IIUC).
But fsuid_into_mnt() ultimately calls map_id_up(). That's take a kuid and map it into the user_namespace.
So both the helpers end with into_mnt() but one maps id down and other maps id up. I found this confusing and was wondering how should I visualize it. So thought of asking you.
Is this intentional or can naming be improved so that *_into_mnt() means one thing (Either map_id_up() or map_id_down()). And vice-a-versa for *_from_mnt().
Thanks
Vivek
Quoted 46 lines
include/linux/fs.h +40
-0+static inline kgid_t kgid_into_mnt (struct user_namespace *mnt_userns, +kgid_t kgid) +{ +return make_kgid (mnt_userns,__kgid_val (kgid)); +} + +static inline kuid_t i_uid_into_mnt (struct user_namespace *mnt_userns, +const struct inode *inode) +{ +return kuid_into_mnt (mnt_userns, inode->i_uid); +} + +static inline kgid_t i_gid_into_mnt (struct user_namespace *mnt_userns, +const struct inode *inode) +{ +return kgid_into_mnt (mnt_userns, inode->i_gid); +} + +static inline kuid_t kuid_from_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return KUIDT_INIT (from_kuid (mnt_userns, kuid)); +} + +static inline kgid_t kgid_from_mnt (struct user_namespace *mnt_userns, +kgid_t kgid) +{ +return KGIDT_INIT (from_kgid (mnt_userns, kgid)); +} + +static inline kuid_t fsuid_into_mnt (struct user_namespace *mnt_userns) +{ +return kuid_from_mnt (mnt_userns,current_fsuid ()); +} + +static inline kgid_t fsgid_into_mnt (struct user_namespace *mnt_userns) +{ +return kgid_from_mnt (mnt_userns,current_fsgid ()); +} +extern struct timespec64 current_time (struct inode *inode);/* Signature · 1 line
2.30.0
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 02/40] fs: add id translation helpers
Quoted 75 lines · Vivek Goyal
Quoted 52 lines · Christian Brauner
Add simple helpers to make it easy to map kuids into and from idmapped mounts. We provide simple wrappers that filesystems can use to e.g. initialize inodes similar to i_{uid,gid}_read() and i_{uid,gid}_write(). Accessing an inode through an idmapped mount maps the
i_uidandi_gidof the inode to the mount's user namespace. If the fsids are used to initialize inodes they are unmapped according to the mount's user namespace. Passing the initial user namespace to these helpers makes them a nop and so any non-idmapped paths will not be impacted.Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Get rid of the ifdefs and the config option that hid idmapped mounts./* v3 */
unchanged/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent./* v5 */
unchanged
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
unchanged
base-commit:19c329f6808995b142b3966301f217c831e7cf31--- include/linux/fs.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)include/linux/fs.h +1
-0@@ -40,6 +40,7 @@#include <linux/build_bug.h> #include <linux/stddef.h> #include <linux/mount.h> +#include <linux/cred.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h> include/linux/fs.h static inline void i_gid_write(struct inode *inode, gid_t gid) · line 1582
Quoted 9 lines
include/linux/fs.h +6
-0@@ -1573,6 +1574,52 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid =make_kgid (inode->i_sb->s_user_ns, gid); } +static inline kuid_t kuid_into_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return make_kuid (mnt_userns,__kuid_val (kuid)); +} +Hi Christian,
I am having little trouble w.r.t function names and trying to figure out whether they are mapping id down or up.
For example,
kuid_into_mnt()ultimately callsmap_id_down(). That is, id visible inside user namespace is mapped to host
(if observer is ininit_user_ns, IIUC).But
fsuid_into_mnt()ultimately callsmap_id_up(). That's take a kuid and map it into theuser_namespace.
Quoted 7 lines
So both the helpers end with
into_mnt()but one maps id down and other maps id up. I found this confusing and was wondering how should I visualize it. So thought of asking you.Is this intentional or can naming be improved so that
*_into_mnt()means one thing (Eithermap_id_up()ormap_id_down()). And vice-a-versa for*_from_mnt().
[Trimming my crazy Cc list to not spam everyone.].
Hey Vivek,
Thank you for your feedback, really appreciated!
The naming was intended to always signify that the helpers always return a k{u,g}id but I can certainly see how the naming isn't as clear as it should be for those helpers in other ways. I would suggest we remove such direct exposures of these helpers completely and make it simpler for callers by introducing very straightforward helpers. See the tiny patches below (only compile tested for now):
From 1bab0249295d0cad359f39a38e6171bcd2d68a60 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sat, 13 Mar 2021 15:08:04 +0100
Subject: [PATCH 1/2] fs: introduce fsuidgid_has_mapping() helper
Don't open-code the checks and instead move them into a clean little helper we can call. This also reduces the risk that if we ever changing something here we forget to change all locations.
--- fs/namei.c | 11 +++-------- include/linux/fs.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)
fs/namei.c +3 -8
@@ -2823,16 +2823,14 @@ static int may_delete(struct user_namespace *mnt_userns, struct inode *dir,static inline int may_create (struct user_namespace *mnt_userns,struct inode *dir,struct dentry *child) { -struct user_namespace *s_user_ns;audit_inode_child (dir, child,AUDIT_TYPE_CHILD_CREATE );if (child->d_inode)return -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; - s_user_ns = dir->i_sb->s_user_ns; -if (!kuid_has_mapping (s_user_ns,fsuid_into_mnt (mnt_userns)) || - !kgid_has_mapping (s_user_ns,fsgid_into_mnt (mnt_userns))) +if (!fsuidgid_has_mapping (dir->i_sb, mnt_userns))return -EOVERFLOW ; +return inode_permission (mnt_userns, dir,MAY_WRITE |MAY_EXEC ); }
@@ -3034,14 +3032,11 @@ static int may_o_create(struct user_namespace *mnt_userns, const struct path *dir, struct dentry *dentry, umode_t mode) { - struct user_namespace *s_user_ns; int error = security_path_mknod(dir, dentry, mode, 0);if (error)return error; - s_user_ns = dir->dentry->d_sb->s_user_ns; -if (!kuid_has_mapping (s_user_ns,fsuid_into_mnt (mnt_userns)) || - !kgid_has_mapping (s_user_ns,fsgid_into_mnt (mnt_userns))) +if (!fsuidgid_has_mapping (dir->dentry->d_sb, mnt_userns))return -EOVERFLOW ; error = inode_permission(mnt_userns, dir->dentry->d_inode,
include/linux/fs.h +13 -0
@@ -1620,6 +1620,19 @@ static inline kgid_t fsgid_into_mnt(struct user_namespace *mnt_userns)return kgid_from_mnt (mnt_userns,current_fsgid ()); } +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; +if (!kuid_has_mapping (s_user_ns, +kuid_from_mnt (mnt_userns,current_fsuid ()))) +return false; +if (!kgid_has_mapping (s_user_ns, +kgid_from_mnt (mnt_userns,current_fsgid ()))) +return false; +return true; +} +extern struct timespec64 current_time (struct inode *inode);/*
Signature · 25 lines
2.27.0 From 2f316f7de3ac96ecc8cc889724c0132e96b47b51 Mon Sep 17 00:00:00 2001 From: Christian Brauner <[email protected]> Date: Sat, 13 Mar 2021 15:11:55 +0100 Subject: [PATCH 2/2] fs: introduce two little fs{u,g}id inode initialization helpers As Vivek pointed out we could tweak the names of the fs{u,g}id helpers. That's already good but the better approach is to not expose them in this way to filesystems at all and simply give the filesystems two helpers inode_fsuid_set() and inode_fsgid_set() that will do the right thing. Inspired-by: Vivek Goyal <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Christian Brauner <[email protected]> --- fs/ext4/ialloc.c | 2 +- fs/inode.c | 4 ++-- fs/xfs/xfs_inode.c | 2 +- include/linux/fs.h | 10 ++++++---- 4 files changed, 10 insertions(+), 8 deletions(-)
fs/ext4/ialloc.c +1 -1
@@ -970,7 +970,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,i_gid_write (inode, owner[1 ]); }else if (test_opt (sb,GRPID )) { inode->i_mode = mode; - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns); inode->i_gid = dir->i_gid; }else inode_init_owner (mnt_userns, inode, dir, mode);
fs/inode.c +2 -2
@@ -2148,7 +2148,7 @@ EXPORT_SYMBOL(init_special_inode);void inode_init_owner (struct user_namespace *mnt_userns,struct inode *inode,const struct inode *dir,umode_t mode) { - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns);if (dir && dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;
@@ -2160,7 +2160,7 @@ void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode, !capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID)) mode &= ~S_ISGID ; }else - inode->i_gid =fsgid_into_mnt (mnt_userns); +inode_fsgid_set (inode, mnt_userns); inode->i_mode = mode; }EXPORT_SYMBOL (inode_init_owner);
fs/xfs/xfs_inode.c +1 -1
@@ -812,7 +812,7 @@ xfs_init_new_inode(if (dir && !(dir->i_mode &S_ISGID ) && (mp->m_flags &XFS_MOUNT_GRPID )) { - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns); inode->i_gid = dir->i_gid; inode->i_mode = mode; }else {
include/linux/fs.h +6 -4
@@ -1610,14 +1610,16 @@ static inline kgid_t kgid_from_mnt(struct user_namespace *mnt_userns,return KGIDT_INIT (from_kgid (mnt_userns, kgid)); } -static inline kuid_t fsuid_into_mnt (struct user_namespace *mnt_userns) +static inline void inode_fsuid_set (struct inode *inode, +struct user_namespace *mnt_userns) { -return kuid_from_mnt (mnt_userns,current_fsuid ()); + inode->i_uid =kuid_from_mnt (mnt_userns,current_fsuid ()); } -static inline kgid_t fsgid_into_mnt (struct user_namespace *mnt_userns) +static inline void inode_fsgid_set (struct inode *inode, +struct user_namespace *mnt_userns) { -return kgid_from_mnt (mnt_userns,current_fsgid ()); + inode->i_gid =kgid_from_mnt (mnt_userns,current_fsgid ()); } static inline bool fsuidgid_has_mapping(struct super_block *sb,
Signature · 1 line
2.27.0
Re: [PATCH v6 02/40] fs: add id translation helpers
Quoted 88 lines · Christian Brauner
Quoted 75 lines · Vivek Goyal
Quoted 52 lines · Christian Brauner
Add simple helpers to make it easy to map kuids into and from idmapped mounts. We provide simple wrappers that filesystems can use to e.g. initialize inodes similar to i_{uid,gid}_read() and i_{uid,gid}_write(). Accessing an inode through an idmapped mount maps the
i_uidandi_gidof the inode to the mount's user namespace. If the fsids are used to initialize inodes they are unmapped according to the mount's user namespace. Passing the initial user namespace to these helpers makes them a nop and so any non-idmapped paths will not be impacted.Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Get rid of the ifdefs and the config option that hid idmapped mounts./* v3 */
unchanged/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent./* v5 */
unchanged
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
unchanged
base-commit:19c329f6808995b142b3966301f217c831e7cf31--- include/linux/fs.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)include/linux/fs.h +1
-0@@ -40,6 +40,7 @@#include <linux/build_bug.h> #include <linux/stddef.h> #include <linux/mount.h> +#include <linux/cred.h> #include <asm/byteorder.h> #include <uapi/linux/fs.h> include/linux/fs.h static inline void i_gid_write(struct inode *inode, gid_t gid) · line 1582
Quoted 9 lines
include/linux/fs.h +6
-0@@ -1573,6 +1574,52 @@ static inline void i_gid_write(struct inode *inode, gid_t gid) inode->i_gid =make_kgid (inode->i_sb->s_user_ns, gid); } +static inline kuid_t kuid_into_mnt (struct user_namespace *mnt_userns, +kuid_t kuid) +{ +return make_kuid (mnt_userns,__kuid_val (kuid)); +} +Hi Christian,
I am having little trouble w.r.t function names and trying to figure out whether they are mapping id down or up.
For example,
kuid_into_mnt()ultimately callsmap_id_down(). That is, id visible inside user namespace is mapped to host
(if observer is ininit_user_ns, IIUC).But
fsuid_into_mnt()ultimately callsmap_id_up(). That's take a kuid and map it into theuser_namespace.Quoted 7 lines
So both the helpers end with
into_mnt()but one maps id down and other maps id up. I found this confusing and was wondering how should I visualize it. So thought of asking you.Is this intentional or can naming be improved so that
*_into_mnt()means one thing (Eithermap_id_up()ormap_id_down()). And vice-a-versa for*_from_mnt().[Trimming my crazy Cc list to not spam everyone.].
Hey Vivek,
Quoted 8 lines
Thank you for your feedback, really appreciated!
The naming was intended to always signify that the helpers always return a k{u,g}id but I can certainly see how the naming isn't as clear as it should be for those helpers in other ways. I would suggest we remove such direct exposures of these helpers completely and make it simpler for callers by introducing very straightforward helpers. See the tiny patches below (only compile tested for now):
Hi Chirstian,
Thanks for the following patches. Now we are only left with kuid_from_mnt() and kuid_into_mnt() and I can wrap my head around it.
Thanks
Vivek
Quoted 185 lines
From
1bab0249295d0cad359f39a38e6171bcd2d68a60Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sat, 13 Mar 2021 15:08:04 +0100
Subject: [PATCH 1/2] fs: introducefsuidgid_has_mapping()helperDon't open-code the checks and instead move them into a clean little helper we can call. This also reduces the risk that if we ever changing something here we forget to change all locations.
Inspired-by Vivek Goyal <[email protected]>Cc Christoph Hellwig <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>--- fs/namei.c | 11 +++-------- include/linux/fs.h | 13 +++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-)fs/namei.c +3
-8@@ -2823,16 +2823,14 @@ static int may_delete(struct user_namespace *mnt_userns, struct inode *dir,static inline int may_create (struct user_namespace *mnt_userns,struct inode *dir,struct dentry *child) { -struct user_namespace *s_user_ns;audit_inode_child (dir, child,AUDIT_TYPE_CHILD_CREATE );if (child->d_inode)return -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; - s_user_ns = dir->i_sb->s_user_ns; -if (!kuid_has_mapping (s_user_ns,fsuid_into_mnt (mnt_userns)) || - !kgid_has_mapping (s_user_ns,fsgid_into_mnt (mnt_userns))) +if (!fsuidgid_has_mapping (dir->i_sb, mnt_userns))return -EOVERFLOW ; +return inode_permission (mnt_userns, dir,MAY_WRITE |MAY_EXEC ); }@@ -3034,14 +3032,11 @@ static int may_o_create(struct user_namespace *mnt_userns, const struct path *dir, struct dentry *dentry, umode_t mode) { - struct user_namespace *s_user_ns; int error = security_path_mknod(dir, dentry, mode, 0);if (error)return error; - s_user_ns = dir->dentry->d_sb->s_user_ns; -if (!kuid_has_mapping (s_user_ns,fsuid_into_mnt (mnt_userns)) || - !kgid_has_mapping (s_user_ns,fsgid_into_mnt (mnt_userns))) +if (!fsuidgid_has_mapping (dir->dentry->d_sb, mnt_userns))return -EOVERFLOW ; error = inode_permission(mnt_userns, dir->dentry->d_inode,include/linux/fs.h +13
-0@@ -1620,6 +1620,19 @@ static inline kgid_t fsgid_into_mnt(struct user_namespace *mnt_userns)return kgid_from_mnt (mnt_userns,current_fsgid ()); } +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; +if (!kuid_has_mapping (s_user_ns, +kuid_from_mnt (mnt_userns,current_fsuid ()))) +return false; +if (!kgid_has_mapping (s_user_ns, +kgid_from_mnt (mnt_userns,current_fsgid ()))) +return false; +return true; +} +extern struct timespec64 current_time (struct inode *inode);/* Signature · 25 lines
2.27.0 From 2f316f7de3ac96ecc8cc889724c0132e96b47b51 Mon Sep 17 00:00:00 2001 From: Christian Brauner <[email protected]> Date: Sat, 13 Mar 2021 15:11:55 +0100 Subject: [PATCH 2/2] fs: introduce two little fs{u,g}id inode initialization helpers As Vivek pointed out we could tweak the names of the fs{u,g}id helpers. That's already good but the better approach is to not expose them in this way to filesystems at all and simply give the filesystems two helpers inode_fsuid_set() and inode_fsgid_set() that will do the right thing. Inspired-by: Vivek Goyal <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Al Viro <[email protected]> Signed-off-by: Christian Brauner <[email protected]> --- fs/ext4/ialloc.c | 2 +- fs/inode.c | 4 ++-- fs/xfs/xfs_inode.c | 2 +- include/linux/fs.h | 10 ++++++---- 4 files changed, 10 insertions(+), 8 deletions(-)fs/ext4/ialloc.c +1
-1@@ -970,7 +970,7 @@ struct inode *__ext4_new_inode(struct user_namespace *mnt_userns,i_gid_write (inode, owner[1 ]); }else if (test_opt (sb,GRPID )) { inode->i_mode = mode; - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns); inode->i_gid = dir->i_gid; }else inode_init_owner (mnt_userns, inode, dir, mode);fs/inode.c +2
-2@@ -2148,7 +2148,7 @@ EXPORT_SYMBOL(init_special_inode);void inode_init_owner (struct user_namespace *mnt_userns,struct inode *inode,const struct inode *dir,umode_t mode) { - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns);if (dir && dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;@@ -2160,7 +2160,7 @@ void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode, !capable_wrt_inode_uidgid(mnt_userns, dir, CAP_FSETID)) mode &= ~S_ISGID ; }else - inode->i_gid =fsgid_into_mnt (mnt_userns); +inode_fsgid_set (inode, mnt_userns); inode->i_mode = mode; }EXPORT_SYMBOL (inode_init_owner);fs/xfs/xfs_inode.c +1
-1@@ -812,7 +812,7 @@ xfs_init_new_inode(if (dir && !(dir->i_mode &S_ISGID ) && (mp->m_flags &XFS_MOUNT_GRPID )) { - inode->i_uid =fsuid_into_mnt (mnt_userns); +inode_fsuid_set (inode, mnt_userns); inode->i_gid = dir->i_gid; inode->i_mode = mode; }else {include/linux/fs.h +6
-4@@ -1610,14 +1610,16 @@ static inline kgid_t kgid_from_mnt(struct user_namespace *mnt_userns,return KGIDT_INIT (from_kgid (mnt_userns, kgid)); } -static inline kuid_t fsuid_into_mnt (struct user_namespace *mnt_userns) +static inline void inode_fsuid_set (struct inode *inode, +struct user_namespace *mnt_userns) { -return kuid_from_mnt (mnt_userns,current_fsuid ()); + inode->i_uid =kuid_from_mnt (mnt_userns,current_fsuid ()); } -static inline kgid_t fsgid_into_mnt (struct user_namespace *mnt_userns) +static inline void inode_fsgid_set (struct inode *inode, +struct user_namespace *mnt_userns) { -return kgid_from_mnt (mnt_userns,current_fsgid ()); + inode->i_gid =kgid_from_mnt (mnt_userns,current_fsgid ()); } static inline bool fsuidgid_has_mapping(struct super_block *sb,Signature · 1 line
2.27.0
Re: [PATCH v6 02/40] fs: add id translation helpers
In reply to Christian Braunerinclude/linux/fs.h static inline kgid_t fsgid_into_mnt(struct user_namespace *mnt_userns) · line 1633
Quoted 8 lines
include/linux/fs.h +8
-0+struct user_namespace *s_user_ns = sb->s_user_ns; +if (!kuid_has_mapping (s_user_ns, +kuid_from_mnt (mnt_userns,current_fsuid ()))) +return false; +if (!kgid_has_mapping (s_user_ns, +kgid_from_mnt (mnt_userns,current_fsgid ()))) +return false; +return true;
Please don't use one tab indents for conditional continuations, as that looks really weird. Always use two tabs or align to the opening brace.
Otherwise these helpers looks really useful.
PATCH v6 3/40 fs: add file and path permissions helpers
In reply to Christian BraunerAdd two simple helpers to check permissions on a file and path respectively and convert over some callers. It simplifies quite a few codepaths and also reduces the churn in later patches quite a bit. Christoph also correctly points out that this makes codepaths (e.g. ioctls) way easier to follow that would otherwise have to do more complex argument passing than necessary.
---
/* v2 */
patch not present
/* v3 */
patch not present
/* v4 */
patch not present
/* v5 */
patch not present
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Make file_user_ns() static inline.
- Add file_permission() and path_permission() helpers.
--- fs/init.c | 6 +++--- fs/notify/fanotify/fanotify_user.c | 2 +- fs/notify/inotify/inotify_user.c | 2 +- fs/open.c | 6 +++--- fs/udf/file.c | 2 +- fs/verity/enable.c | 2 +- include/linux/fs.h | 8 ++++++++ kernel/bpf/inode.c | 2 +- kernel/sys.c | 2 +- mm/madvise.c | 2 +- mm/memcontrol.c | 2 +- mm/mincore.c | 2 +- net/unix/af_unix.c | 2 +- 13 files changed, 24 insertions(+), 16 deletions(-)
fs/init.c +3 -3
@@ -49,7 +49,7 @@ int __init init_chdir(const char *filename) error =kern_path (filename,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &path);if (error)return error; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); + error =path_permission (&path,MAY_EXEC |MAY_CHDIR );if (!error)set_fs_pwd (current->fs, &path);path_put (&path);
@@ -64,7 +64,7 @@ int __init init_chroot(const char *filename) error =kern_path (filename,LOOKUP_FOLLOW |LOOKUP_DIRECTORY , &path);if (error)return error; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); + error =path_permission (&path,MAY_EXEC |MAY_CHDIR );if (error) goto dput_and_out; error = -EPERM ;
@@ -118,7 +118,7 @@ int __init init_eaccess(const char *filename) error =kern_path (filename,LOOKUP_FOLLOW , &path);if (error)return error; - error =inode_permission (d_inode (path.dentry),MAY_ACCESS ); + error =path_permission (&path,MAY_ACCESS );path_put (&path);return error; }
fs/notify/fanotify/fanotify_user.c +1 -1
@@ -702,7 +702,7 @@ static int fanotify_find_path(int dfd, const char __user *filename, }/* you can only watch an inode if you have read permissions on it */ - ret =inode_permission (path->dentry->d_inode,MAY_READ ); + ret =path_permission (path,MAY_READ );if (ret) {path_put (path); goto out;
fs/notify/inotify/inotify_user.c +1 -1
@@ -352,7 +352,7 @@ static int inotify_find_inode(const char __user *dirname, struct path *path,if (error)return error;/* you can only watch an inode if you have read permissions on it */ - error =inode_permission (path->dentry->d_inode,MAY_READ ); + error =path_permission (path,MAY_READ );if (error) {path_put (path);return error;
fs/open.c +3 -3
@@ -492,7 +492,7 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)if (error) goto out; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); + error =path_permission (&path,MAY_EXEC |MAY_CHDIR );if (error) goto dput_and_out;
@@ -521,7 +521,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)if (!d_can_lookup (f.file->f_path.dentry)) goto out_putf; - error =inode_permission (file_inode (f.file),MAY_EXEC |MAY_CHDIR ); + error =file_permission (f.file,MAY_EXEC |MAY_CHDIR );if (!error)set_fs_pwd (current->fs, &f.file->f_path); out_putf:
@@ -540,7 +540,7 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)if (error) goto out; - error =inode_permission (path.dentry->d_inode,MAY_EXEC |MAY_CHDIR ); + error =path_permission (&path,MAY_EXEC |MAY_CHDIR );if (error) goto dput_and_out;
fs/udf/file.c +1 -1
@@ -183,7 +183,7 @@ long udf_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)long old_block, new_block;int result; -if (inode_permission (inode,MAY_READ ) !=0 ) { +if (file_permission (filp,MAY_READ ) !=0 ) {udf_debug ("no permission to access inode %lu\n" , inode->i_ino);return -EPERM ; }
fs/verity/enable.c +1 -1
@@ -369,7 +369,7 @@ int fsverity_ioctl_enable(struct file *filp, const void __user *uarg)* has verity enabled, and to stabilize the data being hashed. */ - err =inode_permission (inode,MAY_WRITE ); + err =file_permission (filp,MAY_WRITE );if (err)return err;
include/linux/fs.h +8 -0
@@ -2812,6 +2812,14 @@ static inline int bmap(struct inode *inode, sector_t *block)extern int notify_change (struct dentry *,struct iattr *,struct inode **);extern int inode_permission (struct inode *,int );extern int generic_permission (struct inode *,int ); +static inline int file_permission (struct file *file,int mask) +{ +return inode_permission (file_inode (file), mask); +} +static inline int path_permission (const struct path *path,int mask) +{ +return inode_permission (d_inode (path->dentry), mask); +}extern int __check_sticky (struct inode *dir,struct inode *inode);static inline bool execute_ok (struct inode *inode)
kernel/bpf/inode.c +1 -1
@@ -507,7 +507,7 @@ static void *bpf_obj_do_get(const char __user *pathname,return ERR_PTR (ret); inode =d_backing_inode (path.dentry); - ret =inode_permission (inode,ACC_MODE (flags)); + ret =path_permission (&path,ACC_MODE (flags));if (ret) goto out;
kernel/sys.c +1 -1
@@ -1848,7 +1848,7 @@ static int prctl_set_mm_exe_file(struct mm_struct *mm, unsigned int fd)if (!S_ISREG (inode->i_mode) ||path_noexec (&exe.file->f_path)) goto exit; - err =inode_permission (inode,MAY_EXEC ); + err =file_permission (exe.file,MAY_EXEC );if (err) goto exit;
mm/madvise.c +1 -1
@@ -540,7 +540,7 @@ static inline bool can_do_pageout(struct vm_area_struct *vma)* opens a side channel. */ return inode_owner_or_capable (file_inode (vma->vm_file)) || -inode_permission (file_inode (vma->vm_file),MAY_WRITE ) ==0 ; +file_permission (vma->vm_file,MAY_WRITE ) ==0 ; } static long madvise_pageout(struct vm_area_struct *vma,
mm/memcontrol.c +1 -1
@@ -4899,7 +4899,7 @@ static ssize_t memcg_write_event_control(struct kernfs_open_file *of,/* the process need read permission on control file */ /* AV: shouldn't we check that it's been opened for read instead? */ - ret =inode_permission (file_inode (cfile.file),MAY_READ ); + ret =file_permission (cfile.file,MAY_READ );if (ret <0 ) goto out_put_cfile;
mm/mincore.c +1 -1
@@ -167,7 +167,7 @@ static inline bool can_do_mincore(struct vm_area_struct *vma)* mappings, which opens a side channel. */ return inode_owner_or_capable (file_inode (vma->vm_file)) || -inode_permission (file_inode (vma->vm_file),MAY_WRITE ) ==0 ; +file_permission (vma->vm_file,MAY_WRITE ) ==0 ; }static const struct mm_walk_ops mincore_walk_ops = {
net/unix/af_unix.c +1 -1
@@ -936,7 +936,7 @@ static struct sock *unix_find_other(struct net *net,if (err) goto fail; inode =d_backing_inode (path.dentry); - err =inode_permission (inode,MAY_WRITE ); + err =path_permission (&path,MAY_WRITE );if (err) goto put_fail;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 03/40] fs: add file and path permissions helpers
Quoted 7 lines · Christian Brauner
Add two simple helpers to check permissions on a file and path respectively and convert over some callers. It simplifies quite a few codepaths and also reduces the churn in later patches quite a bit. Christoph also correctly points out that this makes codepaths (e.g. ioctls) way easier to follow that would otherwise have to do more complex argument passing than necessary.
Quoted 7 lines
Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Suggested-by Christoph Hellwig <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 4/40 capability: handle idmapped mounts
In reply to Christian BraunerIn order to determine whether a caller holds privilege over a given inode the capability framework exposes the two helpers privileged_wrt_inode_uidgid() and capable_wrt_inode_uidgid(). The former verifies that the inode has a mapping in the caller's user namespace and the latter additionally verifies that the caller has the requested capability in their current user namespace.
If the inode is accessed through an idmapped mount map it into the mount's user namespace. Afterwards the checks are identical to non-idmapped inodes. If the initial user namespace is passed all operations are a nop so non-idmapped mounts will not see a change in behavior.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
- Wrap lines over 80 chars.
--- fs/attr.c | 8 ++++---- fs/exec.c | 3 ++- fs/inode.c | 3 ++- fs/namei.c | 13 ++++++++----- fs/overlayfs/super.c | 2 +- fs/posix_acl.c | 2 +- fs/xfs/xfs_ioctl.c | 2 +- include/linux/capability.h | 7 +++++-- kernel/capability.c | 14 +++++++++----- security/commoncap.c | 5 +++-- 10 files changed, 36 insertions(+), 23 deletions(-)
fs/attr.c +4 -4
@@ -23,7 +23,7 @@ static bool chown_ok(const struct inode *inode, kuid_t uid)if (uid_eq (current_fsuid (), inode->i_uid) &&uid_eq (uid, inode->i_uid))return true; -if (capable_wrt_inode_uidgid (inode,CAP_CHOWN )) +if (capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_CHOWN ))return true;if (uid_eq (inode->i_uid,INVALID_UID ) &&ns_capable (inode->i_sb->s_user_ns,CAP_CHOWN ))
@@ -36,7 +36,7 @@ static bool chgrp_ok(const struct inode *inode, kgid_t gid)if (uid_eq (current_fsuid (), inode->i_uid) && (in_group_p (gid) ||gid_eq (gid, inode->i_gid)))return true; -if (capable_wrt_inode_uidgid (inode,CAP_CHOWN )) +if (capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_CHOWN ))return true;if (gid_eq (inode->i_gid,INVALID_GID ) &&ns_capable (inode->i_sb->s_user_ns,CAP_CHOWN ))
@@ -92,7 +92,7 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr)/* Also check the setgid bit! */ if (!in_group_p ((ia_valid &ATTR_GID ) ? attr->ia_gid : inode->i_gid) && - !capable_wrt_inode_uidgid (inode,CAP_FSETID )) + !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) attr->ia_mode &= ~S_ISGID ; }
@@ -193,7 +193,7 @@ void setattr_copy(struct inode *inode, const struct iattr *attr)umode_t mode = attr->ia_mode;if (!in_group_p (inode->i_gid) && - !capable_wrt_inode_uidgid (inode,CAP_FSETID )) + !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) mode &= ~S_ISGID ; inode->i_mode = mode; }
fs/exec.c +2 -1
@@ -1411,7 +1411,8 @@ void would_dump(struct linux_binprm *bprm, struct file *file)/* Ensure mm->user_ns contains the executable */ user_ns = old = bprm->mm->user_ns;while ((user_ns != &init_user_ns) && - !privileged_wrt_inode_uidgid (user_ns, inode)) + !privileged_wrt_inode_uidgid (user_ns, &init_user_ns, + inode)) user_ns = user_ns->parent;if (old != user_ns) {
fs/inode.c +2 -1
@@ -2146,7 +2146,8 @@ void inode_init_owner(struct inode *inode, const struct inode *dir, mode |=S_ISGID ; else if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP) && !in_group_p(inode->i_gid) && - !capable_wrt_inode_uidgid(dir, CAP_FSETID)) + !capable_wrt_inode_uidgid(&init_user_ns, dir, + CAP_FSETID)) mode &= ~S_ISGID ; }else inode->i_gid =current_fsgid ();
fs/namei.c +8 -5
@@ -357,10 +357,11 @@ int generic_permission(struct inode *inode, int mask)if (S_ISDIR (inode->i_mode)) {/* DACs are overridable for directories */ if (!(mask &MAY_WRITE )) -if (capable_wrt_inode_uidgid (inode, +if (capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_DAC_READ_SEARCH ))return 0 ; -if (capable_wrt_inode_uidgid (inode,CAP_DAC_OVERRIDE )) +if (capable_wrt_inode_uidgid (&init_user_ns, inode, +CAP_DAC_OVERRIDE ))return 0 ;return -EACCES ; }
@@ -370,7 +371,8 @@ int generic_permission(struct inode *inode, int mask)*/ mask &=MAY_READ |MAY_WRITE |MAY_EXEC ;if (mask ==MAY_READ ) -if (capable_wrt_inode_uidgid (inode,CAP_DAC_READ_SEARCH )) +if (capable_wrt_inode_uidgid (&init_user_ns, inode, +CAP_DAC_READ_SEARCH ))return 0 ;/* * Read/write DACs are always overridable.
@@ -378,7 +380,8 @@ int generic_permission(struct inode *inode, int mask)* at least one exec bit set. */ if (!(mask &MAY_EXEC ) || (inode->i_mode &S_IXUGO )) -if (capable_wrt_inode_uidgid (inode,CAP_DAC_OVERRIDE )) +if (capable_wrt_inode_uidgid (&init_user_ns, inode, +CAP_DAC_OVERRIDE ))return 0 ;return -EACCES ;
@@ -2659,7 +2662,7 @@ int __check_sticky(struct inode *dir, struct inode *inode)return 0 ;if (uid_eq (dir->i_uid, fsuid))return 0 ; -return !capable_wrt_inode_uidgid (inode,CAP_FOWNER ); +return !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FOWNER ); }EXPORT_SYMBOL (__check_sticky);
fs/overlayfs/super.c +1 -1
@@ -1017,7 +1017,7 @@ ovl_posix_acl_xattr_set(const struct xattr_handler *handler,if (unlikely (inode->i_mode &S_ISGID ) && handler->flags ==ACL_TYPE_ACCESS && !in_group_p (inode->i_gid) && - !capable_wrt_inode_uidgid (inode,CAP_FSETID )) { + !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) {struct iattr iattr = { .ia_valid =ATTR_KILL_SGID }; err =ovl_setattr (dentry, &iattr);
fs/posix_acl.c +1 -1
@@ -656,7 +656,7 @@ int posix_acl_update_mode(struct inode *inode, umode_t *mode_p,if (error ==0 ) *acl =NULL ;if (!in_group_p (inode->i_gid) && - !capable_wrt_inode_uidgid (inode,CAP_FSETID )) + !capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_FSETID )) mode &= ~S_ISGID ; *mode_p = mode;return 0 ;
fs/xfs/xfs_ioctl.c +1 -1
@@ -1502,7 +1502,7 @@ xfs_ioctl_setattr(*/ if ((VFS_I (ip)->i_mode & (S_ISUID |S_ISGID )) && - !capable_wrt_inode_uidgid (VFS_I (ip),CAP_FSETID )) + !capable_wrt_inode_uidgid (&init_user_ns,VFS_I (ip),CAP_FSETID ))VFS_I (ip)->i_mode &= ~(S_ISUID |S_ISGID );/* Change the ownerships and register project quota modifications */
include/linux/capability.h +5 -2
@@ -247,8 +247,11 @@ static inline bool ns_capable_setid(struct user_namespace *ns, int cap) return true; }#endif /* CONFIG_MULTIUSER */ -extern bool privileged_wrt_inode_uidgid (struct user_namespace *ns,const struct inode *inode); -extern bool capable_wrt_inode_uidgid (const struct inode *inode,int cap); +bool privileged_wrt_inode_uidgid (struct user_namespace *ns, +struct user_namespace *mnt_userns, +const struct inode *inode); +bool capable_wrt_inode_uidgid (struct user_namespace *mnt_userns, +const struct inode *inode,int cap);extern bool file_ns_capable (const struct file *file,struct user_namespace *ns,int cap);extern bool ptracer_capable (struct task_struct *tsk,struct user_namespace *ns);static inline bool perfmon_capable (void )
kernel/capability.c +9 -5
@@ -484,10 +484,12 @@ EXPORT_SYMBOL(file_ns_capable);* * Return true if the inode uid and gid are within the namespace. */ -bool privileged_wrt_inode_uidgid (struct user_namespace *ns,const struct inode *inode) +bool privileged_wrt_inode_uidgid (struct user_namespace *ns, +struct user_namespace *mnt_userns, +const struct inode *inode) { -return kuid_has_mapping (ns, inode->i_uid) && -kgid_has_mapping (ns, inode->i_gid); +return kuid_has_mapping (ns,i_uid_into_mnt (mnt_userns, inode)) && +kgid_has_mapping (ns,i_gid_into_mnt (mnt_userns, inode)); }/**
@@ -499,11 +501,13 @@ bool privileged_wrt_inode_uidgid(struct user_namespace *ns, const struct inode ** its own user namespace and that the given inode's uid and gid are * mapped into the current user namespace. */ -bool capable_wrt_inode_uidgid (const struct inode *inode,int cap) +bool capable_wrt_inode_uidgid (struct user_namespace *mnt_userns, +const struct inode *inode,int cap) {struct user_namespace *ns =current_user_ns (); -return ns_capable (ns, cap) &&privileged_wrt_inode_uidgid (ns, inode); +return ns_capable (ns, cap) && +privileged_wrt_inode_uidgid (ns, mnt_userns, inode); }EXPORT_SYMBOL (capable_wrt_inode_uidgid);
security/commoncap.c +3 -2
@@ -489,7 +489,7 @@ int cap_convert_nscap(struct dentry *dentry, const void **ivalue, size_t size)return -EINVAL ;if (!validheader (size, cap))return -EINVAL ; -if (!capable_wrt_inode_uidgid (inode,CAP_SETFCAP )) +if (!capable_wrt_inode_uidgid (&init_user_ns, inode,CAP_SETFCAP ))return -EPERM ;if (size ==XATTR_CAPS_SZ_2 )if (ns_capable (inode->i_sb->s_user_ns,CAP_SETFCAP ))
@@ -956,7 +956,8 @@ int cap_inode_removexattr(struct dentry *dentry, const char *name)struct inode *inode =d_backing_inode (dentry);if (!inode)return -EINVAL ; -if (!capable_wrt_inode_uidgid (inode,CAP_SETFCAP )) +if (!capable_wrt_inode_uidgid (&init_user_ns, inode, +CAP_SETFCAP ))return -EPERM ;return 0 ; }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 04/40] capability: handle idmapped mounts
Quoted 12 lines · Christian Brauner
In order to determine whether a caller holds privilege over a given inode the capability framework exposes the two helpers
privileged_wrt_inode_uidgid()andcapable_wrt_inode_uidgid(). The former verifies that the inode has a mapping in the caller's user namespace and the latter additionally verifies that the caller has the requested capability in their current user namespace.
If the inode is accessed through an idmapped mount map it into the mount's user namespace. Afterwards the checks are identical to non-idmapped inodes. If the initial user namespace is passed all operations are a nop so non-idmapped mounts will not see a change in behavior.
Quoted 8 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Acked-by Serge Hallyn <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 5/39 namei: make permission helpers idmapped mount aware
In reply to Christian BraunerThe two helpers inode_permission() and generic_permission() are used by the vfs to perform basic permission checking by verifying that the caller is privileged over an inode. In order to handle idmapped mounts we extend the two helpers with an additional user namespace argument. On idmapped mounts the two helpers will make sure to map the inode according to the mount's user namespace and then peform identical permission checks to inode_permission() and generic_permission(). If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- "Serge E. Hallyn" <[email protected]>:
- Add proper documentation for all the changed permission checking helpers and adjust terminology to avoid any potential confusion.
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
- Christoph Hellwig <[email protected]>:
- Change commit message to reflect the fact that no new permission helpers are introduced but only the existing ones changed.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Drop "extern"s in headers.
- Wrap lines > 80 chars.
--- fs/attr.c | 3 +- fs/btrfs/inode.c | 2 +- fs/btrfs/ioctl.c | 12 ++-- fs/ceph/inode.c | 2 +- fs/cifs/cifsfs.c | 2 +- fs/configfs/symlink.c | 3 +- fs/ecryptfs/inode.c | 3 +- fs/exec.c | 2 +- fs/fuse/dir.c | 5 +- fs/gfs2/inode.c | 2 +- fs/hostfs/hostfs_kern.c | 2 +- fs/kernfs/inode.c | 2 +- fs/libfs.c | 7 ++- fs/namei.c | 121 +++++++++++++++++++++++++++----------- fs/nfs/dir.c | 2 +- fs/nfsd/nfsfh.c | 3 +- fs/nfsd/vfs.c | 5 +- fs/nilfs2/inode.c | 2 +- fs/ocfs2/file.c | 2 +- fs/ocfs2/refcounttree.c | 4 +- fs/open.c | 4 +- fs/orangefs/inode.c | 2 +- fs/overlayfs/file.c | 2 +- fs/overlayfs/inode.c | 4 +- fs/overlayfs/util.c | 2 +- fs/posix_acl.c | 17 ++++-- fs/proc/base.c | 4 +- fs/proc/fd.c | 2 +- fs/reiserfs/xattr.c | 2 +- fs/remap_range.c | 2 +- fs/xattr.c | 2 +- include/linux/fs.h | 10 ++-- include/linux/posix_acl.h | 7 ++- ipc/mqueue.c | 2 +- kernel/bpf/inode.c | 2 +- kernel/cgroup/cgroup.c | 2 +- 36 files changed, 164 insertions(+), 88 deletions(-)
fs/attr.c +2 -1
@@ -244,7 +244,8 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **dereturn -EPERM ;if (!inode_owner_or_capable (inode)) { - error =inode_permission (inode,MAY_WRITE ); + error =inode_permission (&init_user_ns, inode, +MAY_WRITE );if (error)return error; }
fs/btrfs/inode.c +1 -1
@@ -9889,7 +9889,7 @@ static int btrfs_permission(struct inode *inode, int mask)if (BTRFS_I (inode)->flags &BTRFS_INODE_READONLY )return -EACCES ; } -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }static int btrfs_tmpfile (struct inode *dir,struct dentry *dentry,umode_t mode)
fs/btrfs/ioctl.c +7 -5
@@ -922,7 +922,7 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)BUG_ON (d_inode (victim->d_parent) != dir);audit_inode_child (dir, victim,AUDIT_TYPE_CHILD_DELETE ); - error =inode_permission (dir,MAY_WRITE |MAY_EXEC ); + error =inode_permission (&init_user_ns, dir,MAY_WRITE |MAY_EXEC );if (error)return error;if (IS_APPEND (dir))
@@ -951,7 +951,7 @@ static inline int btrfs_may_create(struct inode *dir, struct dentry *child)return -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; -return inode_permission (dir,MAY_WRITE |MAY_EXEC ); +return inode_permission (&init_user_ns, dir,MAY_WRITE |MAY_EXEC ); }/*
@@ -2538,7 +2538,8 @@ static int btrfs_search_path_in_tree_user(struct inode *inode, ret =PTR_ERR (temp_inode); goto out_put; } - ret =inode_permission (temp_inode,MAY_READ |MAY_EXEC ); + ret =inode_permission (&init_user_ns, temp_inode, +MAY_READ |MAY_EXEC );iput (temp_inode);if (ret) { ret = -EACCES ;
@@ -3068,7 +3069,8 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,if (root == dest) goto out_dput; - err =inode_permission (inode,MAY_WRITE |MAY_EXEC ); + err =inode_permission (&init_user_ns, inode, +MAY_WRITE |MAY_EXEC );if (err) goto out_dput; }
@@ -3139,7 +3141,7 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)* running and allows defrag on files open in read-only mode. */ if (!capable (CAP_SYS_ADMIN ) && -inode_permission (inode,MAY_WRITE )) { +inode_permission (&init_user_ns, inode,MAY_WRITE )) { ret = -EPERM ; goto out; }
fs/ceph/inode.c +1 -1
@@ -2331,7 +2331,7 @@ int ceph_permission(struct inode *inode, int mask) err =ceph_do_getattr (inode,CEPH_CAP_AUTH_SHARED , false);if (!err) - err =generic_permission (inode, mask); + err =generic_permission (&init_user_ns, inode, mask);return err; }
fs/cifs/cifsfs.c +1 -1
@@ -320,7 +320,7 @@ static int cifs_permission(struct inode *inode, int mask)on the client (above and beyond ACL on servers) for servers which do not support setting and viewing mode bits, so allowing client to check permissions is useful */ -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }static struct kmem_cache *cifs_inode_cachep;
fs/configfs/symlink.c +2 -1
@@ -197,7 +197,8 @@ int configfs_symlink(struct inode *dir, struct dentry *dentry, const char *symnaif (dentry->d_inode ||d_unhashed (dentry)) ret = -EEXIST ;else - ret =inode_permission (dir,MAY_WRITE |MAY_EXEC ); + ret =inode_permission (&init_user_ns, dir, +MAY_WRITE |MAY_EXEC );if (!ret) ret = type->ct_item_ops->allow_link (parent_item, target_item);if (!ret) {
fs/ecryptfs/inode.c +2 -1
@@ -864,7 +864,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)static int ecryptfs_permission (struct inode *inode,int mask) { -return inode_permission (ecryptfs_inode_to_lower (inode), mask); +return inode_permission (&init_user_ns, +ecryptfs_inode_to_lower (inode), mask); }/**
fs/exec.c +1 -1
@@ -1404,7 +1404,7 @@ EXPORT_SYMBOL(begin_new_exec);void would_dump (struct linux_binprm *bprm,struct file *file) {struct inode *inode =file_inode (file); -if (inode_permission (inode,MAY_READ ) <0 ) { +if (inode_permission (&init_user_ns, inode,MAY_READ ) <0 ) {struct user_namespace *old, *user_ns; bprm->interp_flags |=BINPRM_FLAGS_ENFORCE_NONDUMP ;
fs/fuse/dir.c +3 -2
@@ -1280,7 +1280,7 @@ static int fuse_permission(struct inode *inode, int mask) }if (fc->default_permissions) { - err =generic_permission (inode, mask); + err =generic_permission (&init_user_ns, inode, mask);/* If permission is denied, try to refresh file attributes. This is also needed, because the root
@@ -1288,7 +1288,8 @@ static int fuse_permission(struct inode *inode, int mask)if (err == -EACCES && !refreshed) { err =fuse_perm_getattr (inode, mask);if (!err) - err =generic_permission (inode, mask); + err =generic_permission (&init_user_ns, + inode, mask); }/* Note: the opposite of the above test does not
fs/gfs2/inode.c +1 -1
@@ -1852,7 +1852,7 @@ int gfs2_permission(struct inode *inode, int mask)if ((mask &MAY_WRITE ) &&IS_IMMUTABLE (inode)) error = -EPERM ;else - error =generic_permission (inode, mask); + error =generic_permission (&init_user_ns, inode, mask);if (gfs2_holder_initialized (&i_gh))gfs2_glock_dq_uninit (&i_gh);
fs/hostfs/hostfs_kern.c +1 -1
@@ -779,7 +779,7 @@ static int hostfs_permission(struct inode *ino, int desired) err =access_file (name, r, w, x);__putname (name);if (!err) - err =generic_permission (ino, desired); + err =generic_permission (&init_user_ns, ino, desired);return err; }
fs/kernfs/inode.c +1 -1
@@ -285,7 +285,7 @@ int kernfs_iop_permission(struct inode *inode, int mask)kernfs_refresh_inode (kn, inode);mutex_unlock (&kernfs_mutex); -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); } int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
fs/libfs.c +6 -1
@@ -1318,9 +1318,14 @@ static ssize_t empty_dir_listxattr(struct dentry *dentry, char *list, size_t sizreturn -EOPNOTSUPP ; } +static int empty_dir_permission (struct inode *inode,int mask) +{ +return generic_permission (&init_user_ns, inode, mask); +} +static const struct inode_operations empty_dir_inode_operations = { .lookup = empty_dir_lookup, - .permission = generic_permission, + .permission = empty_dir_permission, .setattr = empty_dir_setattr, .getattr = empty_dir_getattr, .listxattr = empty_dir_listxattr,
fs/namei.c +86 -35
300 lines not on this page · raw message
fs/nfs/dir.c +1 -1
@@ -2987,7 +2987,7 @@ int nfs_permission(struct inode *inode, int mask) res =nfs_revalidate_inode (NFS_SERVER (inode), inode);if (res ==0 ) - res =generic_permission (inode, mask); + res =generic_permission (&init_user_ns, inode, mask); goto out; }EXPORT_SYMBOL_GPL (nfs_permission);
fs/nfsd/nfsfh.c +2 -1
@@ -40,7 +40,8 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)/* make sure parents give x permission to user */ int err; parent =dget_parent (tdentry); - err =inode_permission (d_inode (parent),MAY_EXEC ); + err =inode_permission (&init_user_ns, +d_inode (parent),MAY_EXEC );if (err <0 ) {dput (parent);break ;
fs/nfsd/vfs.c +3 -2
@@ -2391,13 +2391,14 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,return 0 ;/* This assumes NFSD_MAY_{READ,WRITE,EXEC} == MAY_{READ,WRITE,EXEC} */ - err =inode_permission (inode, acc & (MAY_READ |MAY_WRITE |MAY_EXEC )); + err =inode_permission (&init_user_ns, inode, + acc & (MAY_READ |MAY_WRITE |MAY_EXEC ));/* Allow read access to binaries even when mode 111 */ if (err == -EACCES &&S_ISREG (inode->i_mode) && (acc == (NFSD_MAY_READ |NFSD_MAY_OWNER_OVERRIDE ) || acc == (NFSD_MAY_READ |NFSD_MAY_READ_IF_EXEC ))) - err =inode_permission (inode,MAY_EXEC ); + err =inode_permission (&init_user_ns, inode,MAY_EXEC );return err?nfserrno (err) :0 ; }
fs/nilfs2/inode.c +1 -1
@@ -851,7 +851,7 @@ int nilfs_permission(struct inode *inode, int mask) root->cno != NILFS_CPTREE_CURRENT_CNO)return -EROFS ;/* snapshot is not writable */ -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }int nilfs_load_inode_block (struct inode *inode,struct buffer_head **pbh)
fs/ocfs2/file.c +1 -1
@@ -1355,7 +1355,7 @@ int ocfs2_permission(struct inode *inode, int mask)dump_stack (); } - ret =generic_permission (inode, mask); + ret =generic_permission (&init_user_ns, inode, mask);ocfs2_inode_unlock_tracker (inode,0 , &oh, had_lock); out:
fs/ocfs2/refcounttree.c +2 -2
@@ -4346,7 +4346,7 @@ static inline int ocfs2_may_create(struct inode *dir, struct dentry *child)return -EEXIST ;if (IS_DEADDIR (dir))return -ENOENT ; -return inode_permission (dir,MAY_WRITE |MAY_EXEC ); +return inode_permission (&init_user_ns, dir,MAY_WRITE |MAY_EXEC ); }/**
@@ -4400,7 +4400,7 @@ static int ocfs2_vfs_reflink(struct dentry *old_dentry, struct inode *dir,* file. */ if (!preserve) { - error =inode_permission (inode,MAY_READ ); + error =inode_permission (&init_user_ns, inode,MAY_READ );if (error)return error; }
fs/open.c +2 -2
@@ -83,7 +83,7 @@ long vfs_truncate(const struct path *path, loff_t length)if (error) goto out; - error =inode_permission (inode,MAY_WRITE ); + error =inode_permission (&init_user_ns, inode,MAY_WRITE );if (error) goto mnt_drop_write_and_out;
@@ -436,7 +436,7 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla goto out_path_release; } - res =inode_permission (inode, mode |MAY_ACCESS ); + res =inode_permission (&init_user_ns, inode, mode |MAY_ACCESS );/* SuS v2 requires we report a read only fs too */ if (res || !(mode &S_IWOTH ) ||special_file (inode->i_mode)) goto out_path_release;
fs/orangefs/inode.c +1 -1
@@ -933,7 +933,7 @@ int orangefs_permission(struct inode *inode, int mask)if (ret <0 )return ret; -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }int orangefs_update_time (struct inode *inode,struct timespec64 *time,int flags)
fs/overlayfs/file.c +1 -1
@@ -50,7 +50,7 @@ static struct file *ovl_open_realfile(const struct file *file, acc_mode |=MAY_APPEND ; old_cred =ovl_override_creds (inode->i_sb); - err =inode_permission (realinode,MAY_OPEN | acc_mode); + err =inode_permission (&init_user_ns, realinode,MAY_OPEN | acc_mode);if (err) { realfile =ERR_PTR (err); }else {
fs/overlayfs/inode.c +2 -2
@@ -294,7 +294,7 @@ int ovl_permission(struct inode *inode, int mask)* Check overlay inode with the creds of task and underlying inode * with creds of mounter */ - err =generic_permission (inode, mask); + err =generic_permission (&init_user_ns, inode, mask);if (err)return err;
@@ -305,7 +305,7 @@ int ovl_permission(struct inode *inode, int mask)/* Make sure mounter can read file for copy up later */ mask |=MAY_READ ; } - err =inode_permission (realinode, mask); + err =inode_permission (&init_user_ns, realinode, mask);revert_creds (old_cred);return err;
fs/overlayfs/util.c +1 -1
@@ -479,7 +479,7 @@ struct file *ovl_path_open(struct path *path, int flags)BUG (); } - err =inode_permission (inode, acc_mode |MAY_OPEN ); + err =inode_permission (&init_user_ns, inode, acc_mode |MAY_OPEN );if (err)return ERR_PTR (err);
fs/posix_acl.c +12 -5
@@ -345,10 +345,13 @@ EXPORT_SYMBOL(posix_acl_from_mode);* by the acl. Returns -E... otherwise. */ int -posix_acl_permission (struct inode *inode,const struct posix_acl *acl,int want) +posix_acl_permission (struct user_namespace *mnt_userns,struct inode *inode, +const struct posix_acl *acl,int want) {const struct posix_acl_entry *pa, *pe, *mask_obj;int found =0 ; +kuid_t uid; +kgid_t gid; want &=MAY_READ |MAY_WRITE |MAY_EXEC ;
@@ -356,22 +359,26 @@ posix_acl_permission(struct inode *inode, const struct posix_acl *acl, int want)switch (pa->e_tag) {case ACL_USER_OBJ :/* (May have been checked already) */ -if (uid_eq (inode->i_uid,current_fsuid ())) + uid =i_uid_into_mnt (mnt_userns, inode); +if (uid_eq (uid,current_fsuid ())) goto check_perm;break ;case ACL_USER : -if (uid_eq (pa->e_uid,current_fsuid ())) + uid =kuid_into_mnt (mnt_userns, pa->e_uid); +if (uid_eq (uid,current_fsuid ())) goto mask;break ;case ACL_GROUP_OBJ : -if (in_group_p (inode->i_gid)) { + gid =i_gid_into_mnt (mnt_userns, inode); +if (in_group_p (gid)) { found =1 ;if ((pa->e_perm & want) == want) goto mask; }break ;case ACL_GROUP : -if (in_group_p (pa->e_gid)) { + gid =kgid_into_mnt (mnt_userns, pa->e_gid); +if (in_group_p (gid)) { found =1 ;if ((pa->e_perm & want) == want) goto mask;
fs/proc/base.c +2 -2
@@ -751,7 +751,7 @@ static int proc_pid_permission(struct inode *inode, int mask)return -EPERM ; } -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }
@@ -3492,7 +3492,7 @@ static int proc_tid_comm_permission(struct inode *inode, int mask)return 0 ; } -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }static const struct inode_operations proc_tid_comm_inode_operations = {
fs/proc/fd.c +1 -1
@@ -281,7 +281,7 @@ int proc_fd_permission(struct inode *inode, int mask)struct task_struct *p;int rv; - rv =generic_permission (inode, mask); + rv =generic_permission (&init_user_ns, inode, mask);if (rv ==0 )return rv;
fs/reiserfs/xattr.c +1 -1
@@ -957,7 +957,7 @@ int reiserfs_permission(struct inode *inode, int mask)if (IS_PRIVATE (inode))return 0 ; -return generic_permission (inode, mask); +return generic_permission (&init_user_ns, inode, mask); }static int xattr_hide_revalidate (struct dentry *dentry,unsigned int flags)
fs/remap_range.c +1 -1
@@ -438,7 +438,7 @@ static bool allow_file_dedupe(struct file *file)return true;if (uid_eq (current_fsuid (),file_inode (file)->i_uid))return true; -if (!inode_permission (file_inode (file),MAY_WRITE )) +if (!inode_permission (&init_user_ns,file_inode (file),MAY_WRITE ))return true;return false; }
fs/xattr.c +1 -1
@@ -131,7 +131,7 @@ xattr_permission(struct inode *inode, const char *name, int mask)return -EPERM ; } -return inode_permission (inode, mask); +return inode_permission (&init_user_ns, inode, mask); }/*
include/linux/fs.h +6 -4
@@ -2810,15 +2810,17 @@ static inline int bmap(struct inode *inode, sector_t *block)#endif extern int notify_change (struct dentry *,struct iattr *,struct inode **); -extern int inode_permission (struct inode *,int ); -extern int generic_permission (struct inode *,int ); +int inode_permission (struct user_namespace *,struct inode *,int ); +int generic_permission (struct user_namespace *,struct inode *,int );static inline int file_permission (struct file *file,int mask) { -return inode_permission (file_inode (file), mask); +return inode_permission (file_mnt_user_ns (file), +file_inode (file), mask); }static inline int path_permission (const struct path *path,int mask) { -return inode_permission (d_inode (path->dentry), mask); +return inode_permission (mnt_user_ns (path->mnt), +d_inode (path->dentry), mask); }extern int __check_sticky (struct inode *dir,struct inode *inode);
include/linux/posix_acl.h +5 -2
@@ -15,6 +15,8 @@#include <linux/refcount.h> #include <uapi/linux/posix_acl.h> +struct user_namespace ; +struct posix_acl_entry {short e_tag;unsigned short e_perm;
@@ -61,8 +63,6 @@ posix_acl_release(struct posix_acl *acl)extern void posix_acl_init (struct posix_acl *,int );extern struct posix_acl *posix_acl_alloc (int ,gfp_t ); -extern int posix_acl_valid (struct user_namespace *,const struct posix_acl *); -extern int posix_acl_permission (struct inode *,const struct posix_acl *,int );extern struct posix_acl *posix_acl_from_mode (umode_t ,gfp_t );extern int posix_acl_equiv_mode (const struct posix_acl *,umode_t *);extern int __posix_acl_create (struct posix_acl **,gfp_t ,umode_t *);
@@ -85,6 +85,9 @@ struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type);void set_cached_acl (struct inode *inode,int type,struct posix_acl *acl);void forget_cached_acl (struct inode *inode,int type);void forget_all_cached_acls (struct inode *inode); +int posix_acl_valid (struct user_namespace *,const struct posix_acl *); +int posix_acl_permission (struct user_namespace *,struct inode *, +const struct posix_acl *,int );static inline void cache_no_acl (struct inode *inode) {
ipc/mqueue.c +1 -1
@@ -873,7 +873,7 @@ static int prepare_open(struct dentry *dentry, int oflag, int ro,if ((oflag &O_ACCMODE ) == (O_RDWR |O_WRONLY ))return -EINVAL ; acc = oflag2acc[oflag &O_ACCMODE ]; -return inode_permission (d_inode (dentry), acc); +return inode_permission (&init_user_ns,d_inode (dentry), acc); } static int do_mq_open(const char __user *u_name, int oflag, umode_t mode,
kernel/bpf/inode.c +1 -1
@@ -558,7 +558,7 @@ int bpf_obj_get_user(const char __user *pathname, int flags)static struct bpf_prog *__get_prog_inode (struct inode *inode,enum bpf_prog_type type) {struct bpf_prog *prog; -int ret =inode_permission (inode,MAY_READ ); +int ret =inode_permission (&init_user_ns, inode,MAY_READ );if (ret)return ERR_PTR (ret);
kernel/cgroup/cgroup.c +1 -1
@@ -4670,7 +4670,7 @@ static int cgroup_may_write(const struct cgroup *cgrp, struct super_block *sb)if (!inode)return -ENOMEM ; - ret =inode_permission (inode,MAY_WRITE ); + ret =inode_permission (&init_user_ns, inode,MAY_WRITE );iput (inode);return ret; }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 05/39] namei: make permission helpers idmapped mount aware
Quoted 10 lines · Christian Brauner
The two helpers
inode_permission()andgeneric_permission()are used by the vfs to perform basic permission checking by verifying that the caller is privileged over an inode. In order to handle idmapped mounts we extend the two helpers with an additional user namespace argument. On idmapped mounts the two helpers will make sure to map the inode according to the mount's user namespace and then peform identical permission checks toinode_permission()andgeneric_permission(). If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Quoted 8 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Acked-by Serge Hallyn <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 05/39] namei: make permission helpers idmapped mount aware
In reply to Christian BraunerIf I NFS-exported an idmapped mount, I think I'd expect idmapped clients to see the mapped IDs.
Looks like that means taking the user namespace from the struct svc_export everwhere, for example:
fs/nfsd/nfsfh.c static int nfsd_acceptable(void *expv, struct dentry *dentry) · line 44
Quoted 10 lines · Christian Brauner
index
66f2ef67792a..8d90796e236a100644fs/nfsd/nfsfh.c +2
-1@@ -40,7 +40,8 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)/* make sure parents give x permission to user */ int err; parent =dget_parent (tdentry); - err =inode_permission (d_inode (parent),MAY_EXEC ); + err =inode_permission (&init_user_ns, +d_inode (parent),MAY_EXEC );
err = inode_permission(exp->ex_path.mnt->mnt_userns, d_inode(parent, MAY_EXEC);
?
--b.
Re: [PATCH v6 05/39] namei: make permission helpers idmapped mount aware
Quoted 7 lines · J. Bruce Fields
If I NFS-exported an idmapped mount, I think I'd expect idmapped clients to see the mapped IDs.
Looks like that means taking the user namespace from the struct
svc_exporteverwhere, for example:On Thu, Jan 21, 2021 at 02:19:24PM +0100, Christian Brauner wrote:
Quoted 13 lines
fs/nfsd/nfsfh.c static int nfsd_acceptable(void *expv, struct dentry *dentry) · line 44
Quoted 10 lines
index
66f2ef67792a..8d90796e236a100644fs/nfsd/nfsfh.c +2
-1@@ -40,7 +40,8 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)/* make sure parents give x permission to user */ int err; parent =dget_parent (tdentry); - err =inode_permission (d_inode (parent),MAY_EXEC ); + err =inode_permission (&init_user_ns, +d_inode (parent),MAY_EXEC );err = inode_permission(exp->ex_path.mnt->mnt_userns, d_inode(parent, MAY_EXEC);
Hey Bruce, thanks! Imho, the clean approach for now is to not export idmapped mounts until we have ported that part of nfs similar to what we do for stacking filesystems for now. I've tested and taken this patch into my tree:
---
From 7a6a53bca1ecd8db872de1ee81d1a57e1829e525 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sat, 23 Jan 2021 12:00:02 +0100
Subject: [PATCH] nfs: do not export idmapped mounts
Prevent nfs from exporting idmapped mounts until we have ported it to support exporting idmapped mounts.
---
/* v2 */
/* v3 */
/* v4 */
/* v5 */
/* v5 */
patch introduced
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/nfsd/export.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/nfsd/export.c +9 -3
@@ -369,8 +369,9 @@ static struct svc_export *svc_export_update(struct svc_export *new, struct svc_export *old);static struct svc_export *svc_export_lookup (struct svc_export *); -static int check_export (struct inode *inode,int *flags,unsigned char *uuid) +static int check_export (struct path *path,int *flags,unsigned char *uuid) { +struct inode *inode =d_inode (path->dentry);/* * We currently export only dirs, regular files, and (for v4
@@ -394,6 +395,7 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid)* or an FSID number (so NFSEXP_FSID or ->uuid is needed). * 2: We must be able to find an inode from a filehandle. * This means that s_export_op must be set. +* 3: We must not currently be on an idmapped mount. */ if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) && !(*flags & NFSEXP_FSID) &&
@@ -408,6 +410,11 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid)return -EINVAL ; } +if (mnt_user_ns (path->mnt) != &init_user_ns) { +dprintk ("exp_export: export of idmapped mounts not yet supported.\n" ); +return -EINVAL ; + } +if (inode->i_sb->s_export_op->flags &EXPORT_OP_NOSUBTREECHK && !(*flags &NFSEXP_NOSUBTREECHECK )) { dprintk("%s: %s does not support subtree checking!\n",
@@ -636,8 +643,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) goto out4; } - err =check_export (d_inode (exp.ex_path.dentry), &exp.ex_flags, - exp.ex_uuid); + err =check_export (&exp.ex_path, &exp.ex_flags, exp.ex_uuid);if (err) goto out4;/*
Signature · 1 line
2.30.0
Re: [PATCH v6 05/39] namei: make permission helpers idmapped mount aware
Quoted 22 lines · Christian Brauner
Quoted 7 lines · J. Bruce Fields
If I NFS-exported an idmapped mount, I think I'd expect idmapped clients to see the mapped IDs.
Looks like that means taking the user namespace from the struct
svc_exporteverwhere, for example:On Thu, Jan 21, 2021 at 02:19:24PM +0100, Christian Brauner wrote:
Quoted 13 lines
fs/nfsd/nfsfh.c static int nfsd_acceptable(void *expv, struct dentry *dentry) · line 44
Quoted 10 lines
index
66f2ef67792a..8d90796e236a100644fs/nfsd/nfsfh.c +2
-1@@ -40,7 +40,8 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)/* make sure parents give x permission to user */ int err; parent =dget_parent (tdentry); - err =inode_permission (d_inode (parent),MAY_EXEC ); + err =inode_permission (&init_user_ns, +d_inode (parent),MAY_EXEC );err = inode_permission(exp->ex_path.mnt->mnt_userns, d_inode(parent, MAY_EXEC);
Quoted 4 lines
Hey Bruce, thanks! Imho, the clean approach for now is to not export idmapped mounts until we have ported that part of nfs similar to what we do for stacking filesystems for now. I've tested and taken this patch into my tree:
Oh good, thanks. My real fear was that we'd fix this up later and leave users in a situation where the server exposes different IDs depending on kernel version, which would be a mess. Looks like this should avoid that.
As for making idmapped mounts actually work with nfsd--are you planning to do that, or do you need me to? I hope the patch is straightforward; I'm more worried testing it.
--b.
Quoted 79 lines
---
Quoted 1 line
From
7a6a53bca1ecd8db872de1ee81d1a57e1829e525Mon Sep 17 00:00:00 2001From: Christian Brauner <[email protected]>
Date: Sat, 23 Jan 2021 12:00:02 +0100
Subject: [PATCH] nfs: do not export idmapped mountsPrevent nfs from exporting idmapped mounts until we have ported it to support exporting idmapped mounts.
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc "J. Bruce Fields" <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 *//* v3 */
/* v4 */
/* v5 */
/* v5 */
patch introduced
base-commit:19c329f6808995b142b3966301f217c831e7cf31--- fs/nfsd/export.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)fs/nfsd/export.c +9
-3@@ -369,8 +369,9 @@ static struct svc_export *svc_export_update(struct svc_export *new, struct svc_export *old);static struct svc_export *svc_export_lookup (struct svc_export *); -static int check_export (struct inode *inode,int *flags,unsigned char *uuid) +static int check_export (struct path *path,int *flags,unsigned char *uuid) { +struct inode *inode =d_inode (path->dentry);/* * We currently export only dirs, regular files, and (for v4 @@ -394,6 +395,7 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid)* or an FSID number (so NFSEXP_FSID or ->uuid is needed). * 2: We must be able to find an inode from a filehandle. * This means that s_export_op must be set. +* 3: We must not currently be on an idmapped mount. */ if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) && !(*flags & NFSEXP_FSID) &&@@ -408,6 +410,11 @@ static int check_export(struct inode *inode, int *flags, unsigned char *uuid)return -EINVAL ; } +if (mnt_user_ns (path->mnt) != &init_user_ns) { +dprintk ("exp_export: export of idmapped mounts not yet supported.\n" ); +return -EINVAL ; + } +if (inode->i_sb->s_export_op->flags &EXPORT_OP_NOSUBTREECHK && !(*flags &NFSEXP_NOSUBTREECHECK )) { dprintk("%s: %s does not support subtree checking!\n",@@ -636,8 +643,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen) goto out4; } - err =check_export (d_inode (exp.ex_path.dentry), &exp.ex_flags, - exp.ex_uuid); + err =check_export (&exp.ex_path, &exp.ex_flags, exp.ex_uuid);if (err) goto out4;/* Signature · 1 line
2.30.0
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 05/39] namei: make permission helpers idmapped mount aware
Quoted 28 lines · J. Bruce Fields
Quoted 22 lines · Christian Brauner
Quoted 7 lines · J. Bruce Fields
If I NFS-exported an idmapped mount, I think I'd expect idmapped clients to see the mapped IDs.
Looks like that means taking the user namespace from the struct
svc_exporteverwhere, for example:On Thu, Jan 21, 2021 at 02:19:24PM +0100, Christian Brauner wrote:
Quoted 13 lines
fs/nfsd/nfsfh.c static int nfsd_acceptable(void *expv, struct dentry *dentry) · line 44
Quoted 10 lines
index
66f2ef67792a..8d90796e236a100644fs/nfsd/nfsfh.c +2
-1@@ -40,7 +40,8 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)/* make sure parents give x permission to user */ int err; parent =dget_parent (tdentry); - err =inode_permission (d_inode (parent),MAY_EXEC ); + err =inode_permission (&init_user_ns, +d_inode (parent),MAY_EXEC );err = inode_permission(exp->ex_path.mnt->mnt_userns, d_inode(parent, MAY_EXEC);Quoted 4 lines
Hey Bruce, thanks! Imho, the clean approach for now is to not export idmapped mounts until we have ported that part of nfs similar to what we do for stacking filesystems for now. I've tested and taken this patch into my tree:
Quoted 7 lines
Oh good, thanks. My real fear was that we'd fix this up later and leave users in a situation where the server exposes different IDs depending on kernel version, which would be a mess. Looks like this should avoid that.
As for making idmapped mounts actually work with nfsd--are you planning to do that, or do you need me to? I hope the patch is straightforward;
I'm happy to do it or help and there's other people I know who are also interested in that and would likely be happy to do the work too.
Quoted 1 line
I'm more worried testing it.
This whole series has a large xfstest patch associated with it that tests regular vfs behavior and vfs behavior with idmapped mounts. Iirc, xfstests also has infrastructure to test nfs. So I'd expect we expand the idmapped mounts testsuite to test nfs behavior as well. So far it has proven pretty helpful and has already unconvered an unrelated setgid-inheritance xfs bug that Christoph fixed a short time ago.
PATCH v6 6/40 inode: make init and permission helpers idmapped mount aware
In reply to Christian BraunerThe 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.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- Christoph Hellwig <[email protected]>:
- Change commit message to reflect the fact that no new permission helpers are introduced but only the existing ones changed.
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
- Note that inode_owner_or_capable() contains a comparison of the caller's fsuid to the inode's i_uid to determine whether the caller is the owner of the inode. Serge asked whether it is possible that the caller's fsuid is INVALID_UID. If so and i_uid_into_mnt() makes the inode's i_uid INVALID_UID too then the caller could potentially gain privilege over an inode it doesn't own. But this is not feasible since the callers fsuid should never be INVALID_UID unless we have a severe bug how we manage set*id() calls or cred management. Also, if it is possible that the caller's fsuid were to be INVALID_UID we might already have an issue in case a filesystem was mounted with an s_user_ns that doesn't contain a mapping for a inode that was created when the filesystem was mounted with a different user namespace.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
- Wrap long lines over 80 chars.
--- fs/9p/acl.c | 2 +- fs/9p/vfs_inode.c | 2 +- fs/attr.c | 6 +++--- fs/bfs/dir.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/ioctl.c | 10 +++++----- fs/btrfs/tests/btrfs-tests.c | 2 +- fs/crypto/policy.c | 2 +- fs/efivarfs/file.c | 2 +- fs/ext2/ialloc.c | 2 +- fs/ext2/ioctl.c | 6 +++--- fs/ext4/ialloc.c | 2 +- fs/ext4/ioctl.c | 15 ++++++++------- fs/f2fs/file.c | 14 +++++++------- fs/f2fs/namei.c | 2 +- fs/f2fs/xattr.c | 2 +- fs/fcntl.c | 2 +- fs/gfs2/file.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/hfsplus/ioctl.c | 2 +- fs/hugetlbfs/inode.c | 2 +- fs/inode.c | 36 ++++++++++++++++++++++++++---------- fs/jfs/ioctl.c | 2 +- fs/jfs/jfs_inode.c | 2 +- fs/minix/bitmap.c | 2 +- fs/namei.c | 5 +++-- fs/nilfs2/inode.c | 2 +- fs/nilfs2/ioctl.c | 2 +- fs/ocfs2/dlmfs/dlmfs.c | 4 ++-- fs/ocfs2/ioctl.c | 2 +- fs/ocfs2/namei.c | 2 +- fs/omfs/inode.c | 2 +- fs/overlayfs/dir.c | 2 +- fs/overlayfs/file.c | 4 ++-- fs/overlayfs/super.c | 2 +- fs/overlayfs/util.c | 2 +- fs/posix_acl.c | 2 +- fs/ramfs/inode.c | 2 +- fs/reiserfs/ioctl.c | 4 ++-- fs/reiserfs/namei.c | 2 +- fs/sysv/ialloc.c | 2 +- fs/ubifs/dir.c | 2 +- fs/ubifs/ioctl.c | 2 +- fs/udf/ialloc.c | 2 +- fs/ufs/ialloc.c | 2 +- fs/xattr.c | 3 ++- fs/xfs/xfs_ioctl.c | 2 +- fs/zonefs/super.c | 2 +- include/linux/fs.h | 8 ++++---- kernel/bpf/inode.c | 2 +- mm/madvise.c | 3 ++- mm/mincore.c | 3 ++- mm/shmem.c | 2 +- security/selinux/hooks.c | 4 ++-- 54 files changed, 112 insertions(+), 91 deletions(-)
fs/9p/acl.c +1 -1
@@ -258,7 +258,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,if (S_ISLNK (inode->i_mode))return -EOPNOTSUPP ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (value) {/* update the cached acl value */
fs/9p/vfs_inode.c +1 -1
@@ -251,7 +251,7 @@ int v9fs_init_inode(struct v9fs_session_info *v9ses, {int err =0 ; -inode_init_owner (inode,NULL , mode); +inode_init_owner (&init_user_ns,inode,NULL , mode); inode->i_blocks =0 ; inode->i_rdev = rdev; inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode);
fs/attr.c +3 -3
@@ -87,7 +87,7 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr)/* Make sure a caller can chmod. */ if (ia_valid & ATTR_MODE) { - if (!inode_owner_or_capable(inode)) + if (!inode_owner_or_capable(&init_user_ns, inode)) return -EPERM; /* Also check the setgid bit! */ if (!in_group_p((ia_valid & ATTR_GID) ? attr->ia_gid :
@@ -98,7 +98,7 @@ int setattr_prepare(struct dentry *dentry, struct iattr *attr)/* Check for setting the inode time. */ if (ia_valid & (ATTR_MTIME_SET |ATTR_ATIME_SET |ATTR_TIMES_SET )) { -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; }
@@ -243,7 +243,7 @@ int notify_change(struct dentry * dentry, struct iattr * attr, struct inode **deif (IS_IMMUTABLE (inode))return -EPERM ; -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { error =inode_permission (&init_user_ns, inode,MAY_WRITE );if (error)
fs/bfs/dir.c +1 -1
@@ -96,7 +96,7 @@ static int bfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, }set_bit (ino, info->si_imap); info->si_freei--; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); inode->i_blocks =0 ; inode->i_op = &bfs_file_inops;
fs/btrfs/inode.c +1 -1
@@ -6190,7 +6190,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,if (ret !=0 ) goto fail_unlock; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);inode_set_bytes (inode,0 ); inode->i_mtime =current_time (inode);
fs/btrfs/ioctl.c +5 -5
@@ -213,7 +213,7 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg)const char *comp =NULL ;u32 binode_flags; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (btrfs_root_readonly (root))
@@ -429,7 +429,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)unsigned old_i_flags;int ret =0 ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (btrfs_root_readonly (root))
@@ -1862,7 +1862,7 @@ static noinline int __btrfs_ioctl_snap_create(struct file *file,btrfs_info (BTRFS_I (file_inode (file))->root->fs_info,"Snapshot src from another FS" ); ret = -EXDEV ; - }else if (!inode_owner_or_capable (src_inode)) { + }else if (!inode_owner_or_capable (&init_user_ns, src_inode)) {/* * Subvolume creation is not restricted, but snapshots * are limited to own subvolumes only
@@ -1982,7 +1982,7 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,u64 flags;int ret =0 ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; ret =mnt_want_write_file (file);
@@ -4453,7 +4453,7 @@ static long _btrfs_ioctl_set_received_subvol(struct file *file,int ret =0 ;int received_uuid_changed; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; ret =mnt_want_write_file (file);
fs/btrfs/tests/btrfs-tests.c +1 -1
@@ -62,7 +62,7 @@ struct inode *btrfs_new_test_inode(void)BTRFS_I (inode)->location.type =BTRFS_INODE_ITEM_KEY ;BTRFS_I (inode)->location.objectid =BTRFS_FIRST_FREE_OBJECTID ;BTRFS_I (inode)->location.offset =0 ; -inode_init_owner (inode,NULL ,S_IFREG ); +inode_init_owner (&init_user_ns, inode,NULL ,S_IFREG );return inode; }
fs/crypto/policy.c +1 -1
@@ -465,7 +465,7 @@ int fscrypt_ioctl_set_policy(struct file *filp, const void __user *arg)return -EFAULT ; policy.version = version; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; ret =mnt_want_write_file (filp);
fs/efivarfs/file.c +1 -1
@@ -137,7 +137,7 @@ efivarfs_ioc_setxflags(struct file *file, void __user *arg)unsigned int oldflags =efivarfs_getflags (inode);int error; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (copy_from_user (&flags, arg,sizeof (flags)))
fs/ext2/ialloc.c +1 -1
@@ -551,7 +551,7 @@ struct inode *ext2_new_inode(struct inode *dir, umode_t mode, inode->i_uid =current_fsuid (); inode->i_gid = dir->i_gid; }else -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_ino = ino; inode->i_blocks =0 ;
fs/ext2/ioctl.c +3 -3
@@ -39,7 +39,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (ret)return ret; -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { ret = -EACCES ; goto setflags_out; }
@@ -84,7 +84,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT2_IOC_SETVERSION : {__u32 generation; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; ret =mnt_want_write_file (filp);if (ret)
@@ -117,7 +117,7 @@ long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (!test_opt (inode->i_sb,RESERVATION ) ||!S_ISREG (inode->i_mode))return -ENOTTY ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (get_user (rsv_window_size, (int __user *)arg))
fs/ext4/ialloc.c +1 -1
@@ -972,7 +972,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode *dir, inode->i_uid =current_fsuid (); inode->i_gid = dir->i_gid; }else -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);if (ext4_has_feature_project (sb) &&ext4_test_inode_flag (dir,EXT4_INODE_PROJINHERIT ))
fs/ext4/ioctl.c +8 -7
@@ -139,7 +139,8 @@ static long swap_inode_boot_loader(struct super_block *sb, }if (IS_RDONLY (inode) ||IS_APPEND (inode) ||IS_IMMUTABLE (inode) || - !inode_owner_or_capable (inode) || !capable (CAP_SYS_ADMIN )) { + !inode_owner_or_capable (&init_user_ns, inode) || + !capable (CAP_SYS_ADMIN )) { err = -EPERM ; goto journal_err_out; }
@@ -829,7 +830,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case FS_IOC_SETFLAGS : {int err; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (get_user (flags, (int __user *) arg))
@@ -871,7 +872,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)__u32 generation;int err; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (ext4_has_metadata_csum (inode->i_sb)) {
@@ -1010,7 +1011,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_MIGRATE : {int err; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; err =mnt_want_write_file (filp);
@@ -1032,7 +1033,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_ALLOC_DA_BLKS : {int err; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; err =mnt_want_write_file (filp);
@@ -1217,7 +1218,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)case EXT4_IOC_CLEAR_ES_CACHE : { -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;ext4_clear_inode_es (inode);return 0 ;
@@ -1263,7 +1264,7 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)return -EFAULT ;/* Make sure caller has proper permission */ -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (fa.fsx_xflags & ~EXT4_SUPPORTED_FS_XFLAGS )
fs/f2fs/file.c +7 -7
@@ -1961,7 +1961,7 @@ static int f2fs_ioc_setflags(struct file *filp, unsigned long arg)u32 iflags;int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (get_user (fsflags, (int __user *)arg))
@@ -2008,7 +2008,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp)struct f2fs_sb_info *sbi =F2FS_I_SB (inode);int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (!S_ISREG (inode->i_mode))
@@ -2075,7 +2075,7 @@ static int f2fs_ioc_commit_atomic_write(struct file *filp)struct inode *inode =file_inode (filp);int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; ret =mnt_want_write_file (filp);
@@ -2117,7 +2117,7 @@ static int f2fs_ioc_start_volatile_write(struct file *filp)struct inode *inode =file_inode (filp);int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (!S_ISREG (inode->i_mode))
@@ -2152,7 +2152,7 @@ static int f2fs_ioc_release_volatile_write(struct file *filp)struct inode *inode =file_inode (filp);int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; ret =mnt_want_write_file (filp);
@@ -2181,7 +2181,7 @@ static int f2fs_ioc_abort_volatile_write(struct file *filp)struct inode *inode =file_inode (filp);int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; ret =mnt_want_write_file (filp);
@@ -3158,7 +3158,7 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)return -EFAULT ;/* Make sure caller has proper permission */ -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (fa.fsx_xflags & ~F2FS_SUPPORTED_XFLAGS )
fs/f2fs/namei.c +1 -1
@@ -46,7 +46,7 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode) nid_free = true; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_ino = ino; inode->i_blocks =0 ;
fs/f2fs/xattr.c +1 -1
@@ -114,7 +114,7 @@ static int f2fs_xattr_advise_set(const struct xattr_handler *handler,unsigned char old_advise =F2FS_I (inode)->i_advise;unsigned char new_advise; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (value ==NULL )return -EINVAL ;
fs/fcntl.c +1 -1
@@ -46,7 +46,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)/* O_NOATIME can only be set by the owner or superuser */ if ((arg &O_NOATIME ) && !(filp->f_flags &O_NOATIME )) -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;/* required for strict SunOS emulation */
fs/gfs2/file.c +1 -1
@@ -238,7 +238,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask, goto out; error = -EACCES ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode)) goto out; error =0 ;
fs/hfsplus/inode.c +1 -1
@@ -376,7 +376,7 @@ struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,return NULL ; inode->i_ino = sbi->next_cnid++; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);set_nlink (inode,1 ); inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode);
fs/hfsplus/ioctl.c +1 -1
@@ -91,7 +91,7 @@ static int hfsplus_ioctl_setflags(struct file *file, int __user *user_flags)if (err) goto out; -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { err = -EACCES ; goto out_drop_write; }
fs/hugetlbfs/inode.c +1 -1
@@ -836,7 +836,7 @@ static struct inode *hugetlbfs_get_inode(struct super_block *sb,struct hugetlbfs_inode_info *info =HUGETLBFS_I (inode); inode->i_ino =get_next_ino (); -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);lockdep_set_class (&inode->i_mapping->i_mmap_rwsem, &hugetlbfs_i_mmap_rwsem_key); inode->i_mapping->a_ops = &hugetlbfs_aops;
fs/inode.c +26 -10
@@ -2130,14 +2130,21 @@ EXPORT_SYMBOL(init_special_inode);/** * inode_init_owner - Init uid,gid,mode for new inode according to posix standards +* @mnt_userns: User namespace of the mount the inode was created from * @inode: New inode * @dir: Directory inode * @mode: mode of the new inode +* +* If the inode has been created through an idmapped mount the user namespace of +* the vfsmount must be passed through @mnt_userns. This function will then take +* care to map the inode according to @mnt_userns before checking permissions +* and initializing i_uid and i_gid. On non-idmapped mounts or if permission +* checking is to be performed on the raw inode simply passs init_user_ns. */ -void inode_init_owner (struct inode *inode,const struct inode *dir, -umode_t mode) +void inode_init_owner (struct user_namespace *mnt_userns,struct inode *inode, +const struct inode *dir,umode_t mode) { - inode->i_uid =current_fsuid (); + inode->i_uid =fsuid_into_mnt (mnt_userns);if (dir && dir->i_mode &S_ISGID ) { inode->i_gid = dir->i_gid;
@@ -2145,32 +2152,41 @@ void inode_init_owner(struct inode *inode, const struct inode *dir,if (S_ISDIR (mode)) mode |=S_ISGID ;else if ((mode & (S_ISGID |S_IXGRP )) == (S_ISGID |S_IXGRP ) && - !in_group_p (inode->i_gid) && - !capable_wrt_inode_uidgid (&init_user_ns, dir, -CAP_FSETID )) + !in_group_p (i_gid_into_mnt (mnt_userns, dir)) && + !capable_wrt_inode_uidgid (mnt_userns, dir,CAP_FSETID )) mode &= ~S_ISGID ; }else - inode->i_gid =current_fsgid (); + inode->i_gid =fsgid_into_mnt (mnt_userns); inode->i_mode = mode; }EXPORT_SYMBOL (inode_init_owner);/** * inode_owner_or_capable - check current task permissions to inode +* @mnt_userns: user namespace of the mount the inode was found from * @inode: inode being checked * * Return true if current either has CAP_FOWNER in a namespace with the * inode owner uid mapped, or owns the file. +* +* If the inode has been found through an idmapped mount the user namespace of +* the vfsmount must be passed through @mnt_userns. This function will then take +* care to map the inode according to @mnt_userns before checking permissions. +* On non-idmapped mounts or if permission checking is to be performed on the +* raw inode simply passs init_user_ns. */ -bool inode_owner_or_capable (const struct inode *inode) +bool inode_owner_or_capable (struct user_namespace *mnt_userns, +const struct inode *inode) { +kuid_t i_uid;struct user_namespace *ns; -if (uid_eq (current_fsuid (), inode->i_uid)) + i_uid =i_uid_into_mnt (mnt_userns, inode); +if (uid_eq (current_fsuid (), i_uid))return true; ns =current_user_ns (); -if (kuid_has_mapping (ns, inode->i_uid) &&ns_capable (ns,CAP_FOWNER )) +if (kuid_has_mapping (ns, i_uid) &&ns_capable (ns,CAP_FOWNER ))return true;return false; }
fs/jfs/ioctl.c +1 -1
@@ -76,7 +76,7 @@ long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (err)return err; -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { err = -EACCES ; goto setflags_out; }
fs/jfs/jfs_inode.c +1 -1
@@ -64,7 +64,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode) goto fail_put; } -inode_init_owner (inode, parent, mode); +inode_init_owner (&init_user_ns, inode, parent, mode);/* * New inodes need to save sane values on disk when * uid & gid mount options are used
fs/minix/bitmap.c +1 -1
@@ -252,7 +252,7 @@ struct inode *minix_new_inode(const struct inode *dir, umode_t mode, int *error)iput (inode);return NULL ; } -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_ino = j; inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); inode->i_blocks =0 ;
fs/namei.c +3 -2
@@ -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 ;
fs/nilfs2/inode.c +1 -1
@@ -348,7 +348,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_t mode)/* reference count of i_bh inherits from nilfs_mdt_read_block() */ atomic64_inc (&root->inodes_count); -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_ino = ino; inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode);
fs/nilfs2/ioctl.c +1 -1
@@ -132,7 +132,7 @@ static int nilfs_ioctl_setflags(struct inode *inode, struct file *filp,unsigned int flags, oldflags;int ret; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (get_user (flags, (int __user *)argp))
fs/ocfs2/dlmfs/dlmfs.c +2 -2
@@ -329,7 +329,7 @@ static struct inode *dlmfs_get_root_inode(struct super_block *sb)if (inode) { inode->i_ino =get_next_ino (); -inode_init_owner (inode,NULL , mode); +inode_init_owner (&init_user_ns, inode,NULL , mode); inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode);inc_nlink (inode);
@@ -352,7 +352,7 @@ static struct inode *dlmfs_get_inode(struct inode *parent,return NULL ; inode->i_ino =get_next_ino (); -inode_init_owner (inode, parent, mode); +inode_init_owner (&init_user_ns, inode, parent, mode); inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode); ip =DLMFS_I (inode);
fs/ocfs2/ioctl.c +1 -1
@@ -96,7 +96,7 @@ static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags, } status = -EACCES ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode)) goto bail_unlock;if (!S_ISDIR (inode->i_mode))
fs/ocfs2/namei.c +1 -1
@@ -198,7 +198,7 @@ static struct inode *ocfs2_get_init_inode(struct inode *dir, umode_t mode)* callers. */ if (S_ISDIR (mode))set_nlink (inode,2 ); -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); status =dquot_initialize (inode);if (status)return ERR_PTR (status);
fs/omfs/inode.c +1 -1
@@ -48,7 +48,7 @@ struct inode *omfs_new_inode(struct inode *dir, umode_t mode) goto fail; inode->i_ino = new_block; -inode_init_owner (inode,NULL , mode); +inode_init_owner (&init_user_ns, inode,NULL , mode); inode->i_mapping->a_ops = &omfs_aops; inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode);
fs/overlayfs/dir.c +1 -1
@@ -636,7 +636,7 @@ static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev, inode->i_state |=I_CREATING ;spin_unlock (&inode->i_lock); -inode_init_owner (inode, dentry->d_parent->d_inode, mode); +inode_init_owner (&init_user_ns, inode, dentry->d_parent->d_inode, mode); attr.mode = inode->i_mode; err =ovl_create_or_link (dentry, inode, &attr, false);
fs/overlayfs/file.c +2 -2
@@ -54,7 +54,7 @@ static struct file *ovl_open_realfile(const struct file *file,if (err) { realfile =ERR_PTR (err); }else { -if (!inode_owner_or_capable (realinode)) +if (!inode_owner_or_capable (&init_user_ns, realinode)) flags &= ~O_NOATIME ; realfile = open_with_fake_path(&file->f_path, flags, realinode,
@@ -520,7 +520,7 @@ static long ovl_ioctl_set_flags(struct file *file, unsigned int cmd,long ret;struct inode *inode =file_inode (file); -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ; ret =mnt_want_write_file (file);
fs/overlayfs/super.c +1 -1
@@ -1005,7 +1005,7 @@ ovl_posix_acl_xattr_set(const struct xattr_handler *handler, goto out_acl_release; } err = -EPERM ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode)) goto out_acl_release;posix_acl_release (acl);
fs/overlayfs/util.c +1 -1
@@ -484,7 +484,7 @@ struct file *ovl_path_open(struct path *path, int flags)return ERR_PTR (err);/* O_NOATIME is an optimization, don't fail if not permitted */ -if (inode_owner_or_capable (inode)) +if (inode_owner_or_capable (&init_user_ns, inode)) flags |=O_NOATIME ;return dentry_open (path, flags,current_cred ());
fs/posix_acl.c +1 -1
@@ -874,7 +874,7 @@ set_posix_acl(struct inode *inode, int type, struct posix_acl *acl)if (type ==ACL_TYPE_DEFAULT && !S_ISDIR (inode->i_mode))return acl ? -EACCES :0 ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ;if (acl) {
fs/ramfs/inode.c +1 -1
@@ -67,7 +67,7 @@ struct inode *ramfs_get_inode(struct super_block *sb,if (inode) { inode->i_ino =get_next_ino (); -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_mapping->a_ops = &ramfs_aops;mapping_set_gfp_mask (inode->i_mapping,GFP_HIGHUSER );mapping_set_unevictable (inode->i_mapping);
fs/reiserfs/ioctl.c +2 -2
@@ -59,7 +59,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)if (err)break ; -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { err = -EPERM ; goto setflags_out; }
@@ -101,7 +101,7 @@ long reiserfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) err =put_user (inode->i_generation, (int __user *)arg);break ;case REISERFS_IOC_SETVERSION : -if (!inode_owner_or_capable (inode)) { +if (!inode_owner_or_capable (&init_user_ns, inode)) { err = -EPERM ;break ; }
fs/reiserfs/namei.c +1 -1
@@ -615,7 +615,7 @@ static int new_inode_init(struct inode *inode, struct inode *dir, umode_t mode)* the quota init calls have to know who to charge the quota to, so * we have to set uid and gid here */ -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);return dquot_initialize (inode); }
fs/sysv/ialloc.c +1 -1
@@ -163,7 +163,7 @@ struct inode * sysv_new_inode(const struct inode * dir, umode_t mode) *sbi->s_sb_fic_count =cpu_to_fs16 (sbi, count);fs16_add (sbi, sbi->s_sb_total_free_inodes,-1 );dirty_sb (sb); -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_ino =fs16_to_cpu (sbi, ino); inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); inode->i_blocks =0 ;
fs/ubifs/dir.c +1 -1
@@ -94,7 +94,7 @@ struct inode *ubifs_new_inode(struct ubifs_info *c, struct inode *dir,*/ inode->i_flags |=S_NOCMTIME ; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode); inode->i_mapping->nrpages =0 ;
fs/ubifs/ioctl.c +1 -1
@@ -155,7 +155,7 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (IS_RDONLY (inode))return -EROFS ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EACCES ;if (get_user (flags, (int __user *) arg))
fs/udf/ialloc.c +1 -1
@@ -103,7 +103,7 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode)mutex_unlock (&sbi->s_alloc_mutex); } -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);if (UDF_QUERY_FLAG (sb,UDF_FLAG_UID_SET )) inode->i_uid = sbi->s_uid;if (UDF_QUERY_FLAG (sb,UDF_FLAG_GID_SET ))
fs/ufs/ialloc.c +1 -1
@@ -289,7 +289,7 @@ struct inode *ufs_new_inode(struct inode *dir, umode_t mode)ufs_mark_sb_dirty (sb); inode->i_ino = cg * uspi->s_ipg + bit; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_blocks =0 ; inode->i_generation =0 ; inode->i_mtime = inode->i_atime = inode->i_ctime =current_time (inode);
fs/xattr.c +2 -1
@@ -127,7 +127,8 @@ xattr_permission(struct inode *inode, const char *name, int mask)if (!S_ISREG (inode->i_mode) && !S_ISDIR (inode->i_mode))return (mask &MAY_WRITE ) ? -EPERM : -ENODATA ;if (S_ISDIR (inode->i_mode) && (inode->i_mode &S_ISVTX ) && - (mask &MAY_WRITE ) && !inode_owner_or_capable (inode)) + (mask &MAY_WRITE ) && + !inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; }
fs/xfs/xfs_ioctl.c +1 -1
@@ -1300,7 +1300,7 @@ xfs_ioctl_setattr_get_trans(* The user ID of the calling process must be equal to the file owner * ID, except in cases where the CAP_FSETID capability is applicable. */ -if (!inode_owner_or_capable (VFS_I (ip))) { +if (!inode_owner_or_capable (&init_user_ns,VFS_I (ip))) { error = -EPERM ; goto out_cancel; }
fs/zonefs/super.c +1 -1
@@ -1223,7 +1223,7 @@ static void zonefs_init_dir_inode(struct inode *parent, struct inode *inode,struct super_block *sb = parent->i_sb; inode->i_ino =blkdev_nr_zones (sb->s_bdev->bd_disk) + type +1 ; -inode_init_owner (inode, parent,S_IFDIR |0555 ); +inode_init_owner (&init_user_ns, inode, parent,S_IFDIR |0555 ); inode->i_op = &zonefs_dir_inode_operations; inode->i_fop = &simple_dir_operations;set_nlink (inode,2 );
include/linux/fs.h +4 -4
@@ -1762,8 +1762,8 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb)return __sb_start_write_trylock (sb,SB_FREEZE_FS ); } - -extern bool inode_owner_or_capable (const struct inode *inode); +bool inode_owner_or_capable (struct user_namespace *mnt_userns, +const struct inode *inode);/* * VFS helper functions..
@@ -1805,8 +1805,8 @@ extern long compat_ptr_ioctl(struct file *file, unsigned int cmd,/* * VFS file helper functions. */ -extern void inode_init_owner (struct inode *inode,const struct inode *dir, -umode_t mode); +void inode_init_owner (struct user_namespace *mnt_userns,struct inode *inode, +const struct inode *dir,umode_t mode);extern bool may_open_dev (const struct path *path);/*
kernel/bpf/inode.c +1 -1
@@ -122,7 +122,7 @@ static struct inode *bpf_get_inode(struct super_block *sb, inode->i_mtime = inode->i_atime; inode->i_ctime = inode->i_atime; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode);return inode; }
mm/madvise.c +2 -1
@@ -539,7 +539,8 @@ static inline bool can_do_pageout(struct vm_area_struct *vma)* otherwise we'd be including shared non-exclusive mappings, which * opens a side channel. */ -return inode_owner_or_capable (file_inode (vma->vm_file)) || +return inode_owner_or_capable (&init_user_ns, +file_inode (vma->vm_file)) ||file_permission (vma->vm_file,MAY_WRITE ) ==0 ; }
mm/mincore.c +2 -1
@@ -166,7 +166,8 @@ static inline bool can_do_mincore(struct vm_area_struct *vma)* for writing; otherwise we'd be including shared non-exclusive * mappings, which opens a side channel. */ -return inode_owner_or_capable (file_inode (vma->vm_file)) || +return inode_owner_or_capable (&init_user_ns, +file_inode (vma->vm_file)) ||file_permission (vma->vm_file,MAY_WRITE ) ==0 ; }
mm/shmem.c +1 -1
@@ -2303,7 +2303,7 @@ static struct inode *shmem_get_inode(struct super_block *sb, const struct inode inode =new_inode (sb);if (inode) { inode->i_ino = ino; -inode_init_owner (inode, dir, mode); +inode_init_owner (&init_user_ns, inode, dir, mode); inode->i_blocks =0 ; inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode); inode->i_generation =prandom_u32 ();
security/selinux/hooks.c +2 -2
@@ -3140,13 +3140,13 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, }if (!selinux_initialized (&selinux_state)) -return (inode_owner_or_capable (inode) ?0 : -EPERM ); +return (inode_owner_or_capable (&init_user_ns, inode) ?0 : -EPERM ); sbsec = inode->i_sb->s_security;if (!(sbsec->flags &SBLABEL_MNT ))return -EOPNOTSUPP ; -if (!inode_owner_or_capable (inode)) +if (!inode_owner_or_capable (&init_user_ns, inode))return -EPERM ; ad.type =LSM_AUDIT_DATA_DENTRY ;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 06/40] inode: make init and permission helpers idmapped mount aware
Quoted 14 lines · Christian Brauner
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.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
PATCH v6 7/40 attr: handle idmapped mounts
In reply to Christian BraunerWhen file attributes are changed most filesystems rely on the setattr_prepare(), setattr_copy(), and notify_change() helpers for initialization and permission checking. Let them handle idmapped mounts. If the inode is accessed through an idmapped mount map it into 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.
Helpers that perform checks on the ia_uid and ia_gid fields in struct iattr assume that ia_uid and ia_gid are intended values and have already been mapped correctly at the userspace-kernelspace boundary as we already do today. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
- kernel test robot <[email protected]>:
- Adapt __setattr_copy() in fs/f2fs when CONFIG_F2FS_FS_POSIX_ACL is selected.
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
--- arch/powerpc/platforms/cell/spufs/inode.c | 2 +- drivers/base/devtmpfs.c | 4 +- fs/9p/vfs_inode.c | 4 +- fs/9p/vfs_inode_dotl.c | 4 +- fs/adfs/inode.c | 2 +- fs/affs/inode.c | 4 +- fs/attr.c | 119 ++++++++++++++++------ fs/btrfs/inode.c | 4 +- fs/cachefiles/interface.c | 4 +- fs/ceph/inode.c | 2 +- fs/cifs/inode.c | 8 +- fs/ecryptfs/inode.c | 7 +- fs/exfat/file.c | 4 +- fs/ext2/inode.c | 4 +- fs/ext4/inode.c | 4 +- fs/f2fs/file.c | 10 +- fs/fat/file.c | 4 +- fs/fuse/dir.c | 2 +- fs/gfs2/inode.c | 4 +- fs/hfs/inode.c | 4 +- fs/hfsplus/inode.c | 4 +- fs/hostfs/hostfs_kern.c | 4 +- fs/hpfs/inode.c | 4 +- fs/hugetlbfs/inode.c | 4 +- fs/inode.c | 2 +- fs/jffs2/fs.c | 2 +- fs/jfs/file.c | 4 +- fs/kernfs/inode.c | 4 +- fs/libfs.c | 4 +- fs/minix/file.c | 4 +- fs/nfsd/nfsproc.c | 2 +- fs/nfsd/vfs.c | 4 +- fs/nilfs2/inode.c | 4 +- fs/ntfs/inode.c | 2 +- fs/ocfs2/dlmfs/dlmfs.c | 4 +- fs/ocfs2/file.c | 4 +- fs/omfs/file.c | 4 +- fs/open.c | 8 +- fs/orangefs/inode.c | 4 +- fs/overlayfs/copy_up.c | 8 +- fs/overlayfs/dir.c | 2 +- fs/overlayfs/inode.c | 4 +- fs/overlayfs/super.c | 2 +- fs/proc/base.c | 4 +- fs/proc/generic.c | 4 +- fs/proc/proc_sysctl.c | 4 +- fs/ramfs/file-nommu.c | 4 +- fs/reiserfs/inode.c | 4 +- fs/sysv/file.c | 4 +- fs/ubifs/file.c | 2 +- fs/udf/file.c | 4 +- fs/ufs/inode.c | 4 +- fs/utimes.c | 3 +- fs/xfs/xfs_iops.c | 2 +- fs/zonefs/super.c | 4 +- include/linux/fs.h | 8 +- mm/shmem.c | 4 +- 57 files changed, 206 insertions(+), 137 deletions(-)
arch/powerpc/platforms/cell/spufs/inode.c +1 -1
@@ -98,7 +98,7 @@ spufs_setattr(struct dentry *dentry, struct iattr *attr)if ((attr->ia_valid &ATTR_SIZE ) && (attr->ia_size != inode->i_size))return -EINVAL ; -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
drivers/base/devtmpfs.c +2 -2
@@ -221,7 +221,7 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid, newattrs.ia_gid = gid; newattrs.ia_valid =ATTR_MODE |ATTR_UID |ATTR_GID ;inode_lock (d_inode (dentry)); -notify_change (dentry, &newattrs,NULL ); +notify_change (&init_user_ns, dentry, &newattrs,NULL );inode_unlock (d_inode (dentry));/* mark as kernel-created inode */
@@ -328,7 +328,7 @@ static int handle_remove(const char *nodename, struct device *dev) newattrs.ia_valid =ATTR_UID |ATTR_GID |ATTR_MODE ;inode_lock (d_inode (dentry)); -notify_change (dentry, &newattrs,NULL ); +notify_change (&init_user_ns, dentry, &newattrs,NULL );inode_unlock (d_inode (dentry)); err =vfs_unlink (d_inode (parent.dentry), dentry,NULL );if (!err || err == -ENOENT )
fs/9p/vfs_inode.c +2 -2
@@ -1062,7 +1062,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)struct p9_wstat wstat;p9_debug (P9_DEBUG_VFS ,"\n" ); - retval =setattr_prepare (dentry, iattr); + retval =setattr_prepare (&init_user_ns, dentry, iattr);if (retval)return retval;
@@ -1118,7 +1118,7 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)v9fs_invalidate_inode_attr (d_inode (dentry)); -setattr_copy (d_inode (dentry), iattr); +setattr_copy (&init_user_ns,d_inode (dentry), iattr);mark_inode_dirty (d_inode (dentry));return 0 ; }
fs/9p/vfs_inode_dotl.c +2 -2
@@ -549,7 +549,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)p9_debug (P9_DEBUG_VFS ,"\n" ); - retval =setattr_prepare (dentry, iattr); + retval =setattr_prepare (&init_user_ns, dentry, iattr);if (retval)return retval;
@@ -590,7 +590,7 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)truncate_setsize (inode, iattr->ia_size);v9fs_invalidate_inode_attr (inode); -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);mark_inode_dirty (inode);if (iattr->ia_valid &ATTR_MODE ) {/* We also want to update ACL when we update mode bits */
fs/adfs/inode.c +1 -1
@@ -299,7 +299,7 @@ adfs_notify_change(struct dentry *dentry, struct iattr *attr)unsigned int ia_valid = attr->ia_valid;int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);/* * we can't change the UID or GID of any file -
fs/affs/inode.c +2 -2
@@ -223,7 +223,7 @@ affs_notify_change(struct dentry *dentry, struct iattr *attr)pr_debug ("notify_change(%lu,0x%x)\n" , inode->i_ino, attr->ia_valid); - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error) goto out;
@@ -249,7 +249,7 @@ affs_notify_change(struct dentry *dentry, struct iattr *attr)affs_truncate (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);if (attr->ia_valid &ATTR_MODE )
fs/attr.c +90 -29
226 lines not on this page · raw message
fs/btrfs/inode.c +2 -2
@@ -5054,7 +5054,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)if (btrfs_root_readonly (root))return -EROFS ; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
@@ -5065,7 +5065,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) }if (attr->ia_valid) { -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);inode_inc_iversion (inode); err =btrfs_dirty_inode (inode);
fs/cachefiles/interface.c +2 -2
@@ -470,14 +470,14 @@ static int cachefiles_attr_changed(struct fscache_object *_object)_debug ("discard tail %llx" , oi_size); newattrs.ia_valid =ATTR_SIZE ; newattrs.ia_size = oi_size &PAGE_MASK ; - ret =notify_change (object->backer, &newattrs,NULL ); + ret =notify_change (&init_user_ns, object->backer, &newattrs,NULL );if (ret <0 ) goto truncate_failed; } newattrs.ia_valid =ATTR_SIZE ; newattrs.ia_size = ni_size; - ret =notify_change (object->backer, &newattrs,NULL ); + ret =notify_change (&init_user_ns, object->backer, &newattrs,NULL ); truncate_failed:inode_unlock (d_inode (object->backer));
fs/ceph/inode.c +1 -1
@@ -2247,7 +2247,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr)if (ceph_snap (inode) !=CEPH_NOSNAP )return -EROFS ; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err !=0 )return err;
fs/cifs/inode.c +4 -4
@@ -2610,7 +2610,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NO_PERM ) attrs->ia_valid |=ATTR_FORCE ; - rc =setattr_prepare (direntry, attrs); + rc =setattr_prepare (&init_user_ns, direntry, attrs);if (rc <0 ) goto out;
@@ -2715,7 +2715,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) attrs->ia_size != i_size_read(inode))truncate_setsize (inode, attrs->ia_size); -setattr_copy (inode, attrs); +setattr_copy (&init_user_ns, inode, attrs);mark_inode_dirty (inode);/* force revalidate when any of these times are set since some
@@ -2757,7 +2757,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_NO_PERM ) attrs->ia_valid |=ATTR_FORCE ; - rc =setattr_prepare (direntry, attrs); + rc =setattr_prepare (&init_user_ns, direntry, attrs);if (rc <0 ) {free_xid (xid);return rc;
@@ -2913,7 +2913,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) attrs->ia_size != i_size_read(inode))truncate_setsize (inode, attrs->ia_size); -setattr_copy (inode, attrs); +setattr_copy (&init_user_ns, inode, attrs);mark_inode_dirty (inode); cifs_setattr_exit:
fs/ecryptfs/inode.c +4 -3
@@ -855,7 +855,8 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)struct dentry *lower_dentry =ecryptfs_dentry_to_lower (dentry);inode_lock (d_inode (lower_dentry)); - rc =notify_change (lower_dentry, &lower_ia,NULL ); + rc =notify_change (&init_user_ns, lower_dentry, + &lower_ia,NULL );inode_unlock (d_inode (lower_dentry)); }return rc;
@@ -934,7 +935,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) }mutex_unlock (&crypt_stat->cs_mutex); - rc =setattr_prepare (dentry, ia); + rc =setattr_prepare (&init_user_ns, dentry, ia);if (rc) goto out;if (ia->ia_valid &ATTR_SIZE ) {
@@ -960,7 +961,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) lower_ia.ia_valid &= ~ATTR_MODE ;inode_lock (d_inode (lower_dentry)); - rc =notify_change (lower_dentry, &lower_ia,NULL ); + rc =notify_change (&init_user_ns, lower_dentry, &lower_ia,NULL );inode_unlock (d_inode (lower_dentry)); out:fsstack_copy_attr_all (inode, lower_inode);
fs/exfat/file.c +2 -2
@@ -305,7 +305,7 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr) ATTR_TIMES_SET); } - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr); attr->ia_valid = ia_valid;if (error) goto out;
@@ -340,7 +340,7 @@ int exfat_setattr(struct dentry *dentry, struct iattr *attr)up_write (&EXFAT_I (inode)->truncate_lock); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);exfat_truncate_atime (&inode->i_atime);mark_inode_dirty (inode);
fs/ext2/inode.c +2 -2
@@ -1669,7 +1669,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, iattr); + error =setattr_prepare (&init_user_ns, dentry, iattr);if (error)return error;
@@ -1689,7 +1689,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)if (error)return error; } -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);if (iattr->ia_valid &ATTR_MODE ) error =posix_acl_chmod (inode, inode->i_mode);mark_inode_dirty (inode);
fs/ext4/inode.c +2 -2
@@ -5337,7 +5337,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) ATTR_GID | ATTR_TIMES_SET))))return -EPERM ; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -5512,7 +5512,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) }if (!error) { -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode); }
fs/f2fs/file.c +6 -4
@@ -831,7 +831,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, }#ifdef CONFIG_F2FS_FS_POSIX_ACL -static void __setattr_copy (struct inode *inode,const struct iattr *attr) +static void __setattr_copy (struct user_namespace *mnt_userns,struct inode *inode, +const struct iattr *attr) {unsigned int ia_valid = attr->ia_valid;
@@ -847,8 +848,9 @@ static void __setattr_copy(struct inode *inode, const struct iattr *attr) inode->i_ctime = attr->ia_ctime;if (ia_valid &ATTR_MODE ) {umode_t mode = attr->ia_mode; +kgid_t kgid =i_gid_into_mnt (mnt_userns, inode); -if (!in_group_p (inode->i_gid) && !capable (CAP_FSETID )) +if (!in_group_p (kgid) && !capable (CAP_FSETID )) mode &= ~S_ISGID ;set_acl_inode (inode, mode); }
@@ -869,7 +871,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) !f2fs_is_compress_backend_ready(inode))return -EOPNOTSUPP ; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
@@ -945,7 +947,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)spin_unlock (&F2FS_I (inode)->i_size_lock); } -__setattr_copy (inode, attr); +__setattr_copy (&init_user_ns, inode, attr);if (attr->ia_valid &ATTR_MODE ) { err =posix_acl_chmod (inode,f2fs_get_inode_mode (inode));
fs/fat/file.c +2 -2
@@ -480,7 +480,7 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_valid &= ~TIMES_SET_FLAGS ; } - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr); attr->ia_valid = ia_valid;if (error) {if (sbi->options.quiet)
@@ -550,7 +550,7 @@ int fat_setattr(struct dentry *dentry, struct iattr *attr)fat_truncate_time (inode, &attr->ia_mtime,S_MTIME ); attr->ia_valid &= ~(ATTR_ATIME |ATTR_CTIME |ATTR_MTIME ); -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode); out:return error;
fs/fuse/dir.c +1 -1
@@ -1611,7 +1611,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,if (!fc->default_permissions) attr->ia_valid |=ATTR_FORCE ; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
fs/gfs2/inode.c +2 -2
@@ -1861,7 +1861,7 @@ int gfs2_permission(struct inode *inode, int mask)static int __gfs2_setattr_simple (struct inode *inode,struct iattr *attr) { -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
@@ -1982,7 +1982,7 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) goto error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error) goto error;
fs/hfs/inode.c +2 -2
@@ -608,7 +608,7 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)struct hfs_sb_info *hsb =HFS_SB (inode->i_sb);int error; - error =setattr_prepare (dentry, attr);/* basic permission checks */ + error =setattr_prepare (&init_user_ns, dentry, attr);/* basic permission checks */ if (error)return error;
@@ -647,7 +647,7 @@ int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)current_time (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/hfsplus/inode.c +2 -2
@@ -246,7 +246,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -264,7 +264,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct iattr *attr) inode->i_mtime = inode->i_ctime =current_time (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ;
fs/hostfs/hostfs_kern.c +2 -2
@@ -792,7 +792,7 @@ static int hostfs_setattr(struct dentry *dentry, struct iattr *attr)int fd =HOSTFS_I (inode)->fd; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
@@ -849,7 +849,7 @@ static int hostfs_setattr(struct dentry *dentry, struct iattr *attr) attr->ia_size != i_size_read(inode))truncate_setsize (inode, attr->ia_size); -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/hpfs/inode.c +2 -2
@@ -274,7 +274,7 @@ int hpfs_setattr(struct dentry *dentry, struct iattr *attr)if ((attr->ia_valid &ATTR_SIZE ) && attr->ia_size > inode->i_size) goto out_unlock; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error) goto out_unlock;
@@ -288,7 +288,7 @@ int hpfs_setattr(struct dentry *dentry, struct iattr *attr)hpfs_truncate (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);hpfs_write_inode (inode);
fs/hugetlbfs/inode.c +2 -2
@@ -761,7 +761,7 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)BUG_ON (!inode); - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -780,7 +780,7 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr)return error; } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/inode.c +1 -1
@@ -1912,7 +1912,7 @@ static int __remove_privs(struct dentry *dentry, int kill)* Note we call this on write, so notify_change will not * encounter any conflicting delegations: */ -return notify_change (dentry, &newattrs,NULL ); +return notify_change (&init_user_ns, dentry, &newattrs,NULL ); }/*
fs/jffs2/fs.c +1 -1
@@ -195,7 +195,7 @@ int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)struct inode *inode =d_inode (dentry);int rc; - rc =setattr_prepare (dentry, iattr); + rc =setattr_prepare (&init_user_ns, dentry, iattr);if (rc)return rc;
fs/jfs/file.c +2 -2
@@ -90,7 +90,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)struct inode *inode =d_inode (dentry);int rc; - rc =setattr_prepare (dentry, iattr); + rc =setattr_prepare (&init_user_ns, dentry, iattr);if (rc)return rc;
@@ -118,7 +118,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)jfs_truncate (inode); } -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);mark_inode_dirty (inode);if (iattr->ia_valid &ATTR_MODE )
fs/kernfs/inode.c +2 -2
@@ -122,7 +122,7 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr)return -EINVAL ;mutex_lock (&kernfs_mutex); - error =setattr_prepare (dentry, iattr); + error =setattr_prepare (&init_user_ns, dentry, iattr);if (error) goto out;
@@ -131,7 +131,7 @@ int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr) goto out;/* this ignores size changes */ -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr); out:mutex_unlock (&kernfs_mutex);
fs/libfs.c +2 -2
@@ -497,13 +497,13 @@ int simple_setattr(struct dentry *dentry, struct iattr *iattr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, iattr); + error =setattr_prepare (&init_user_ns, dentry, iattr);if (error)return error;if (iattr->ia_valid &ATTR_SIZE )truncate_setsize (inode, iattr->ia_size); -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);mark_inode_dirty (inode);return 0 ; }
fs/minix/file.c +2 -2
@@ -27,7 +27,7 @@ static int minix_setattr(struct dentry *dentry, struct iattr *attr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -41,7 +41,7 @@ static int minix_setattr(struct dentry *dentry, struct iattr *attr)minix_truncate (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/nfsd/nfsproc.c +1 -1
@@ -90,7 +90,7 @@ nfsd_proc_setattr(struct svc_rqst *rqstp)if (delta <0 ) delta = -delta;if (delta <MAX_TOUCH_TIME_ERROR && -setattr_prepare (fhp->fh_dentry, iap) !=0 ) { +setattr_prepare (&init_user_ns, fhp->fh_dentry, iap) !=0 ) {/* * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME. * This will cause notify_change to set these times
fs/nfsd/vfs.c +2 -2
@@ -448,7 +448,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap, .ia_size = iap->ia_size, }; - host_err =notify_change (dentry, &size_attr,NULL ); + host_err =notify_change (&init_user_ns, dentry, &size_attr,NULL );if (host_err) goto out_unlock; iap->ia_valid &= ~ATTR_SIZE ;
@@ -463,7 +463,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap, } iap->ia_valid |=ATTR_CTIME ; - host_err =notify_change (dentry, iap,NULL ); + host_err =notify_change (&init_user_ns, dentry, iap,NULL ); out_unlock:fh_unlock (fhp);
fs/nilfs2/inode.c +2 -2
@@ -812,7 +812,7 @@ int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)struct super_block *sb = inode->i_sb;int err; - err =setattr_prepare (dentry, iattr); + err =setattr_prepare (&init_user_ns, dentry, iattr);if (err)return err;
@@ -827,7 +827,7 @@ int nilfs_setattr(struct dentry *dentry, struct iattr *iattr)nilfs_truncate (inode); } -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);mark_inode_dirty (inode);if (iattr->ia_valid &ATTR_MODE ) {
fs/ntfs/inode.c +1 -1
@@ -2866,7 +2866,7 @@ int ntfs_setattr(struct dentry *dentry, struct iattr *attr)int err;unsigned int ia_valid = attr->ia_valid; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err) goto out;/* We do not support NTFS ACLs yet. */
fs/ocfs2/dlmfs/dlmfs.c +2 -2
@@ -196,11 +196,11 @@ static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr)struct inode *inode =d_inode (dentry); attr->ia_valid &= ~ATTR_SIZE ; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error; -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/ocfs2/file.c +2 -2
@@ -1142,7 +1142,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr)if (!(attr->ia_valid &OCFS2_VALID_ATTRS ))return 0 ; - status =setattr_prepare (dentry, attr); + status =setattr_prepare (&init_user_ns, dentry, attr);if (status)return status;
@@ -1263,7 +1263,7 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) } } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode); status =ocfs2_mark_inode_dirty (handle, inode, bh);
fs/omfs/file.c +2 -2
@@ -348,7 +348,7 @@ static int omfs_setattr(struct dentry *dentry, struct iattr *attr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -361,7 +361,7 @@ static int omfs_setattr(struct dentry *dentry, struct iattr *attr)omfs_truncate (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/open.c +5 -3
@@ -61,7 +61,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,inode_lock (dentry->d_inode);/* Note any delegations or leases have already been broken: */ - ret =notify_change (dentry, &newattrs,NULL ); + ret =notify_change (&init_user_ns, dentry, &newattrs,NULL );inode_unlock (dentry->d_inode);return ret; }
@@ -580,7 +580,8 @@ int chmod_common(const struct path *path, umode_t mode) goto out_unlock; newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; - error =notify_change (path->dentry, &newattrs, &delegated_inode); + error =notify_change (&init_user_ns, path->dentry, &newattrs, + &delegated_inode); out_unlock:inode_unlock (inode);if (delegated_inode) {
@@ -671,7 +672,8 @@ int chown_common(const struct path *path, uid_t user, gid_t group)inode_lock (inode); error =security_path_chown (path, uid, gid);if (!error) - error =notify_change (path->dentry, &newattrs, &delegated_inode); + error =notify_change (&init_user_ns, path->dentry, &newattrs, + &delegated_inode);inode_unlock (inode);if (delegated_inode) { error =break_deleg_wait (&delegated_inode);
fs/orangefs/inode.c +2 -2
@@ -855,7 +855,7 @@ int __orangefs_setattr(struct inode *inode, struct iattr *iattr)ORANGEFS_I (inode)->attr_uid =current_fsuid ();ORANGEFS_I (inode)->attr_gid =current_fsgid (); } -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);spin_unlock (&inode->i_lock);mark_inode_dirty (inode);
@@ -876,7 +876,7 @@ int orangefs_setattr(struct dentry *dentry, struct iattr *iattr)int ret;gossip_debug (GOSSIP_INODE_DEBUG ,"__orangefs_setattr: called on %pd\n" , dentry); - ret =setattr_prepare (dentry, iattr); + ret =setattr_prepare (&init_user_ns, dentry, iattr);if (ret) goto out; ret =__orangefs_setattr (d_inode (dentry), iattr);
fs/overlayfs/copy_up.c +4 -4
@@ -235,7 +235,7 @@ static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat) .ia_size = stat->size, }; -return notify_change (upperdentry, &attr,NULL ); +return notify_change (&init_user_ns, upperdentry, &attr,NULL ); }static int ovl_set_timestamps (struct dentry *upperdentry,struct kstat *stat)
@@ -247,7 +247,7 @@ static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat) .ia_mtime = stat->mtime, }; -return notify_change (upperdentry, &attr,NULL ); +return notify_change (&init_user_ns, upperdentry, &attr,NULL ); }int ovl_set_attr (struct dentry *upperdentry,struct kstat *stat)
@@ -259,7 +259,7 @@ int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat) .ia_valid = ATTR_MODE, .ia_mode = stat->mode, }; - err =notify_change (upperdentry, &attr,NULL ); + err =notify_change (&init_user_ns, upperdentry, &attr,NULL ); }if (!err) {struct iattr attr = {
@@ -267,7 +267,7 @@ int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat) .ia_uid = stat->uid, .ia_gid = stat->gid, }; - err =notify_change (upperdentry, &attr,NULL ); + err =notify_change (&init_user_ns, upperdentry, &attr,NULL ); }if (!err)ovl_set_timestamps (upperdentry, stat);
fs/overlayfs/dir.c +1 -1
@@ -508,7 +508,7 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, .ia_mode = cattr->mode, };inode_lock (newdentry->d_inode); - err =notify_change (newdentry, &attr,NULL ); + err =notify_change (&init_user_ns, newdentry, &attr,NULL );inode_unlock (newdentry->d_inode);if (err) goto out_cleanup;
fs/overlayfs/inode.c +2 -2
@@ -21,7 +21,7 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)struct dentry *upperdentry;const struct cred *old_cred; - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
@@ -79,7 +79,7 @@ int ovl_setattr(struct dentry *dentry, struct iattr *attr)inode_lock (upperdentry->d_inode); old_cred =ovl_override_creds (dentry->d_sb); - err =notify_change (upperdentry, attr,NULL ); + err =notify_change (&init_user_ns, upperdentry, attr,NULL );revert_creds (old_cred);if (!err)ovl_copyattr (upperdentry->d_inode, dentry->d_inode);
fs/overlayfs/super.c +1 -1
@@ -804,7 +804,7 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,/* Clear any inherited mode bits */ inode_lock (work->d_inode); - err =notify_change (work, &attr,NULL ); + err =notify_change (&init_user_ns, work, &attr,NULL );inode_unlock (work->d_inode);if (err) goto out_dput;
fs/proc/base.c +2 -2
@@ -693,11 +693,11 @@ int proc_setattr(struct dentry *dentry, struct iattr *attr)if (attr->ia_valid &ATTR_MODE )return -EPERM ; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error; -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/proc/generic.c +2 -2
@@ -121,11 +121,11 @@ static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)struct proc_dir_entry *de =PDE (inode);int error; - error =setattr_prepare (dentry, iattr); + error =setattr_prepare (&init_user_ns, dentry, iattr);if (error)return error; -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);mark_inode_dirty (inode);proc_set_user (de, inode->i_uid, inode->i_gid);
fs/proc/proc_sysctl.c +2 -2
@@ -821,11 +821,11 @@ static int proc_sys_setattr(struct dentry *dentry, struct iattr *attr)if (attr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID ))return -EPERM ; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error; -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/ramfs/file-nommu.c +2 -2
@@ -165,7 +165,7 @@ static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia)int ret =0 ;/* POSIX UID/GID verification for setting inode attributes */ - ret =setattr_prepare (dentry, ia); + ret =setattr_prepare (&init_user_ns, dentry, ia);if (ret)return ret;
@@ -185,7 +185,7 @@ static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia) } } -setattr_copy (inode, ia); +setattr_copy (&init_user_ns, inode, ia); out: ia->ia_valid = old_ia_valid;return ret;
fs/reiserfs/inode.c +2 -2
@@ -3288,7 +3288,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)unsigned int ia_valid;int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -3413,7 +3413,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr) }if (!error) { -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode); }
fs/sysv/file.c +2 -2
@@ -34,7 +34,7 @@ static int sysv_setattr(struct dentry *dentry, struct iattr *attr)struct inode *inode =d_inode (dentry);int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -47,7 +47,7 @@ static int sysv_setattr(struct dentry *dentry, struct iattr *attr)sysv_truncate (inode); } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/ubifs/file.c +1 -1
@@ -1265,7 +1265,7 @@ int ubifs_setattr(struct dentry *dentry, struct iattr *attr)dbg_gen ("ino %lu, mode %#x, ia_valid %#x" , inode->i_ino, inode->i_mode, attr->ia_valid); - err =setattr_prepare (dentry, attr); + err =setattr_prepare (&init_user_ns, dentry, attr);if (err)return err;
fs/udf/file.c +2 -2
@@ -259,7 +259,7 @@ static int udf_setattr(struct dentry *dentry, struct iattr *attr)struct super_block *sb = inode->i_sb;int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -282,7 +282,7 @@ static int udf_setattr(struct dentry *dentry, struct iattr *attr)if (attr->ia_valid &ATTR_MODE )udf_update_extra_perms (inode, attr->ia_mode); -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/ufs/inode.c +2 -2
@@ -1217,7 +1217,7 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)unsigned int ia_valid = attr->ia_valid;int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -1227,7 +1227,7 @@ int ufs_setattr(struct dentry *dentry, struct iattr *attr)return error; } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);mark_inode_dirty (inode);return 0 ; }
fs/utimes.c +2 -1
@@ -62,7 +62,8 @@ int vfs_utimes(const struct path *path, struct timespec64 *times) } retry_deleg:inode_lock (inode); - error =notify_change (path->dentry, &newattrs, &delegated_inode); + error =notify_change (&init_user_ns, path->dentry, &newattrs, + &delegated_inode);inode_unlock (inode);if (delegated_inode) { error =break_deleg_wait (&delegated_inode);
fs/xfs/xfs_iops.c +1 -1
@@ -637,7 +637,7 @@ xfs_vn_change_ok(if (XFS_FORCED_SHUTDOWN (mp))return -EIO ; -return setattr_prepare (dentry, iattr); +return setattr_prepare (&init_user_ns, dentry, iattr); }/*
fs/zonefs/super.c +2 -2
@@ -488,7 +488,7 @@ static int zonefs_inode_setattr(struct dentry *dentry, struct iattr *iattr)if (unlikely (IS_IMMUTABLE (inode)))return -EPERM ; - ret =setattr_prepare (dentry, iattr); + ret =setattr_prepare (&init_user_ns, dentry, iattr);if (ret)return ret;
@@ -516,7 +516,7 @@ static int zonefs_inode_setattr(struct dentry *dentry, struct iattr *iattr)return ret; } -setattr_copy (inode, iattr); +setattr_copy (&init_user_ns, inode, iattr);return 0 ; }
include/linux/fs.h +5 -3
@@ -2809,7 +2809,8 @@ static inline int bmap(struct inode *inode, sector_t *block) }#endif -extern int notify_change (struct dentry *,struct iattr *,struct inode **); +int notify_change (struct user_namespace *,struct dentry *, +struct iattr *,struct inode **);int inode_permission (struct user_namespace *,struct inode *,int );int generic_permission (struct user_namespace *,struct inode *,int );static inline int file_permission (struct file *file,int mask)
@@ -3274,9 +3275,10 @@ extern int buffer_migrate_page_norefs(struct address_space *,#define buffer_migrate_page_norefs NULL#endif -extern int setattr_prepare (struct dentry *,struct iattr *); +int setattr_prepare (struct user_namespace *,struct dentry *,struct iattr *);extern int inode_newsize_ok (const struct inode *,loff_t offset); -extern void setattr_copy (struct inode *inode,const struct iattr *attr); +void setattr_copy (struct user_namespace *,struct inode *inode, +const struct iattr *attr);extern int file_update_time (struct file *file);
mm/shmem.c +2 -2
@@ -1087,7 +1087,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr)struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb);int error; - error =setattr_prepare (dentry, attr); + error =setattr_prepare (&init_user_ns, dentry, attr);if (error)return error;
@@ -1141,7 +1141,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr) } } -setattr_copy (inode, attr); +setattr_copy (&init_user_ns, inode, attr);if (attr->ia_valid &ATTR_MODE ) error =posix_acl_chmod (inode, inode->i_mode);return error;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 8/40 acl: handle idmapped mounts
In reply to Christian BraunerThe posix acl permission checking helpers determine whether a caller is privileged over an inode according to the acls associated with the inode. Add helpers that make it possible to handle acls on idmapped mounts.
The vfs and the filesystems targeted by this first iteration make use of posix_acl_fix_xattr_from_user() and posix_acl_fix_xattr_to_user() to translate basic posix access and default permissions such as the ACL_USER and ACL_GROUP type according to the initial user namespace (or the superblock's user namespace) to and from the caller's current user namespace. Adapt these two helpers to handle idmapped mounts whereby we either map from or into the mount's user namespace depending on in which direction we're translating.
Similarly, cap_convert_nscap() is used by the vfs to translate user namespace and non-user namespace aware filesystem capabilities from the superblock's user namespace to the caller's user namespace. Enable it to handle idmapped mounts by accounting for the mount's user namespace.
In addition the fileystems targeted in the first iteration of this patch series make use of the posix_acl_chmod() and, posix_acl_update_mode() helpers. Both helpers perform permission checks on the target inode. Let them handle idmapped mounts. These two helpers are called when posix acls are set by the respective filesystems to handle this case we extend the ->set() method to take an additional user namespace argument to pass the mount's user namespace down.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from header.
--- Documentation/filesystems/locking.rst | 7 ++- Documentation/filesystems/porting.rst | 2 + fs/9p/acl.c | 4 +- fs/9p/xattr.c | 1 + fs/afs/xattr.c | 2 + fs/btrfs/acl.c | 3 +- fs/btrfs/inode.c | 3 +- fs/btrfs/xattr.c | 2 + fs/ceph/acl.c | 3 +- fs/ceph/inode.c | 2 +- fs/ceph/xattr.c | 1 + fs/cifs/xattr.c | 1 + fs/ecryptfs/inode.c | 1 + fs/ext2/acl.c | 3 +- fs/ext2/inode.c | 2 +- fs/ext2/xattr_security.c | 1 + fs/ext2/xattr_trusted.c | 1 + fs/ext2/xattr_user.c | 1 + fs/ext4/acl.c | 3 +- fs/ext4/inode.c | 2 +- fs/ext4/xattr_hurd.c | 1 + fs/ext4/xattr_security.c | 1 + fs/ext4/xattr_trusted.c | 1 + fs/ext4/xattr_user.c | 1 + fs/f2fs/acl.c | 3 +- fs/f2fs/file.c | 7 ++- fs/f2fs/xattr.c | 2 + fs/fuse/xattr.c | 2 + fs/gfs2/acl.c | 2 +- fs/gfs2/inode.c | 3 +- fs/gfs2/xattr.c | 1 + fs/hfs/attr.c | 1 + fs/hfsplus/xattr.c | 1 + fs/hfsplus/xattr_security.c | 1 + fs/hfsplus/xattr_trusted.c | 1 + fs/hfsplus/xattr_user.c | 1 + fs/jffs2/acl.c | 3 +- fs/jffs2/fs.c | 2 +- fs/jffs2/security.c | 1 + fs/jffs2/xattr_trusted.c | 1 + fs/jffs2/xattr_user.c | 1 + fs/jfs/acl.c | 2 +- fs/jfs/file.c | 2 +- fs/jfs/xattr.c | 2 + fs/kernfs/inode.c | 2 + fs/nfs/nfs4proc.c | 3 + fs/nfsd/nfs2acl.c | 6 +- fs/nfsd/nfs3acl.c | 6 +- fs/nfsd/nfs4acl.c | 5 +- fs/ocfs2/acl.c | 3 +- fs/ocfs2/xattr.c | 3 + fs/orangefs/acl.c | 3 +- fs/orangefs/inode.c | 2 +- fs/orangefs/xattr.c | 1 + fs/overlayfs/super.c | 3 + fs/posix_acl.c | 79 ++++++++++++++++++++------- fs/reiserfs/xattr_acl.c | 5 +- fs/reiserfs/xattr_security.c | 3 +- fs/reiserfs/xattr_trusted.c | 3 +- fs/reiserfs/xattr_user.c | 3 +- fs/ubifs/xattr.c | 1 + fs/xattr.c | 14 +++-- fs/xfs/xfs_acl.c | 3 +- fs/xfs/xfs_iops.c | 2 +- fs/xfs/xfs_xattr.c | 7 ++- include/linux/capability.h | 3 +- include/linux/posix_acl.h | 11 ++-- include/linux/posix_acl_xattr.h | 12 ++-- include/linux/xattr.h | 3 +- mm/shmem.c | 3 +- net/socket.c | 1 + security/commoncap.c | 45 ++++++++++++--- 72 files changed, 238 insertions(+), 85 deletions(-)
Documentation/filesystems/locking.rst +4 -3
@@ -126,9 +126,10 @@ prototypes:: int (*get)(const struct xattr_handler *handler, struct dentry *dentry, struct inode *inode, const char *name, void *buffer, size_t size); - int (*set)(const struct xattr_handler *handler, struct dentry *dentry, - struct inode *inode, const char *name, const void *buffer, - size_t size, int flags); + int (*set)(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, + struct dentry *dentry, struct inode *inode, const char *name, + const void *buffer, size_t size, int flags); locking rules: all may block
Documentation/filesystems/porting.rst +2 -0
@@ -717,6 +717,8 @@ be removed. Switch while you still can; the old one won't stay. **mandatory** ->setxattr() and xattr_handler.set() get dentry and inode passed separately. +The xattr_handler.set() gets passed the user namespace of the mount the inode +is seen from so filesystems can idmap the i_uid and i_gid accordingly. dentry might be yet to be attached to inode, so do _not_ use its ->d_inode in the instances. Rationale: !@#!@# security_d_instantiate() needs to be called before we attach dentry to inode and !@#!@##!@$!$#!@#$!@$!@$ smack
fs/9p/acl.c +3 -1
@@ -239,6 +239,7 @@ static int v9fs_xattr_get_acl(const struct xattr_handler *handler, }static int v9fs_xattr_set_acl (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -279,7 +280,8 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,struct iattr iattr = {0 };struct posix_acl *old_acl = acl; - retval =posix_acl_update_mode (inode, &iattr.ia_mode, &acl); + retval =posix_acl_update_mode (mnt_userns, inode, + &iattr.ia_mode, &acl);if (retval) goto err_out;if (!acl) {
fs/9p/xattr.c +1 -0
@@ -157,6 +157,7 @@ static int v9fs_xattr_handler_get(const struct xattr_handler *handler, }static int v9fs_xattr_handler_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/afs/xattr.c +2 -0
@@ -120,6 +120,7 @@ static const struct afs_operation_ops afs_store_acl_operation = {* Set a file's AFS3 ACL. */ static int afs_xattr_set_acl (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
@@ -248,6 +249,7 @@ static const struct afs_operation_ops yfs_store_opaque_acl2_operation = {* Set a file's YFS ACL. */ static int afs_xattr_set_yfs (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/btrfs/acl.c +2 -1
@@ -113,7 +113,8 @@ int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)umode_t old_mode = inode->i_mode;if (type ==ACL_TYPE_ACCESS && acl) { - ret =posix_acl_update_mode (inode, &inode->i_mode, &acl); + ret =posix_acl_update_mode (&init_user_ns, inode, + &inode->i_mode, &acl);if (ret)return ret; }
fs/btrfs/inode.c +2 -1
@@ -5070,7 +5070,8 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) err =btrfs_dirty_inode (inode);if (!err && attr->ia_valid &ATTR_MODE ) - err =posix_acl_chmod (inode, inode->i_mode); + err =posix_acl_chmod (&init_user_ns, inode, + inode->i_mode); }return err;
fs/btrfs/xattr.c +2 -0
@@ -362,6 +362,7 @@ static int btrfs_xattr_handler_get(const struct xattr_handler *handler, }static int btrfs_xattr_handler_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
@@ -371,6 +372,7 @@ static int btrfs_xattr_handler_set(const struct xattr_handler *handler, }static int btrfs_xattr_handler_set_prop (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ceph/acl.c +2 -1
@@ -100,7 +100,8 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)case ACL_TYPE_ACCESS : name =XATTR_NAME_POSIX_ACL_ACCESS ;if (acl) { - ret =posix_acl_update_mode (inode, &new_mode, &acl); + ret =posix_acl_update_mode (&init_user_ns, inode, + &new_mode, &acl);if (ret) goto out; }
fs/ceph/inode.c +1 -1
@@ -2262,7 +2262,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr *attr) err =__ceph_setattr (inode, attr);if (err >=0 && (attr->ia_valid &ATTR_MODE )) - err =posix_acl_chmod (inode, attr->ia_mode); + err =posix_acl_chmod (&init_user_ns, inode, attr->ia_mode);return err; }
fs/ceph/xattr.c +1 -0
@@ -1238,6 +1238,7 @@ static int ceph_get_xattr_handler(const struct xattr_handler *handler, }static int ceph_set_xattr_handler (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/cifs/xattr.c +1 -0
@@ -101,6 +101,7 @@ static int cifs_creation_time_set(unsigned int xid, struct cifs_tcon *pTcon, }static int cifs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ecryptfs/inode.c +1 -0
@@ -1133,6 +1133,7 @@ static int ecryptfs_xattr_get(const struct xattr_handler *handler, }static int ecryptfs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext2/acl.c +2 -1
@@ -223,7 +223,8 @@ ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)umode_t mode = inode->i_mode;if (type ==ACL_TYPE_ACCESS && acl) { - error =posix_acl_update_mode (inode, &mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, &mode, + &acl);if (error)return error; update_mode =1 ;
fs/ext2/inode.c +1 -1
@@ -1691,7 +1691,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr) }setattr_copy (&init_user_ns, inode, iattr);if (iattr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, inode, inode->i_mode);mark_inode_dirty (inode);return error;
fs/ext2/xattr_security.c +1 -0
@@ -19,6 +19,7 @@ ext2_xattr_security_get(const struct xattr_handler *handler,static int ext2_xattr_security_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext2/xattr_trusted.c +1 -0
@@ -26,6 +26,7 @@ ext2_xattr_trusted_get(const struct xattr_handler *handler,static int ext2_xattr_trusted_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext2/xattr_user.c +1 -0
@@ -30,6 +30,7 @@ ext2_xattr_user_get(const struct xattr_handler *handler,static int ext2_xattr_user_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext4/acl.c +2 -1
@@ -245,7 +245,8 @@ ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)ext4_fc_start_update (inode);if ((type ==ACL_TYPE_ACCESS ) && acl) { - error =posix_acl_update_mode (inode, &mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, &mode, + &acl);if (error) goto out_stop;if (mode != inode->i_mode)
fs/ext4/inode.c +1 -1
@@ -5524,7 +5524,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)ext4_orphan_del (NULL , inode);if (!error && (ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (inode, inode->i_mode); + rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); err_out:if (error)
fs/ext4/xattr_hurd.c +1 -0
@@ -32,6 +32,7 @@ ext4_xattr_hurd_get(const struct xattr_handler *handler,static int ext4_xattr_hurd_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext4/xattr_security.c +1 -0
@@ -23,6 +23,7 @@ ext4_xattr_security_get(const struct xattr_handler *handler,static int ext4_xattr_security_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext4/xattr_trusted.c +1 -0
@@ -30,6 +30,7 @@ ext4_xattr_trusted_get(const struct xattr_handler *handler,static int ext4_xattr_trusted_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/ext4/xattr_user.c +1 -0
@@ -31,6 +31,7 @@ ext4_xattr_user_get(const struct xattr_handler *handler,static int ext4_xattr_user_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/f2fs/acl.c +2 -1
@@ -213,7 +213,8 @@ static int __f2fs_set_acl(struct inode *inode, int type,case ACL_TYPE_ACCESS : name_index =F2FS_XATTR_INDEX_POSIX_ACL_ACCESS ;if (acl && !ipage) { - error =posix_acl_update_mode (inode, &mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, + &mode, &acl);if (error)return error;set_acl_inode (inode, mode);
fs/f2fs/file.c +4 -3
@@ -831,8 +831,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat, }#ifdef CONFIG_F2FS_FS_POSIX_ACL -static void __setattr_copy (struct user_namespace *mnt_userns,struct inode *inode, -const struct iattr *attr) +static void __setattr_copy (struct user_namespace *mnt_userns, +struct inode *inode,const struct iattr *attr) {unsigned int ia_valid = attr->ia_valid;
@@ -950,7 +950,8 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)__setattr_copy (&init_user_ns, inode, attr);if (attr->ia_valid &ATTR_MODE ) { - err =posix_acl_chmod (inode,f2fs_get_inode_mode (inode)); + err =posix_acl_chmod (&init_user_ns, inode, +f2fs_get_inode_mode (inode));if (err ||is_inode_flag_set (inode,FI_ACL_MODE )) { inode->i_mode =F2FS_I (inode)->i_acl_mode;clear_inode_flag (inode,FI_ACL_MODE );
fs/f2fs/xattr.c +2 -0
@@ -64,6 +64,7 @@ static int f2fs_xattr_generic_get(const struct xattr_handler *handler, }static int f2fs_xattr_generic_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -107,6 +108,7 @@ static int f2fs_xattr_advise_get(const struct xattr_handler *handler, }static int f2fs_xattr_advise_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/fuse/xattr.c +2 -0
@@ -188,6 +188,7 @@ static int fuse_xattr_get(const struct xattr_handler *handler, }static int fuse_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -214,6 +215,7 @@ static int no_xattr_get(const struct xattr_handler *handler, }static int no_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *nodee,const char *name,const void *value,size_t size,int flags)
fs/gfs2/acl.c +1 -1
@@ -130,7 +130,7 @@ int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type) mode = inode->i_mode;if (type ==ACL_TYPE_ACCESS && acl) { - ret =posix_acl_update_mode (inode, &mode, &acl); + ret =posix_acl_update_mode (&init_user_ns, inode, &mode, &acl);if (ret) goto unlock; }
fs/gfs2/inode.c +2 -1
@@ -1993,7 +1993,8 @@ static int gfs2_setattr(struct dentry *dentry, struct iattr *attr)else { error =gfs2_setattr_simple (inode, attr);if (!error && attr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, inode, + inode->i_mode); } error:
fs/gfs2/xattr.c +1 -0
@@ -1214,6 +1214,7 @@ int __gfs2_xattr_set(struct inode *inode, const char *name, }static int gfs2_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/hfs/attr.c +1 -0
@@ -121,6 +121,7 @@ static int hfs_xattr_get(const struct xattr_handler *handler, }static int hfs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/hfsplus/xattr.c +1 -0
@@ -858,6 +858,7 @@ static int hfsplus_osx_getxattr(const struct xattr_handler *handler, }static int hfsplus_osx_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/hfsplus/xattr_security.c +1 -0
@@ -23,6 +23,7 @@ static int hfsplus_security_getxattr(const struct xattr_handler *handler, }static int hfsplus_security_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/hfsplus/xattr_trusted.c +1 -0
@@ -22,6 +22,7 @@ static int hfsplus_trusted_getxattr(const struct xattr_handler *handler, }static int hfsplus_trusted_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/hfsplus/xattr_user.c +1 -0
@@ -22,6 +22,7 @@ static int hfsplus_user_getxattr(const struct xattr_handler *handler, }static int hfsplus_user_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/jffs2/acl.c +2 -1
@@ -236,7 +236,8 @@ int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)if (acl) {umode_t mode; - rc =posix_acl_update_mode (inode, &mode, &acl); + rc =posix_acl_update_mode (&init_user_ns, inode, &mode, + &acl);if (rc)return rc;if (inode->i_mode != mode) {
fs/jffs2/fs.c +1 -1
@@ -201,7 +201,7 @@ int jffs2_setattr(struct dentry *dentry, struct iattr *iattr) rc =jffs2_do_setattr (inode, iattr);if (!rc && (iattr->ia_valid &ATTR_MODE )) - rc =posix_acl_chmod (inode, inode->i_mode); + rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode);return rc; }
fs/jffs2/security.c +1 -0
@@ -57,6 +57,7 @@ static int jffs2_security_getxattr(const struct xattr_handler *handler, }static int jffs2_security_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/jffs2/xattr_trusted.c +1 -0
@@ -25,6 +25,7 @@ static int jffs2_trusted_getxattr(const struct xattr_handler *handler, }static int jffs2_trusted_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/jffs2/xattr_user.c +1 -0
@@ -25,6 +25,7 @@ static int jffs2_user_getxattr(const struct xattr_handler *handler, }static int jffs2_user_setxattr (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags)
fs/jfs/acl.c +1 -1
@@ -101,7 +101,7 @@ int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type) tid =txBegin (inode->i_sb,0 );mutex_lock (&JFS_IP (inode)->commit_mutex);if (type ==ACL_TYPE_ACCESS && acl) { - rc =posix_acl_update_mode (inode, &mode, &acl); + rc =posix_acl_update_mode (&init_user_ns, inode, &mode, &acl);if (rc) goto end_tx;if (mode != inode->i_mode)
fs/jfs/file.c +1 -1
@@ -122,7 +122,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)mark_inode_dirty (inode);if (iattr->ia_valid &ATTR_MODE ) - rc =posix_acl_chmod (inode, inode->i_mode); + rc =posix_acl_chmod (&init_user_ns, inode, inode->i_mode);return rc; }
fs/jfs/xattr.c +2 -0
@@ -932,6 +932,7 @@ static int jfs_xattr_get(const struct xattr_handler *handler, }static int jfs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -950,6 +951,7 @@ static int jfs_xattr_get_os2(const struct xattr_handler *handler, }static int jfs_xattr_set_os2 (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/kernfs/inode.c +2 -0
@@ -319,6 +319,7 @@ static int kernfs_vfs_xattr_get(const struct xattr_handler *handler, }static int kernfs_vfs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *suffix,const void *value,size_t size,int flags)
@@ -385,6 +386,7 @@ static int kernfs_vfs_user_xattr_rm(struct kernfs_node *kn, }static int kernfs_vfs_user_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *suffix,const void *value,size_t size,int flags)
fs/nfs/nfs4proc.c +3 -0
@@ -7491,6 +7491,7 @@ nfs4_release_lockowner(struct nfs_server *server, struct nfs4_lock_state *lsp)#define XATTR_NAME_NFSV4_ACL "system.nfs4_acl"static int nfs4_xattr_set_nfs4_acl (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *key,const void *buf,size_t buflen,int flags)
@@ -7513,6 +7514,7 @@ static bool nfs4_xattr_list_nfs4_acl(struct dentry *dentry)#ifdef CONFIG_NFS_V4_SECURITY_LABEL static int nfs4_xattr_set_nfs4_label (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *key,const void *buf,size_t buflen,int flags)
@@ -7563,6 +7565,7 @@ nfs4_listxattr_nfs4_label(struct inode *inode, char *list, size_t list_len)#ifdef CONFIG_NFS_V4_2 static int nfs4_xattr_set_nfs4_user (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *key,const void *buf,size_t buflen,int flags)
fs/nfsd/nfs2acl.c +4 -2
@@ -113,10 +113,12 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst *rqstp)fh_lock (fh); - error =set_posix_acl (inode,ACL_TYPE_ACCESS , argp->acl_access); + error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_ACCESS , + argp->acl_access);if (error) goto out_drop_lock; - error =set_posix_acl (inode,ACL_TYPE_DEFAULT , argp->acl_default); + error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_DEFAULT , + argp->acl_default);if (error) goto out_drop_lock;
fs/nfsd/nfs3acl.c +4 -2
@@ -103,10 +103,12 @@ static __be32 nfsd3_proc_setacl(struct svc_rqst *rqstp)fh_lock (fh); - error =set_posix_acl (inode,ACL_TYPE_ACCESS , argp->acl_access); + error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_ACCESS , + argp->acl_access);if (error) goto out_drop_lock; - error =set_posix_acl (inode,ACL_TYPE_DEFAULT , argp->acl_default); + error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_DEFAULT , + argp->acl_default); out_drop_lock:fh_unlock (fh);
fs/nfsd/nfs4acl.c +3 -2
@@ -781,12 +781,13 @@ nfsd4_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,fh_lock (fhp); - host_error =set_posix_acl (inode,ACL_TYPE_ACCESS , pacl); + host_error =set_posix_acl (&init_user_ns, inode,ACL_TYPE_ACCESS , pacl);if (host_error <0 ) goto out_drop_lock;if (S_ISDIR (inode->i_mode)) { - host_error =set_posix_acl (inode,ACL_TYPE_DEFAULT , dpacl); + host_error =set_posix_acl (&init_user_ns, inode, +ACL_TYPE_DEFAULT , dpacl); } out_drop_lock:
fs/ocfs2/acl.c +2 -1
@@ -274,7 +274,8 @@ int ocfs2_iop_set_acl(struct inode *inode, struct posix_acl *acl, int type)if (type ==ACL_TYPE_ACCESS && acl) {umode_t mode; - status =posix_acl_update_mode (inode, &mode, &acl); + status =posix_acl_update_mode (&init_user_ns, inode, &mode, + &acl);if (status) goto unlock;
fs/ocfs2/xattr.c +3 -0
@@ -7249,6 +7249,7 @@ static int ocfs2_xattr_security_get(const struct xattr_handler *handler, }static int ocfs2_xattr_security_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -7321,6 +7322,7 @@ static int ocfs2_xattr_trusted_get(const struct xattr_handler *handler, }static int ocfs2_xattr_trusted_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -7351,6 +7353,7 @@ static int ocfs2_xattr_user_get(const struct xattr_handler *handler, }static int ocfs2_xattr_user_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/orangefs/acl.c +2 -1
@@ -132,7 +132,8 @@ int orangefs_set_acl(struct inode *inode, struct posix_acl *acl, int type)* and "mode" to the new desired value. It is up to * us to propagate the new mode back to the server... */ - error =posix_acl_update_mode (inode, &iattr.ia_mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, + &iattr.ia_mode, &acl);if (error) { gossip_err("%s: posix_acl_update_mode err: %d\n", __func__,
fs/orangefs/inode.c +1 -1
@@ -861,7 +861,7 @@ int __orangefs_setattr(struct inode *inode, struct iattr *iattr)if (iattr->ia_valid &ATTR_MODE )/* change mod on a file that has ACLs */ - ret =posix_acl_chmod (inode, inode->i_mode); + ret =posix_acl_chmod (&init_user_ns, inode, inode->i_mode); ret =0 ; out:
fs/orangefs/xattr.c +1 -0
@@ -526,6 +526,7 @@ ssize_t orangefs_listxattr(struct dentry *dentry, char *buffer, size_t size) } static int orangefs_xattr_set_default(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, struct dentry *unused, struct inode *inode, const char *name,
fs/overlayfs/super.c +3 -0
@@ -980,6 +980,7 @@ ovl_posix_acl_xattr_get(const struct xattr_handler *handler,static int __maybe_unused ovl_posix_acl_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -1044,6 +1045,7 @@ static int ovl_own_xattr_get(const struct xattr_handler *handler, }static int ovl_own_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
@@ -1059,6 +1061,7 @@ static int ovl_other_xattr_get(const struct xattr_handler *handler, }static int ovl_other_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/posix_acl.c +58 -21
166 lines not on this page · raw message
fs/reiserfs/xattr_acl.c +3 -2
@@ -40,7 +40,8 @@ reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)reiserfs_write_unlock (inode->i_sb);if (error ==0 ) {if (type ==ACL_TYPE_ACCESS && acl) { - error =posix_acl_update_mode (inode, &mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, + &mode, &acl);if (error) goto unlock; update_mode =1 ;
@@ -399,5 +400,5 @@ int reiserfs_acl_chmod(struct inode *inode) !reiserfs_posixacl(inode->i_sb))return 0 ; -return posix_acl_chmod (inode, inode->i_mode); +return posix_acl_chmod (&init_user_ns, inode, inode->i_mode); }
fs/reiserfs/xattr_security.c +2 -1
@@ -21,7 +21,8 @@ security_get(const struct xattr_handler *handler, struct dentry *unused, }static int -security_set (const struct xattr_handler *handler,struct dentry *unused, +security_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags) {
fs/reiserfs/xattr_trusted.c +2 -1
@@ -20,7 +20,8 @@ trusted_get(const struct xattr_handler *handler, struct dentry *unused, }static int -trusted_set (const struct xattr_handler *handler,struct dentry *unused, +trusted_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags) {
fs/reiserfs/xattr_user.c +2 -1
@@ -18,7 +18,8 @@ user_get(const struct xattr_handler *handler, struct dentry *unused, }static int -user_set (const struct xattr_handler *handler,struct dentry *unused, +user_set (const struct xattr_handler *handler,struct user_namespace *mnt_userns, +struct dentry *unused,struct inode *inode,const char *name,const void *buffer,size_t size,int flags) {
fs/ubifs/xattr.c +1 -0
@@ -681,6 +681,7 @@ static int xattr_get(const struct xattr_handler *handler, }static int xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *value,size_t size,int flags)
fs/xattr.c +9 -5
@@ -175,7 +175,8 @@ __vfs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,return -EOPNOTSUPP ;if (size ==0 ) value ="" ;/* empty EA, do not remove */ -return handler->set (handler, dentry, inode, name, value, size, flags); +return handler->set (handler, &init_user_ns, dentry, inode, name, value, + size, flags); }EXPORT_SYMBOL (__vfs_setxattr);
@@ -281,7 +282,7 @@ vfs_setxattr(struct dentry *dentry, const char *name, const void *value,int error;if (size &&strcmp (name,XATTR_NAME_CAPS ) ==0 ) { - error =cap_convert_nscap (dentry, &value, size); + error =cap_convert_nscap (&init_user_ns, dentry, &value, size);if (error <0 )return error; size = error;
@@ -450,7 +451,8 @@ __vfs_removexattr(struct dentry *dentry, const char *name)return PTR_ERR (handler);if (!handler->set)return -EOPNOTSUPP ; -return handler->set (handler, dentry, inode, name,NULL ,0 ,XATTR_REPLACE ); +return handler->set (handler, &init_user_ns, dentry, inode, name,NULL , +0 ,XATTR_REPLACE ); }EXPORT_SYMBOL (__vfs_removexattr);
@@ -548,7 +550,8 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value, }if ((strcmp (kname,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || (strcmp (kname,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 )) -posix_acl_fix_xattr_from_user (kvalue, size); +posix_acl_fix_xattr_from_user (&init_user_ns, kvalue, + size); } error =vfs_setxattr (d, kname, kvalue, size, flags);
@@ -642,7 +645,8 @@ getxattr(struct dentry *d, const char __user *name, void __user *value,if (error >0 ) {if ((strcmp (kname,XATTR_NAME_POSIX_ACL_ACCESS ) ==0 ) || (strcmp (kname,XATTR_NAME_POSIX_ACL_DEFAULT ) ==0 )) -posix_acl_fix_xattr_to_user (kvalue, error); +posix_acl_fix_xattr_to_user (&init_user_ns, kvalue, + error);if (size &©_to_user (value, kvalue, error)) error = -EFAULT ; }else if (error == -ERANGE && size >=XATTR_SIZE_MAX ) {
fs/xfs/xfs_acl.c +2 -1
@@ -252,7 +252,8 @@ xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)return error;if (type ==ACL_TYPE_ACCESS ) { - error =posix_acl_update_mode (inode, &mode, &acl); + error =posix_acl_update_mode (&init_user_ns, inode, &mode, + &acl);if (error)return error; set_mode = true;
fs/xfs/xfs_iops.c +1 -1
@@ -807,7 +807,7 @@ xfs_setattr_nonsize(* Posix ACL code seems to care about this issue either. */ if (mask &ATTR_MODE ) { - error =posix_acl_chmod (inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, inode, inode->i_mode);if (error)return error; }
fs/xfs/xfs_xattr.c +4 -3
@@ -38,9 +38,10 @@ xfs_xattr_get(const struct xattr_handler *handler, struct dentry *unused, }static int -xfs_xattr_set (const struct xattr_handler *handler,struct dentry *unused, -struct inode *inode,const char *name,const void *value, -size_t size,int flags) +xfs_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused, +struct inode *inode,const char *name,const void *value, +size_t size,int flags) {struct xfs_da_args args = { .dp =XFS_I (inode),
include/linux/capability.h +2 -1
@@ -273,6 +273,7 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns)/* audit system wants to get cap info from files as well */ extern int get_vfs_caps_from_disk (const struct dentry *dentry,struct cpu_vfs_cap_data *cpu_caps); -extern int cap_convert_nscap (struct dentry *dentry,const void **ivalue,size_t size); +int cap_convert_nscap (struct user_namespace *mnt_userns,struct dentry *dentry, +const void **ivalue,size_t size);#endif /* !_LINUX_CAPABILITY_H */
include/linux/posix_acl.h +7 -4
@@ -69,13 +69,15 @@ extern int __posix_acl_create(struct posix_acl **, gfp_t, umode_t *);extern int __posix_acl_chmod (struct posix_acl **,gfp_t ,umode_t );extern struct posix_acl *get_posix_acl (struct inode *,int ); -extern int set_posix_acl (struct inode *,int ,struct posix_acl *); +extern int set_posix_acl (struct user_namespace *,struct inode *,int , +struct posix_acl *);#ifdef CONFIG_FS_POSIX_ACL -extern int posix_acl_chmod (struct inode *,umode_t ); +int posix_acl_chmod (struct user_namespace *,struct inode *,umode_t );extern int posix_acl_create (struct inode *,umode_t *,struct posix_acl **,struct posix_acl **); -extern int posix_acl_update_mode (struct inode *,umode_t *,struct posix_acl **); +int posix_acl_update_mode (struct user_namespace *,struct inode *,umode_t *, +struct posix_acl **);extern int simple_set_acl (struct inode *,struct posix_acl *,int );extern int simple_acl_create (struct inode *,struct inode *);
@@ -95,7 +97,8 @@ static inline void cache_no_acl(struct inode *inode) inode->i_default_acl = NULL; }#else -static inline int posix_acl_chmod (struct inode *inode,umode_t mode) +static inline int posix_acl_chmod (struct user_namespace *mnt_userns, +struct inode *inode,umode_t mode) {return 0 ; }
include/linux/posix_acl_xattr.h +8 -4
@@ -33,13 +33,17 @@ posix_acl_xattr_count(size_t size) }#ifdef CONFIG_FS_POSIX_ACL -void posix_acl_fix_xattr_from_user (void *value,size_t size); -void posix_acl_fix_xattr_to_user (void *value,size_t size); +void posix_acl_fix_xattr_from_user (struct user_namespace *mnt_userns, +void *value,size_t size); +void posix_acl_fix_xattr_to_user (struct user_namespace *mnt_userns, +void *value,size_t size);#else -static inline void posix_acl_fix_xattr_from_user (void *value,size_t size) +static inline void posix_acl_fix_xattr_from_user (struct user_namespace *mnt_userns, +void *value,size_t size) { } -static inline void posix_acl_fix_xattr_to_user (void *value,size_t size) +static inline void posix_acl_fix_xattr_to_user (struct user_namespace *mnt_userns, +void *value,size_t size) { }#endif
include/linux/xattr.h +2 -1
@@ -34,7 +34,8 @@ struct xattr_handler {int (*get)(const struct xattr_handler *,struct dentry *dentry,struct inode *inode,const char *name,void *buffer,size_t size); -int (*set)(const struct xattr_handler *,struct dentry *dentry, +int (*set)(const struct xattr_handler *, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *name,const void *buffer,size_t size,int flags); };
mm/shmem.c +2 -1
@@ -1143,7 +1143,7 @@ static int shmem_setattr(struct dentry *dentry, struct iattr *attr)setattr_copy (&init_user_ns, inode, attr);if (attr->ia_valid &ATTR_MODE ) - error =posix_acl_chmod (inode, inode->i_mode); + error =posix_acl_chmod (&init_user_ns, inode, inode->i_mode);return error; }
@@ -3273,6 +3273,7 @@ static int shmem_xattr_handler_get(const struct xattr_handler *handler, }static int shmem_xattr_handler_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *unused,struct inode *inode,const char *name,const void *value,size_t size,int flags)
net/socket.c +1 -0
@@ -334,6 +334,7 @@ static const struct xattr_handler sockfs_xattr_handler = { };static int sockfs_security_xattr_set (const struct xattr_handler *handler, +struct user_namespace *mnt_userns,struct dentry *dentry,struct inode *inode,const char *suffix,const void *value,size_t size,int flags)
security/commoncap.c +38 -7
81 lines not on this page · raw message
Signature · 1 line
2.30.0
PATCH v6 10/40 commoncap: handle idmapped mounts
In reply to Christian BraunerWhen interacting with user namespace and non-user namespace aware filesystem capabilities the vfs will perform various security checks to determine whether or not the filesystem capabilities can be used by the caller, whether they need to be removed and so on. The main infrastructure for this resides in the capability codepaths but they are called through the LSM security infrastructure even though they are not technically an LSM or optional. This extends the existing security hooks security_inode_removexattr(), security_inode_killpriv(), security_inode_getsecurity() to pass down the mount's user namespace and makes them aware of idmapped mounts.
In order to actually get filesystem capabilities from disk the capability infrastructure exposes the get_vfs_caps_from_disk() helper. For user namespace aware filesystem capabilities a root uid is stored alongside the capabilities.
In order to determine whether the caller can make use of the filesystem capability or whether it needs to be ignored it is translated according to the superblock's user namespace. If it can be translated to uid 0 according to that id mapping the caller can use the filesystem capabilities stored on disk. If we are accessing the inode that holds the filesystem capabilities through an idmapped mount we map the root uid according to the mount's user namespace. Afterwards the checks are identical to non-idmapped mounts: reading filesystem caps from disk enforces that the root uid associated with the filesystem capability must have a mapping in the superblock's user namespace and that the caller is either in the same user namespace or is a descendant of the superblock's user namespace. For filesystems that are mountable inside user namespace the caller can just mount the filesystem and won't usually need to idmap it. If they do want to idmap it they can create an idmapped mount and mark it with a user namespace they created and which is thus a descendant of s_user_ns. For filesystems that are not mountable inside user namespaces the descendant rule is trivially true because the s_user_ns will be the initial user namespace.
If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
- Paul Moore <[email protected]>:
- All audit logging is currently based on init_user_ns and will remain so until other work unrelated to this patchset has landed so always pass &init_user_ns in audit.
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
--- fs/attr.c | 2 +- fs/xattr.c | 18 ++++++---- include/linux/capability.h | 4 ++- include/linux/lsm_hook_defs.h | 15 +++++---- include/linux/lsm_hooks.h | 1 + include/linux/security.h | 54 +++++++++++++++++++----------- kernel/auditsc.c | 5 +-- security/commoncap.c | 62 +++++++++++++++++++++++++++-------- security/security.c | 25 ++++++++------ security/selinux/hooks.c | 20 ++++++----- security/smack/smack_lsm.c | 14 ++++---- 11 files changed, 146 insertions(+), 74 deletions(-)
fs/attr.c +1 -1
@@ -143,7 +143,7 @@ int setattr_prepare(struct user_namespace *mnt_userns, struct dentry *dentry,if (ia_valid &ATTR_KILL_PRIV ) {int error; - error =security_inode_killpriv (dentry); + error =security_inode_killpriv (mnt_userns, dentry);if (error)return error; }
fs/xattr.c +11 -7
@@ -262,7 +262,8 @@ __vfs_setxattr_locked(struct user_namespace *mnt_userns, struct dentry *dentry,if (error)return error; - error =security_inode_setxattr (dentry, name, value, size, flags); + error =security_inode_setxattr (mnt_userns, dentry, name, value, size, + flags);if (error) goto out;
@@ -313,18 +314,20 @@ vfs_setxattr(struct user_namespace *mnt_userns, struct dentry *dentry,EXPORT_SYMBOL_GPL (vfs_setxattr);static ssize_t -xattr_getsecurity (struct inode *inode,const char *name,void *value, -size_t size) +xattr_getsecurity (struct user_namespace *mnt_userns,struct inode *inode, +const char *name,void *value,size_t size) {void *buffer =NULL ;ssize_t len;if (!value || !size) { - len =security_inode_getsecurity (inode, name, &buffer, false); + len =security_inode_getsecurity (mnt_userns, inode, name, + &buffer, false); goto out_noalloc; } - len =security_inode_getsecurity (inode, name, &buffer, true); + len =security_inode_getsecurity (mnt_userns, inode, name, &buffer, + true);if (len <0 )return len;if (size < len) {
@@ -414,7 +417,8 @@ vfs_getxattr(struct user_namespace *mnt_userns, struct dentry *dentry,if (!strncmp (name,XATTR_SECURITY_PREFIX ,XATTR_SECURITY_PREFIX_LEN )) {const char *suffix = name +XATTR_SECURITY_PREFIX_LEN ; -int ret =xattr_getsecurity (inode, suffix, value, size); +int ret =xattr_getsecurity (mnt_userns, inode, suffix, value, + size);/* * Only overwrite the return value if a security module * is actually active.
@@ -486,7 +490,7 @@ __vfs_removexattr_locked(struct user_namespace *mnt_userns,if (error)return error; - error =security_inode_removexattr (dentry, name); + error =security_inode_removexattr (mnt_userns, dentry, name);if (error) goto out;
include/linux/capability.h +3 -1
@@ -271,7 +271,9 @@ static inline bool checkpoint_restore_ns_capable(struct user_namespace *ns) }/* audit system wants to get cap info from files as well */ -extern int get_vfs_caps_from_disk (const struct dentry *dentry,struct cpu_vfs_cap_data *cpu_caps); +int get_vfs_caps_from_disk (struct user_namespace *mnt_userns, +const struct dentry *dentry, +struct cpu_vfs_cap_data *cpu_caps);int cap_convert_nscap (struct user_namespace *mnt_userns,struct dentry *dentry,const void **ivalue,size_t size);
include/linux/lsm_hook_defs.h +9 -6
@@ -133,17 +133,20 @@ LSM_HOOK(int, 0, inode_follow_link, struct dentry *dentry, struct inode *inode, LSM_HOOK(int, 0, inode_permission, struct inode *inode, int mask) LSM_HOOK(int, 0, inode_setattr, struct dentry *dentry, struct iattr *attr) LSM_HOOK(int, 0, inode_getattr, const struct path *path) -LSM_HOOK(int, 0, inode_setxattr, struct dentry *dentry, const char *name, - const void *value, size_t size, int flags) +LSM_HOOK(int, 0, inode_setxattr, struct user_namespace *mnt_userns, + struct dentry *dentry, const char *name, const void *value, + size_t size, int flags) LSM_HOOK(void, LSM_RET_VOID, inode_post_setxattr, struct dentry *dentry, const char *name, const void *value, size_t size, int flags) LSM_HOOK(int, 0, inode_getxattr, struct dentry *dentry, const char *name) LSM_HOOK(int, 0, inode_listxattr, struct dentry *dentry) -LSM_HOOK(int, 0, inode_removexattr, struct dentry *dentry, const char *name) +LSM_HOOK(int, 0, inode_removexattr, struct user_namespace *mnt_userns, + struct dentry *dentry, const char *name) LSM_HOOK(int, 0, inode_need_killpriv, struct dentry *dentry) -LSM_HOOK(int, 0, inode_killpriv, struct dentry *dentry) -LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct inode *inode, - const char *name, void **buffer, bool alloc) +LSM_HOOK(int, 0, inode_killpriv, struct user_namespace *mnt_userns, + struct dentry *dentry) +LSM_HOOK(int, -EOPNOTSUPP, inode_getsecurity, struct user_namespace *mnt_userns, + struct inode *inode, const char *name, void **buffer, bool alloc) LSM_HOOK(int, -EOPNOTSUPP, inode_setsecurity, struct inode *inode, const char *name, const void *value, size_t size, int flags) LSM_HOOK(int, 0, inode_listsecurity, struct inode *inode, char *buffer,
include/linux/lsm_hooks.h +1 -0
@@ -444,6 +444,7 @@* @inode_killpriv: * The setuid bit is being removed. Remove similar security labels. * Called with the dentry->d_inode->i_mutex held. +* @mnt_userns: user namespace of the mount * @dentry is the dentry being changed. * Return 0 on success. If error is returned, then the operation * causing setuid bit removal is failed.
include/linux/security.h +34 -20
95 lines not on this page · raw message
kernel/auditsc.c +3 -2
@@ -1930,7 +1930,7 @@ static inline int audit_copy_fcaps(struct audit_names *name,if (!dentry)return 0 ; - rc =get_vfs_caps_from_disk (dentry, &caps); + rc =get_vfs_caps_from_disk (&init_user_ns, dentry, &caps);if (rc)return rc;
@@ -2481,7 +2481,8 @@ int __audit_log_bprm_fcaps(struct linux_binprm *bprm, ax->d.next = context->aux; context->aux = (void *)ax; -get_vfs_caps_from_disk (bprm->file->f_path.dentry, &vcaps); +get_vfs_caps_from_disk (&init_user_ns, + bprm->file->f_path.dentry, &vcaps); ax->fcap.permitted = vcaps.permitted; ax->fcap.inheritable = vcaps.inheritable;
security/commoncap.c +49 -13
133 lines not on this page · raw message
security/security.c +15 -10
@@ -1280,7 +1280,8 @@ int security_inode_getattr(const struct path *path)return call_int_hook (inode_getattr,0 , path); } -int security_inode_setxattr (struct dentry *dentry,const char *name, +int security_inode_setxattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name,const void *value,size_t size,int flags) {int ret;
@@ -1291,8 +1292,8 @@ int security_inode_setxattr(struct dentry *dentry, const char *name,* SELinux and Smack integrate the cap call, * so assume that all LSMs supplying this call do so. */ - ret =call_int_hook (inode_setxattr,1 , dentry, name, value, size, - flags); + ret =call_int_hook (inode_setxattr,1 , mnt_userns, dentry, name, value, + size, flags);if (ret ==1 ) ret =cap_inode_setxattr (dentry, name, value, size, flags);
@@ -1327,7 +1328,8 @@ int security_inode_listxattr(struct dentry *dentry)return call_int_hook (inode_listxattr,0 , dentry); } -int security_inode_removexattr (struct dentry *dentry,const char *name) +int security_inode_removexattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name) {int ret;
@@ -1337,9 +1339,9 @@ int security_inode_removexattr(struct dentry *dentry, const char *name)* SELinux and Smack integrate the cap call, * so assume that all LSMs supplying this call do so. */ - ret =call_int_hook (inode_removexattr,1 , dentry, name); + ret =call_int_hook (inode_removexattr,1 , mnt_userns, dentry, name);if (ret ==1 ) - ret =cap_inode_removexattr (dentry, name); + ret =cap_inode_removexattr (mnt_userns, dentry, name);if (ret)return ret; ret =ima_inode_removexattr (dentry, name);
@@ -1353,12 +1355,15 @@ int security_inode_need_killpriv(struct dentry *dentry)return call_int_hook (inode_need_killpriv,0 , dentry); } -int security_inode_killpriv (struct dentry *dentry) +int security_inode_killpriv (struct user_namespace *mnt_userns, +struct dentry *dentry) { -return call_int_hook (inode_killpriv,0 , dentry); +return call_int_hook (inode_killpriv,0 , mnt_userns, dentry); } -int security_inode_getsecurity (struct inode *inode,const char *name,void **buffer,bool alloc) +int security_inode_getsecurity (struct user_namespace *mnt_userns, +struct inode *inode,const char *name, +void **buffer,bool alloc) {struct security_hook_list *hp;int rc;
@@ -1369,7 +1374,7 @@ int security_inode_getsecurity(struct inode *inode, const char *name, void **buf* Only one module will provide an attribute with a given name. */ hlist_for_each_entry (hp, &security_hook_heads.inode_getsecurity, list) { - rc = hp->hook.inode_getsecurity (inode, name, buffer, alloc); + rc = hp->hook.inode_getsecurity (mnt_userns, inode, name, buffer, alloc);if (rc !=LSM_RET_DEFAULT (inode_getsecurity))return rc; }
security/selinux/hooks.c +12 -8
@@ -3119,7 +3119,8 @@ static bool has_cap_mac_admin(bool audit)return true; } -static int selinux_inode_setxattr (struct dentry *dentry,const char *name, +static int selinux_inode_setxattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name,const void *value,size_t size,int flags) {struct inode *inode =d_backing_inode (dentry);
@@ -3140,13 +3141,13 @@ static int selinux_inode_setxattr(struct dentry *dentry, const char *name, }if (!selinux_initialized (&selinux_state)) -return (inode_owner_or_capable (&init_user_ns, inode) ?0 : -EPERM ); +return (inode_owner_or_capable (mnt_userns, inode) ?0 : -EPERM ); sbsec = inode->i_sb->s_security;if (!(sbsec->flags &SBLABEL_MNT ))return -EOPNOTSUPP ; -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (mnt_userns, inode))return -EPERM ; ad.type =LSM_AUDIT_DATA_DENTRY ;
@@ -3267,10 +3268,11 @@ static int selinux_inode_listxattr(struct dentry *dentry)return dentry_has_perm (cred, dentry,FILE__GETATTR ); } -static int selinux_inode_removexattr (struct dentry *dentry,const char *name) +static int selinux_inode_removexattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name) {if (strcmp (name,XATTR_NAME_SELINUX )) { -int rc =cap_inode_removexattr (dentry, name); +int rc =cap_inode_removexattr (mnt_userns, dentry, name);if (rc)return rc;
@@ -3336,7 +3338,9 @@ static int selinux_path_notify(const struct path *path, u64 mask,* * Permission check is handled by selinux_inode_getxattr hook. */ -static int selinux_inode_getsecurity (struct inode *inode,const char *name,void **buffer,bool alloc) +static int selinux_inode_getsecurity (struct user_namespace *mnt_userns, +struct inode *inode,const char *name, +void **buffer,bool alloc) {u32 size;int error;
@@ -6533,8 +6537,8 @@ static int selinux_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)static int selinux_inode_getsecctx (struct inode *inode,void **ctx,u32 *ctxlen) {int len =0 ; - len =selinux_inode_getsecurity (inode,XATTR_SELINUX_SUFFIX , - ctx, true); + len =selinux_inode_getsecurity (&init_user_ns, inode, +XATTR_SELINUX_SUFFIX , ctx, true);if (len <0 )return len; *ctxlen = len;
security/smack/smack_lsm.c +8 -6
@@ -1240,7 +1240,8 @@ static int smack_inode_getattr(const struct path *path)* * Returns 0 if access is permitted, an error code otherwise */ -static int smack_inode_setxattr (struct dentry *dentry,const char *name, +static int smack_inode_setxattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name,const void *value,size_t size,int flags) {struct smk_audit_info ad;
@@ -1362,7 +1363,8 @@ static int smack_inode_getxattr(struct dentry *dentry, const char *name)* * Returns 0 if access is permitted, an error code otherwise */ -static int smack_inode_removexattr (struct dentry *dentry,const char *name) +static int smack_inode_removexattr (struct user_namespace *mnt_userns, +struct dentry *dentry,const char *name) {struct inode_smack *isp;struct smk_audit_info ad;
@@ -1377,7 +1379,7 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)if (!smack_privileged (CAP_MAC_ADMIN )) rc = -EPERM ; }else - rc =cap_inode_removexattr (dentry, name); + rc =cap_inode_removexattr (mnt_userns, dentry, name);if (rc !=0 )return rc;
@@ -1420,9 +1422,9 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)* * Returns the size of the attribute or an error code */ -static int smack_inode_getsecurity (struct inode *inode, -const char *name,void **buffer, -bool alloc) +static int smack_inode_getsecurity (struct user_namespace *mnt_userns, +struct inode *inode,const char *name, +void **buffer,bool alloc) {struct socket_smack *ssp;struct socket *sock;
Signature · 1 line
2.30.0
Re: [PATCH v6 10/40] commoncap: handle idmapped mounts
Quoted 7 lines · Christian Brauner
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 11/40 stat: handle idmapped mounts
In reply to Christian BraunerThe generic_fillattr() helper fills in the basic attributes associated with an inode. Enable it to handle idmapped mounts. If the inode is accessed through an idmapped mount map it into the mount's user namespace before we store the uid and gid. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
--- fs/9p/vfs_inode.c | 4 ++-- fs/9p/vfs_inode_dotl.c | 4 ++-- fs/afs/inode.c | 2 +- fs/btrfs/inode.c | 2 +- fs/ceph/inode.c | 2 +- fs/cifs/inode.c | 2 +- fs/coda/inode.c | 2 +- fs/ecryptfs/inode.c | 4 ++-- fs/erofs/inode.c | 2 +- fs/exfat/file.c | 2 +- fs/ext2/inode.c | 2 +- fs/ext4/inode.c | 2 +- fs/f2fs/file.c | 2 +- fs/fat/file.c | 2 +- fs/fuse/dir.c | 2 +- fs/gfs2/inode.c | 2 +- fs/hfsplus/inode.c | 2 +- fs/kernfs/inode.c | 2 +- fs/libfs.c | 4 ++-- fs/minix/inode.c | 2 +- fs/nfs/inode.c | 2 +- fs/nfs/namespace.c | 2 +- fs/ocfs2/file.c | 2 +- fs/orangefs/inode.c | 2 +- fs/proc/base.c | 4 ++-- fs/proc/generic.c | 2 +- fs/proc/proc_net.c | 2 +- fs/proc/proc_sysctl.c | 2 +- fs/proc/root.c | 2 +- fs/stat.c | 20 ++++++++++++++------ fs/sysv/itree.c | 2 +- fs/ubifs/dir.c | 2 +- fs/udf/symlink.c | 2 +- fs/vboxsf/utils.c | 2 +- include/linux/fs.h | 2 +- mm/shmem.c | 2 +- 36 files changed, 54 insertions(+), 46 deletions(-)
fs/9p/vfs_inode.c +2 -2
@@ -1027,7 +1027,7 @@ v9fs_vfs_getattr(const struct path *path, struct kstat *stat,p9_debug (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache ==CACHE_LOOSE || v9ses->cache ==CACHE_FSCACHE ) { -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat);return 0 ; } fid =v9fs_fid_lookup (dentry);
@@ -1040,7 +1040,7 @@ v9fs_vfs_getattr(const struct path *path, struct kstat *stat,return PTR_ERR (st);v9fs_stat2inode (st,d_inode (dentry), dentry->d_sb,0 ); -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat);p9stat_free (st);kfree (st);
fs/9p/vfs_inode_dotl.c +2 -2
@@ -468,7 +468,7 @@ v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,p9_debug (P9_DEBUG_VFS ,"dentry: %p\n" , dentry); v9ses =v9fs_dentry2v9ses (dentry);if (v9ses->cache ==CACHE_LOOSE || v9ses->cache ==CACHE_FSCACHE ) { -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat);return 0 ; } fid =v9fs_fid_lookup (dentry);
@@ -485,7 +485,7 @@ v9fs_vfs_getattr_dotl(const struct path *path, struct kstat *stat,return PTR_ERR (st);v9fs_stat2inode_dotl (st,d_inode (dentry),0 ); -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat);/* Change block size to what the server returned */ stat->blksize = st->st_blksize;
fs/afs/inode.c +1 -1
@@ -745,7 +745,7 @@ int afs_getattr(const struct path *path, struct kstat *stat, do { read_seqbegin_or_lock(&vnode->cb_lock, &seq); - generic_fillattr(inode, stat); + generic_fillattr(&init_user_ns, inode, stat); if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && stat->nlink > 0) stat->nlink -= 1;
fs/btrfs/inode.c +1 -1
@@ -8842,7 +8842,7 @@ static int btrfs_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->dev =BTRFS_I (inode)->root->anon_dev;spin_lock (&BTRFS_I (inode)->lock);
fs/ceph/inode.c +1 -1
@@ -2385,7 +2385,7 @@ int ceph_getattr(const struct path *path, struct kstat *stat,return err; } -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->ino =ceph_present_inode (inode);/*
fs/cifs/inode.c +1 -1
@@ -2408,7 +2408,7 @@ int cifs_getattr(const struct path *path, struct kstat *stat,return rc; } -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->blksize = cifs_sb->ctx->bsize; stat->ino =CIFS_I (inode)->uniqueid;
fs/coda/inode.c +1 -1
@@ -256,7 +256,7 @@ int coda_getattr(const struct path *path, struct kstat *stat, {int err =coda_revalidate_inode (d_inode (path->dentry));if (!err) -generic_fillattr (d_inode (path->dentry), stat); +generic_fillattr (&init_user_ns,d_inode (path->dentry), stat);return err; }
fs/ecryptfs/inode.c +2 -2
@@ -977,7 +977,7 @@ static int ecryptfs_getattr_link(const struct path *path, struct kstat *stat, mount_crypt_stat = &ecryptfs_superblock_to_private ( dentry->d_sb)->mount_crypt_stat; -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat);if (mount_crypt_stat->flags &ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES ) {char *target;size_t targetsiz;
@@ -1005,7 +1005,7 @@ static int ecryptfs_getattr(const struct path *path, struct kstat *stat,if (!rc) {fsstack_copy_attr_all (d_inode (dentry),ecryptfs_inode_to_lower (d_inode (dentry))); -generic_fillattr (d_inode (dentry), stat); +generic_fillattr (&init_user_ns,d_inode (dentry), stat); stat->blocks = lower_stat.blocks; }return rc;
fs/erofs/inode.c +1 -1
@@ -343,7 +343,7 @@ int erofs_getattr(const struct path *path, struct kstat *stat, stat->attributes_mask |= (STATX_ATTR_COMPRESSED |STATX_ATTR_IMMUTABLE ); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/exfat/file.c +1 -1
@@ -273,7 +273,7 @@ int exfat_getattr(const struct path *path, struct kstat *stat,struct inode *inode =d_backing_inode (path->dentry);struct exfat_inode_info *ei =EXFAT_I (inode); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);exfat_truncate_atime (&stat->atime); stat->result_mask |=STATX_BTIME ; stat->btime.tv_sec = ei->i_crtime.tv_sec;
fs/ext2/inode.c +1 -1
@@ -1660,7 +1660,7 @@ int ext2_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/ext4/inode.c +1 -1
@@ -5571,7 +5571,7 @@ int ext4_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_NODUMP | STATX_ATTR_VERITY); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/f2fs/file.c +1 -1
@@ -820,7 +820,7 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_NODUMP | STATX_ATTR_VERITY); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);/* we need to show initial sectors used for inline_data/dentries */ if ((S_ISREG(inode->i_mode) && f2fs_has_inline_data(inode)) ||
fs/fat/file.c +1 -1
@@ -398,7 +398,7 @@ int fat_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) {struct inode *inode =d_inode (path->dentry); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->blksize =MSDOS_SB (inode->i_sb)->cluster_size;if (MSDOS_SB (inode->i_sb)->options.nfs ==FAT_NFS_NOSTALE_RO ) {
fs/fuse/dir.c +1 -1
@@ -1087,7 +1087,7 @@ static int fuse_update_get_attr(struct inode *inode, struct file *file,forget_all_cached_acls (inode); err =fuse_do_getattr (inode, stat, file); }else if (stat) { -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->mode = fi->orig_i_mode; stat->ino = fi->orig_ino; }
fs/gfs2/inode.c +1 -1
@@ -2050,7 +2050,7 @@ static int gfs2_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_IMMUTABLE | STATX_ATTR_NODUMP); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (gfs2_holder_initialized (&gh))gfs2_glock_dq_uninit (&gh);
fs/hfsplus/inode.c +1 -1
@@ -286,7 +286,7 @@ int hfsplus_getattr(const struct path *path, struct kstat *stat, stat->attributes_mask |=STATX_ATTR_APPEND |STATX_ATTR_IMMUTABLE |STATX_ATTR_NODUMP ; -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/kernfs/inode.c +1 -1
@@ -193,7 +193,7 @@ int kernfs_iop_getattr(const struct path *path, struct kstat *stat,kernfs_refresh_inode (kn, inode);mutex_unlock (&kernfs_mutex); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/libfs.c +2 -2
@@ -31,7 +31,7 @@ int simple_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags) { struct inode *inode = d_inode(path->dentry); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->blocks = inode->i_mapping->nrpages << (PAGE_SHIFT -9 );return 0 ; }
@@ -1304,7 +1304,7 @@ static int empty_dir_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int query_flags) { struct inode *inode = d_inode(path->dentry); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/minix/inode.c +1 -1
@@ -658,7 +658,7 @@ int minix_getattr(const struct path *path, struct kstat *stat,struct super_block *sb = path->dentry->d_sb;struct inode *inode =d_inode (path->dentry); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (INODE_VERSION (inode) ==MINIX_V1 ) stat->blocks = (BLOCK_SIZE /512 ) *V1_minix_blocks (stat->size, sb);else
fs/nfs/inode.c +1 -1
@@ -857,7 +857,7 @@ int nfs_getattr(const struct path *path, struct kstat *stat,/* Only return attributes that were revalidated. */ stat->result_mask &= request_mask; out_no_update: -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->ino =nfs_compat_user_ino64 (NFS_FILEID (inode));if (S_ISDIR (inode->i_mode)) stat->blksize =NFS_SERVER (inode)->dtsize;
fs/nfs/namespace.c +1 -1
@@ -213,7 +213,7 @@ nfs_namespace_getattr(const struct path *path, struct kstat *stat, {if (NFS_FH (d_inode (path->dentry))->size !=0 )return nfs_getattr (path, stat, request_mask, query_flags); -generic_fillattr (d_inode (path->dentry), stat); +generic_fillattr (&init_user_ns,d_inode (path->dentry), stat);return 0 ; }
fs/ocfs2/file.c +1 -1
@@ -1313,7 +1313,7 @@ int ocfs2_getattr(const struct path *path, struct kstat *stat, goto bail; } -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);/* * If there is inline data in the inode, the inode will normally not * have data blocks allocated (it may have an external xattr block).
fs/orangefs/inode.c +1 -1
@@ -903,7 +903,7 @@ int orangefs_getattr(const struct path *path, struct kstat *stat, ret =orangefs_inode_getattr (inode, request_mask &STATX_SIZE ?ORANGEFS_GETATTR_SIZE :0 );if (ret ==0 ) { -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);/* override block size reported to stat */ if (!(request_mask &STATX_SIZE ))
fs/proc/base.c +2 -2
@@ -1934,7 +1934,7 @@ int pid_getattr(const struct path *path, struct kstat *stat,struct proc_fs_info *fs_info =proc_sb_info (inode->i_sb);struct task_struct *task; -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->uid =GLOBAL_ROOT_UID ; stat->gid =GLOBAL_ROOT_GID ;
@@ -3803,7 +3803,7 @@ static int proc_task_getattr(const struct path *path, struct kstat *stat, {struct inode *inode =d_inode (path->dentry);struct task_struct *p =get_proc_task (inode); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (p) { stat->nlink +=get_nr_threads (p);
fs/proc/generic.c +1 -1
@@ -145,7 +145,7 @@ static int proc_getattr(const struct path *path, struct kstat *stat, } } -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);return 0 ; }
fs/proc/proc_net.c +1 -1
@@ -297,7 +297,7 @@ static int proc_tgid_net_getattr(const struct path *path, struct kstat *stat, net =get_proc_task_net (inode); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (net !=NULL ) { stat->nlink = net->proc_net->nlink;
fs/proc/proc_sysctl.c +1 -1
@@ -840,7 +840,7 @@ static int proc_sys_getattr(const struct path *path, struct kstat *stat,if (IS_ERR (head))return PTR_ERR (head); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (table) stat->mode = (stat->mode &S_IFMT ) | table->mode;
fs/proc/root.c +1 -1
@@ -311,7 +311,7 @@ void __init proc_root_init(void)static int proc_root_getattr (const struct path *path,struct kstat *stat,u32 request_mask,unsigned int query_flags) { -generic_fillattr (d_inode (path->dentry), stat); +generic_fillattr (&init_user_ns,d_inode (path->dentry), stat); stat->nlink = proc_root.nlink +nr_processes ();return 0 ; }
fs/stat.c +14 -6
@@ -26,21 +26,29 @@/** * generic_fillattr - Fill in the basic attributes from the inode struct -* @inode: Inode to use as the source -* @stat: Where to fill in the attributes +* @mnt_userns: user namespace of the mount the inode was found from +* @inode: Inode to use as the source +* @stat: Where to fill in the attributes * * Fill in the basic attributes in the kstat structure from data that's to be * found on the VFS inode structure. This is the default if no getattr inode * operation is supplied. +* +* If the inode has been found through an idmapped mount the user namespace of +* the vfsmount must be passed through @mnt_userns. This function will then +* take care to map the inode according to @mnt_userns before filling in the +* uid and gid filds. On non-idmapped mounts or if permission checking is to be +* performed on the raw inode simply passs init_user_ns. */ -void generic_fillattr (struct inode *inode,struct kstat *stat) +void generic_fillattr (struct user_namespace *mnt_userns,struct inode *inode, +struct kstat *stat) { stat->dev = inode->i_sb->s_dev; stat->ino = inode->i_ino; stat->mode = inode->i_mode; stat->nlink = inode->i_nlink; - stat->uid = inode->i_uid; - stat->gid = inode->i_gid; + stat->uid =i_uid_into_mnt (mnt_userns, inode); + stat->gid =i_gid_into_mnt (mnt_userns, inode); stat->rdev = inode->i_rdev; stat->size =i_size_read (inode); stat->atime = inode->i_atime;
@@ -87,7 +95,7 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,return inode->i_op->getattr (path, stat, request_mask, query_flags); -generic_fillattr (inode, stat); +generic_fillattr (mnt_user_ns (path->mnt), inode, stat);return 0 ; }EXPORT_SYMBOL (vfs_getattr_nosec);
fs/sysv/itree.c +1 -1
@@ -445,7 +445,7 @@ int sysv_getattr(const struct path *path, struct kstat *stat, u32 request_mask, unsigned int flags) {struct super_block *s = path->dentry->d_sb; -generic_fillattr (d_inode (path->dentry), stat); +generic_fillattr (&init_user_ns,d_inode (path->dentry), stat); stat->blocks = (s->s_blocksize /512 ) *sysv_nblocks (s, stat->size); stat->blksize = s->s_blocksize;return 0 ;
fs/ubifs/dir.c +1 -1
@@ -1589,7 +1589,7 @@ int ubifs_getattr(const struct path *path, struct kstat *stat,STATX_ATTR_ENCRYPTED | STATX_ATTR_IMMUTABLE); -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); stat->blksize =UBIFS_BLOCK_SIZE ; stat->size = ui->ui_size;
fs/udf/symlink.c +1 -1
@@ -159,7 +159,7 @@ static int udf_symlink_getattr(const struct path *path, struct kstat *stat,struct inode *inode =d_backing_inode (dentry);struct page *page; -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat); page =read_mapping_page (inode->i_mapping,0 ,NULL );if (IS_ERR (page))return PTR_ERR (page);
fs/vboxsf/utils.c +1 -1
@@ -233,7 +233,7 @@ int vboxsf_getattr(const struct path *path, struct kstat *kstat,if (err)return err; -generic_fillattr (d_inode (dentry), kstat); +generic_fillattr (&init_user_ns,d_inode (dentry), kstat);return 0 ; }
include/linux/fs.h +1 -1
@@ -3154,7 +3154,7 @@ extern int __page_symlink(struct inode *inode, const char *symname, int len,extern int page_symlink (struct inode *inode,const char *symname,int len);extern const struct inode_operations page_symlink_inode_operations;extern void kfree_link (void *); -extern void generic_fillattr (struct inode *,struct kstat *); +void generic_fillattr (struct user_namespace *,struct inode *,struct kstat *);extern int vfs_getattr_nosec (const struct path *,struct kstat *,u32 ,unsigned int );extern int vfs_getattr (const struct path *,struct kstat *,u32 ,unsigned int );void __inode_add_bytes (struct inode *inode,loff_t bytes);
mm/shmem.c +1 -1
@@ -1072,7 +1072,7 @@ static int shmem_getattr(const struct path *path, struct kstat *stat,shmem_recalc_inode (inode);spin_unlock_irq (&info->lock); } -generic_fillattr (inode, stat); +generic_fillattr (&init_user_ns, inode, stat);if (is_huge_enabled (sb_info)) stat->blksize =HPAGE_PMD_SIZE ;
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 11/40] stat: handle idmapped mounts
Quoted 7 lines · Christian Brauner
The
generic_fillattr()helper fills in the basic attributes associated with an inode. Enable it to handle idmapped mounts. If the inode is accessed through an idmapped mount map it into the mount's user namespace before we store the uid and gid. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 12/40 namei: handle idmapped mounts in may_*() helpers
In reply to Christian BraunerThe may_follow_link(), may_linkat(), may_lookup(), may_open(), may_o_create(), may_create_in_sticky(), may_delete(), and may_create() helpers determine whether the caller is privileged enough to perform the associated operations. Let them handle idmapped mounts by mapping the inode or fsids according to the mount's user namespace. Afterwards the checks are identical to non-idmapped inodes. The patch takes care to retrieve the mount's user namespace right before performing permission checks and passing it down into the fileystem so the user namespace can't change in between by someone idmapping a mount that is currently not idmapped. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/btrfs/ioctl.c | 5 +- fs/init.c | 2 +- fs/inode.c | 2 +- fs/internal.h | 2 +- fs/namei.c | 148 ++++++++++++++++++++++++++++----------------- fs/xattr.c | 2 +- include/linux/fs.h | 14 +++-- 7 files changed, 108 insertions(+), 67 deletions(-)
fs/btrfs/ioctl.c +3 -2
@@ -927,8 +927,9 @@ static int btrfs_may_delete(struct inode *dir, struct dentry *victim, int isdir)return error;if (IS_APPEND (dir))return -EPERM ; -if (check_sticky (dir,d_inode (victim)) ||IS_APPEND (d_inode (victim)) || -IS_IMMUTABLE (d_inode (victim)) ||IS_SWAPFILE (d_inode (victim))) +if (check_sticky (&init_user_ns, dir,d_inode (victim)) || +IS_APPEND (d_inode (victim)) ||IS_IMMUTABLE (d_inode (victim)) || +IS_SWAPFILE (d_inode (victim)))return -EPERM ;if (isdir) {if (!d_is_dir (victim))
fs/init.c +1 -1
@@ -181,7 +181,7 @@ int __init init_link(const char *oldname, const char *newname) error = -EXDEV ;if (old_path.mnt != new_path.mnt) goto out_dput; - error =may_linkat (&old_path); + error =may_linkat (&init_user_ns, &old_path);if (unlikely (error)) goto out_dput; error =security_path_link (old_path.dentry, &new_path, new_dentry);
fs/inode.c +1 -1
@@ -1796,7 +1796,7 @@ bool atime_needs_update(const struct path *path, struct inode *inode)/* Atime updates will likely cause i_uid and i_gid to be written * back improprely if their true value is unknown to the vfs. */ -if (HAS_UNMAPPED_ID (inode)) +if (HAS_UNMAPPED_ID (mnt_user_ns (mnt), inode))return false;if (IS_NOATIME (inode))
fs/internal.h +1 -1
@@ -73,7 +73,7 @@ extern int vfs_path_lookup(struct dentry *, struct vfsmount *, const char *, unsigned int, struct path *);long do_rmdir (int dfd,struct filename *name);long do_unlinkat (int dfd,struct filename *name); -int may_linkat (struct path *link); +int may_linkat (struct user_namespace *mnt_userns,struct path *link);int do_renameat2 (int olddfd,struct filename *oldname,int newdfd,struct filename *newname,unsigned int flags);
fs/namei.c +92 -56
438 lines not on this page · raw message
fs/xattr.c +1 -1
@@ -98,7 +98,7 @@ xattr_permission(struct user_namespace *mnt_userns, struct inode *inode,* to be writen back improperly if their true value is * unknown to the vfs. */ -if (HAS_UNMAPPED_ID (inode)) +if (HAS_UNMAPPED_ID (mnt_userns, inode))return -EPERM ; }
include/linux/fs.h +9 -5
@@ -2083,9 +2083,11 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags#define IS_WHITEOUT (inode) (S_ISCHR(inode->i_mode) && \ (inode)->i_rdev == WHITEOUT_DEV) -static inline bool HAS_UNMAPPED_ID (struct inode *inode) +static inline bool HAS_UNMAPPED_ID (struct user_namespace *mnt_userns, +struct inode *inode) { -return !uid_valid (inode->i_uid) || !gid_valid (inode->i_gid); +return !uid_valid (i_uid_into_mnt (mnt_userns, inode)) || + !gid_valid (i_gid_into_mnt (mnt_userns, inode)); }static inline enum rw_hint file_write_hint (struct file *file)
@@ -2823,7 +2825,8 @@ static inline int path_permission(const struct path *path, int mask)return inode_permission (mnt_user_ns (path->mnt),d_inode (path->dentry), mask); } -extern int __check_sticky (struct inode *dir,struct inode *inode); +int __check_sticky (struct user_namespace *mnt_userns,struct inode *dir, +struct inode *inode);static inline bool execute_ok (struct inode *inode) {
@@ -3442,12 +3445,13 @@ static inline bool is_sxid(umode_t mode)return (mode &S_ISUID ) || ((mode &S_ISGID ) && (mode &S_IXGRP )); } -static inline int check_sticky (struct inode *dir,struct inode *inode) +static inline int check_sticky (struct user_namespace *mnt_userns, +struct inode *dir,struct inode *inode) {if (!(dir->i_mode &S_ISVTX ))return 0 ; -return __check_sticky (dir, inode); +return __check_sticky (mnt_userns, dir, inode); }static inline void inode_has_no_xattr (struct inode *inode)
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 12/40] namei: handle idmapped mounts in may_*() helpers
Quoted 12 lines · Christian Brauner
The
may_follow_link(),may_linkat(),may_lookup(),may_open(),may_o_create(),may_create_in_sticky(),may_delete(), andmay_create()helpers determine whether the caller is privileged enough to perform the associated operations. Let them handle idmapped mounts by mapping the inode or fsids according to the mount's user namespace. Afterwards the checks are identical to non-idmapped inodes. The patch takes care to retrieve the mount's user namespace right before performing permission checks and passing it down into the fileystem so the user namespace can't change in between by someone idmapping a mount that is currently not idmapped. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 13/40 namei: introduce struct renamedata
In reply to Christian BraunerIn order to handle idmapped mounts we will extend the vfs rename helper to take two new arguments in follow up patches. Since this operations already takes a bunch of arguments add a simple struct renamedata and make the current helper use it before we extend it.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
- Christoph Hellwig <[email protected]>:
- Declare variable on separate lines instead of chaining them and wrapping with weird indentation.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
--- fs/cachefiles/namei.c | 9 +++++++-- fs/ecryptfs/inode.c | 10 +++++++--- fs/namei.c | 21 +++++++++++++++------ fs/nfsd/vfs.c | 8 +++++++- fs/overlayfs/overlayfs.h | 9 ++++++++- include/linux/fs.h | 12 +++++++++++- 6 files changed, 55 insertions(+), 14 deletions(-)
fs/cachefiles/namei.c +7 -2
@@ -412,9 +412,14 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,if (ret <0 ) {cachefiles_io_error (cache,"Rename security error %d" , ret); }else { +struct renamedata rd = { + .old_dir =d_inode (dir), + .old_dentry = rep, + .new_dir =d_inode (cache->graveyard), + .new_dentry = grave, + };trace_cachefiles_rename (object, rep, grave, why); - ret =vfs_rename (d_inode (dir), rep, -d_inode (cache->graveyard), grave,NULL ,0 ); + ret =vfs_rename (&rd);if (ret !=0 && ret != -ENOMEM )cachefiles_io_error (cache,"Rename failed with error %d" , ret);
fs/ecryptfs/inode.c +7 -3
@@ -590,6 +590,7 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,struct dentry *lower_new_dir_dentry;struct dentry *trap;struct inode *target_inode; +struct renamedata rd = {};if (flags)return -EINVAL ;
@@ -619,9 +620,12 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, rc = -ENOTEMPTY ; goto out_lock; } - rc =vfs_rename (d_inode (lower_old_dir_dentry), lower_old_dentry, -d_inode (lower_new_dir_dentry), lower_new_dentry, -NULL ,0 ); + + rd.old_dir =d_inode (lower_old_dir_dentry); + rd.old_dentry = lower_old_dentry; + rd.new_dir =d_inode (lower_new_dir_dentry); + rd.new_dentry = lower_new_dentry; + rc =vfs_rename (&rd);if (rc) goto out_lock;if (target_inode)
fs/namei.c +15 -6
@@ -4311,12 +4311,15 @@ SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname* ->i_mutex on parents, which works but leads to some truly excessive * locking]. */ -int vfs_rename (struct inode *old_dir,struct dentry *old_dentry, -struct inode *new_dir,struct dentry *new_dentry, -struct inode **delegated_inode,unsigned int flags) +int vfs_rename (struct renamedata *rd) {int error;struct user_namespace *mnt_userns = &init_user_ns; +struct inode *old_dir = rd->old_dir, *new_dir = rd->new_dir; +struct dentry *old_dentry = rd->old_dentry; +struct dentry *new_dentry = rd->new_dentry; +struct inode **delegated_inode = rd->delegated_inode; +unsigned int flags = rd->flags;bool is_dir =d_is_dir (old_dentry);struct inode *source = old_dentry->d_inode;struct inode *target = new_dentry->d_inode;
@@ -4442,6 +4445,7 @@ EXPORT_SYMBOL(vfs_rename);int do_renameat2 (int olddfd,struct filename *from,int newdfd,struct filename *to,unsigned int flags) { +struct renamedata rd;struct dentry *old_dentry, *new_dentry;struct dentry *trap;struct path old_path, new_path;
@@ -4545,9 +4549,14 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd, &new_path, new_dentry, flags);if (error) goto exit5; - error =vfs_rename (old_path.dentry->d_inode, old_dentry, - new_path.dentry->d_inode, new_dentry, - &delegated_inode, flags); + + rd.old_dir = old_path.dentry->d_inode; + rd.old_dentry = old_dentry; + rd.new_dir = new_path.dentry->d_inode; + rd.new_dentry = new_dentry; + rd.delegated_inode = &delegated_inode; + rd.flags = flags; + error =vfs_rename (&rd); exit5:dput (new_dentry); exit4:
fs/nfsd/vfs.c +7 -1
@@ -1798,7 +1798,13 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, close_cached = true; goto out_dput_old; }else { - host_err =vfs_rename (fdir, odentry, tdir, ndentry,NULL ,0 ); +struct renamedata rd = { + .old_dir = fdir, + .old_dentry = odentry, + .new_dir = tdir, + .new_dentry = ndentry, + }; + host_err =vfs_rename (&rd);if (!host_err) { host_err =commit_metadata (tfhp);if (!host_err)
fs/overlayfs/overlayfs.h +8 -1
@@ -214,9 +214,16 @@ static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, unsigned int flags) {int err; +struct renamedata rd = { + .old_dir = olddir, + .old_dentry = olddentry, + .new_dir = newdir, + .new_dentry = newdentry, + .flags = flags, + };pr_debug ("rename(%pd2, %pd2, 0x%x)\n" , olddentry, newdentry, flags); - err =vfs_rename (olddir, olddentry, newdir, newdentry,NULL , flags); + err =vfs_rename (&rd);if (err) {pr_debug ("...rename(%pd2, %pd2, ...) = %i\n" , olddentry, newdentry, err);
include/linux/fs.h +11 -1
@@ -1775,7 +1775,17 @@ extern int vfs_symlink(struct inode *, struct dentry *, const char *);extern int vfs_link (struct dentry *,struct inode *,struct dentry *,struct inode **);extern int vfs_rmdir (struct inode *,struct dentry *);extern int vfs_unlink (struct inode *,struct dentry *,struct inode **); -extern int vfs_rename (struct inode *,struct dentry *,struct inode *,struct dentry *,struct inode **,unsigned int ); + +struct renamedata { +struct inode *old_dir; +struct dentry *old_dentry; +struct inode *new_dir; +struct dentry *new_dentry; +struct inode **delegated_inode; +unsigned int flags; +} __randomize_layout; + +int vfs_rename (struct renamedata *);static inline int vfs_whiteout (struct inode *dir,struct dentry *dentry) {
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 14/40 namei: prepare for idmapped mounts
In reply to Christian BraunerThe various vfs_*() helpers are called by filesystems or by the vfs itself to perform core operations such as create, link, mkdir, mknod, rename, rmdir, tmpfile and unlink. Enable them to handle idmapped mounts. If the inode is accessed through an idmapped mount map it into the mount's user namespace and pass it down. Afterwards the checks and operations 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.
---
/* v2 */
- Christoph Hellwig <[email protected]>:
- Don't pollute the vfs with additional helpers simply extend the existing helpers with an additional argument and switch all callers.
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove "extern" from headers.
--- drivers/base/devtmpfs.c | 11 +- fs/cachefiles/namei.c | 12 ++- fs/ecryptfs/inode.c | 33 +++--- fs/init.c | 14 +-- fs/namei.c | 227 +++++++++++++++++++++++++++++++-------- fs/nfsd/nfs4recover.c | 6 +- fs/nfsd/vfs.c | 19 ++-- fs/overlayfs/dir.c | 4 +- fs/overlayfs/overlayfs.h | 20 ++-- include/linux/fs.h | 32 ++++-- ipc/mqueue.c | 3 +- net/unix/af_unix.c | 3 +- 12 files changed, 279 insertions(+), 105 deletions(-)
drivers/base/devtmpfs.c +7 -4
@@ -162,7 +162,7 @@ static int dev_mkdir(const char *name, umode_t mode)if (IS_ERR (dentry))return PTR_ERR (dentry); - err =vfs_mkdir (d_inode (path.dentry), dentry, mode); + err =vfs_mkdir (&init_user_ns,d_inode (path.dentry), dentry, mode);if (!err)/* mark as kernel-created inode */ d_inode (dentry)->i_private = &thread;
@@ -212,7 +212,8 @@ static int handle_create(const char *nodename, umode_t mode, kuid_t uid,if (IS_ERR (dentry))return PTR_ERR (dentry); - err =vfs_mknod (d_inode (path.dentry), dentry, mode, dev->devt); + err =vfs_mknod (&init_user_ns,d_inode (path.dentry), dentry, mode, + dev->devt);if (!err) {struct iattr newattrs;
@@ -242,7 +243,8 @@ static int dev_rmdir(const char *name)return PTR_ERR (dentry);if (d_really_is_positive (dentry)) {if (d_inode (dentry)->i_private == &thread) - err =vfs_rmdir (d_inode (parent.dentry), dentry); + err =vfs_rmdir (&init_user_ns,d_inode (parent.dentry), + dentry);else err = -EPERM ; }else {
@@ -330,7 +332,8 @@ static int handle_remove(const char *nodename, struct device *dev)inode_lock (d_inode (dentry));notify_change (&init_user_ns, dentry, &newattrs,NULL );inode_unlock (d_inode (dentry)); - err =vfs_unlink (d_inode (parent.dentry), dentry,NULL ); + err =vfs_unlink (&init_user_ns,d_inode (parent.dentry), + dentry,NULL );if (!err || err == -ENOENT ) deleted =1 ; }
fs/cachefiles/namei.c +8 -4
@@ -311,7 +311,8 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,cachefiles_io_error (cache,"Unlink security error" ); }else {trace_cachefiles_unlink (object, rep, why); - ret =vfs_unlink (d_inode (dir), rep,NULL ); + ret =vfs_unlink (&init_user_ns,d_inode (dir), rep, +NULL );if (preemptive)cachefiles_mark_object_buried (cache, rep, why);
@@ -413,8 +414,10 @@ static int cachefiles_bury_object(struct cachefiles_cache *cache,cachefiles_io_error (cache,"Rename security error %d" , ret); }else {struct renamedata rd = { + .old_mnt_userns = &init_user_ns, .old_dir =d_inode (dir), .old_dentry = rep, + .new_mnt_userns = &init_user_ns, .new_dir =d_inode (cache->graveyard), .new_dentry = grave, };
@@ -566,7 +569,7 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,if (ret <0 ) goto create_error; start = jiffies; - ret =vfs_mkdir (d_inode (dir), next,0 ); + ret =vfs_mkdir (&init_user_ns,d_inode (dir), next,0 );cachefiles_hist (cachefiles_mkdir_histogram, start);if (!key)trace_cachefiles_mkdir (object, next, ret);
@@ -602,7 +605,8 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,if (ret <0 ) goto create_error; start = jiffies; - ret =vfs_create (d_inode (dir), next,S_IFREG , true); + ret =vfs_create (&init_user_ns,d_inode (dir), next, +S_IFREG , true);cachefiles_hist (cachefiles_create_histogram, start);trace_cachefiles_create (object, next, ret);if (ret <0 )
@@ -796,7 +800,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, ret =security_path_mkdir (&path, subdir,0700 );if (ret <0 ) goto mkdir_error; - ret =vfs_mkdir (d_inode (dir), subdir,0700 ); + ret =vfs_mkdir (&init_user_ns,d_inode (dir), subdir,0700 );if (ret <0 ) goto mkdir_error;
fs/ecryptfs/inode.c +20 -13
@@ -141,7 +141,8 @@ static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,else if (d_unhashed (lower_dentry)) rc = -EINVAL ;else - rc =vfs_unlink (lower_dir_inode, lower_dentry,NULL ); + rc =vfs_unlink (&init_user_ns, lower_dir_inode, lower_dentry, +NULL );if (rc) {printk (KERN_ERR "Error in vfs_unlink; rc = [%d]\n" , rc); goto out_unlock;
@@ -180,7 +181,8 @@ ecryptfs_do_create(struct inode *directory_inode, lower_dentry =ecryptfs_dentry_to_lower (ecryptfs_dentry); lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_create (d_inode (lower_dir_dentry), lower_dentry, mode, true); + rc =vfs_create (&init_user_ns,d_inode (lower_dir_dentry), lower_dentry, + mode, true);if (rc) {printk (KERN_ERR "%s: Failure to create dentry in lower fs; " "rc = [%d]\n" , __func__, rc);
@@ -190,7 +192,8 @@ ecryptfs_do_create(struct inode *directory_inode, inode =__ecryptfs_get_inode (d_inode (lower_dentry), directory_inode->i_sb);if (IS_ERR (inode)) { -vfs_unlink (d_inode (lower_dir_dentry), lower_dentry,NULL ); +vfs_unlink (&init_user_ns,d_inode (lower_dir_dentry), + lower_dentry,NULL ); goto out_lock; }fsstack_copy_attr_times (directory_inode,d_inode (lower_dir_dentry));
@@ -436,8 +439,8 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,dget (lower_old_dentry);dget (lower_new_dentry); lower_dir_dentry =lock_parent (lower_new_dentry); - rc =vfs_link (lower_old_dentry,d_inode (lower_dir_dentry), - lower_new_dentry,NULL ); + rc =vfs_link (lower_old_dentry, &init_user_ns, +d_inode (lower_dir_dentry), lower_new_dentry,NULL );if (rc ||d_really_is_negative (lower_new_dentry)) goto out_lock; rc =ecryptfs_interpose (lower_new_dentry, new_dentry, dir->i_sb);
@@ -481,7 +484,7 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry, strlen(symname));if (rc) goto out_lock; - rc =vfs_symlink (d_inode (lower_dir_dentry), lower_dentry, + rc =vfs_symlink (&init_user_ns,d_inode (lower_dir_dentry), lower_dentry, encoded_symname);kfree (encoded_symname);if (rc ||d_really_is_negative (lower_dentry))
@@ -507,7 +510,8 @@ static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode lower_dentry =ecryptfs_dentry_to_lower (dentry); lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mkdir (d_inode (lower_dir_dentry), lower_dentry, mode); + rc =vfs_mkdir (&init_user_ns,d_inode (lower_dir_dentry), lower_dentry, + mode);if (rc ||d_really_is_negative (lower_dentry)) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb);
@@ -541,7 +545,7 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)else if (d_unhashed (lower_dentry)) rc = -EINVAL ;else - rc =vfs_rmdir (lower_dir_inode, lower_dentry); + rc =vfs_rmdir (&init_user_ns, lower_dir_inode, lower_dentry);if (!rc) {clear_nlink (d_inode (dentry));fsstack_copy_attr_times (dir, lower_dir_inode);
@@ -563,7 +567,8 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev lower_dentry =ecryptfs_dentry_to_lower (dentry); lower_dir_dentry =lock_parent (lower_dentry); - rc =vfs_mknod (d_inode (lower_dir_dentry), lower_dentry, mode, dev); + rc =vfs_mknod (&init_user_ns,d_inode (lower_dir_dentry), lower_dentry, + mode, dev);if (rc ||d_really_is_negative (lower_dentry)) goto out; rc =ecryptfs_interpose (lower_dentry, dentry, dir->i_sb);
@@ -621,10 +626,12 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, goto out_lock; } - rd.old_dir =d_inode (lower_old_dir_dentry); - rd.old_dentry = lower_old_dentry; - rd.new_dir =d_inode (lower_new_dir_dentry); - rd.new_dentry = lower_new_dentry; + rd.old_mnt_userns = &init_user_ns; + rd.old_dir =d_inode (lower_old_dir_dentry); + rd.old_dentry = lower_old_dentry; + rd.new_mnt_userns = &init_user_ns; + rd.new_dir =d_inode (lower_new_dir_dentry); + rd.new_dentry = lower_new_dentry; rc =vfs_rename (&rd);if (rc) goto out_lock;
fs/init.c +8 -6
@@ -157,8 +157,8 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev) mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (!error) - error =vfs_mknod (path.dentry->d_inode, dentry, mode, -new_decode_dev (dev)); + error =vfs_mknod (&init_user_ns, path.dentry->d_inode, dentry, + mode,new_decode_dev (dev));done_path_create (&path, dentry);return error; }
@@ -187,8 +187,8 @@ int __init init_link(const char *oldname, const char *newname) error =security_path_link (old_path.dentry, &new_path, new_dentry);if (error) goto out_dput; - error =vfs_link (old_path.dentry, new_path.dentry->d_inode, new_dentry, -NULL ); + error =vfs_link (old_path.dentry, &init_user_ns, + new_path.dentry->d_inode, new_dentry,NULL ); out_dput:done_path_create (&new_path, new_dentry); out:
@@ -207,7 +207,8 @@ int __init init_symlink(const char *oldname, const char *newname)return PTR_ERR (dentry); error =security_path_symlink (&path, dentry, oldname);if (!error) - error =vfs_symlink (path.dentry->d_inode, dentry, oldname); + error =vfs_symlink (&init_user_ns, path.dentry->d_inode, dentry, + oldname);done_path_create (&path, dentry);return error; }
@@ -230,7 +231,8 @@ int __init init_mkdir(const char *pathname, umode_t mode) mode &= ~current_umask (); error =security_path_mkdir (&path, dentry, mode);if (!error) - error =vfs_mkdir (path.dentry->d_inode, dentry, mode); + error =vfs_mkdir (&init_user_ns, path.dentry->d_inode, dentry, + mode);done_path_create (&path, dentry);return error; }
fs/namei.c +184 -43
441 lines not on this page · raw message
fs/nfsd/nfs4recover.c +3 -3
@@ -233,7 +233,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)* as well be forgiving and just succeed silently. */ goto out_put; - status =vfs_mkdir (d_inode (dir), dentry,S_IRWXU ); + status =vfs_mkdir (&init_user_ns,d_inode (dir), dentry,S_IRWXU ); out_put:dput (dentry); out_unlock:
@@ -353,7 +353,7 @@ nfsd4_unlink_clid_dir(char *name, int namlen, struct nfsd_net *nn) status = -ENOENT ;if (d_really_is_negative (dentry)) goto out; - status =vfs_rmdir (d_inode (dir), dentry); + status =vfs_rmdir (&init_user_ns,d_inode (dir), dentry); out:dput (dentry); out_unlock:
@@ -443,7 +443,7 @@ purge_old(struct dentry *parent, struct dentry *child, struct nfsd_net *nn)if (nfs4_has_reclaimed_state (name, nn)) goto out_free; - status =vfs_rmdir (d_inode (parent), child); + status =vfs_rmdir (&init_user_ns,d_inode (parent), child);if (status)printk ("failed to remove client recovery directory %pd\n" , child);
fs/nfsd/vfs.c +11 -8
@@ -1255,12 +1255,12 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp, host_err =0 ;switch (type) {case S_IFREG : - host_err =vfs_create (dirp, dchild, iap->ia_mode, true); + host_err =vfs_create (&init_user_ns, dirp, dchild, iap->ia_mode, true);if (!host_err)nfsd_check_ignore_resizing (iap);break ;case S_IFDIR : - host_err =vfs_mkdir (dirp, dchild, iap->ia_mode); + host_err =vfs_mkdir (&init_user_ns, dirp, dchild, iap->ia_mode);if (!host_err &&unlikely (d_unhashed (dchild))) {struct dentry *d; d = lookup_one_len(dchild->d_name.name,
@@ -1288,7 +1288,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,case S_IFBLK :case S_IFIFO :case S_IFSOCK : - host_err =vfs_mknod (dirp, dchild, iap->ia_mode, rdev); + host_err =vfs_mknod (&init_user_ns, dirp, dchild, + iap->ia_mode, rdev);break ;default : printk(KERN_WARNING "nfsd: bad file type %o in nfsd_create\n",
@@ -1486,7 +1487,7 @@ do_nfsd_create(struct svc_rqst *rqstp, struct svc_fh *fhp,if (!IS_POSIXACL (dirp)) iap->ia_mode &= ~current_umask (); - host_err =vfs_create (dirp, dchild, iap->ia_mode, true); + host_err =vfs_create (&init_user_ns, dirp, dchild, iap->ia_mode, true);if (host_err <0 ) {fh_drop_write (fhp); goto out_nfserr;
@@ -1610,7 +1611,7 @@ nfsd_symlink(struct svc_rqst *rqstp, struct svc_fh *fhp,if (IS_ERR (dnew)) goto out_nfserr; - host_err =vfs_symlink (d_inode (dentry), dnew, path); + host_err =vfs_symlink (&init_user_ns,d_inode (dentry), dnew, path); err =nfserrno (host_err);if (!err) err =nfserrno (commit_metadata (fhp));
@@ -1678,7 +1679,7 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp, err = nfserr_noent;if (d_really_is_negative (dold)) goto out_dput; - host_err =vfs_link (dold, dirp, dnew,NULL ); + host_err =vfs_link (dold, &init_user_ns, dirp, dnew,NULL );if (!host_err) { err =nfserrno (commit_metadata (ffhp));if (!err)
@@ -1799,8 +1800,10 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen, goto out_dput_old; }else {struct renamedata rd = { + .old_mnt_userns = &init_user_ns, .old_dir = fdir, .old_dentry = odentry, + .new_mnt_userns = &init_user_ns, .new_dir = tdir, .new_dentry = ndentry, };
@@ -1891,9 +1894,9 @@ nfsd_unlink(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,if (type !=S_IFDIR ) {if (rdentry->d_sb->s_export_op->flags &EXPORT_OP_CLOSE_BEFORE_UNLINK )nfsd_close_cached_files (rdentry); - host_err =vfs_unlink (dirp, rdentry,NULL ); + host_err =vfs_unlink (&init_user_ns, dirp, rdentry,NULL ); }else { - host_err =vfs_rmdir (dirp, rdentry); + host_err =vfs_rmdir (&init_user_ns, dirp, rdentry); }if (!host_err)
fs/overlayfs/dir.c +2 -2
@@ -821,9 +821,9 @@ static int ovl_remove_upper(struct dentry *dentry, bool is_dir, goto out_dput_upper;if (is_dir) - err =vfs_rmdir (dir, upper); + err =vfs_rmdir (&init_user_ns, dir, upper);else - err =vfs_unlink (dir, upper,NULL ); + err =vfs_unlink (&init_user_ns, dir, upper,NULL );ovl_dir_modified (dentry->d_parent,ovl_type_origin (dentry));/*
fs/overlayfs/overlayfs.h +11 -9
@@ -123,7 +123,7 @@ static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox)static inline int ovl_do_rmdir (struct inode *dir,struct dentry *dentry) { -int err =vfs_rmdir (dir, dentry); +int err =vfs_rmdir (&init_user_ns, dir, dentry);pr_debug ("rmdir(%pd2) = %i\n" , dentry, err);return err;
@@ -131,7 +131,7 @@ static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)static inline int ovl_do_unlink (struct inode *dir,struct dentry *dentry) { -int err =vfs_unlink (dir, dentry,NULL ); +int err =vfs_unlink (&init_user_ns, dir, dentry,NULL );pr_debug ("unlink(%pd2) = %i\n" , dentry, err);return err;
@@ -140,7 +140,7 @@ static inline int ovl_do_unlink(struct inode *dir, struct dentry *dentry)static inline int ovl_do_link (struct dentry *old_dentry,struct inode *dir,struct dentry *new_dentry) { -int err =vfs_link (old_dentry, dir, new_dentry,NULL ); +int err =vfs_link (old_dentry, &init_user_ns, dir, new_dentry,NULL );pr_debug ("link(%pd2, %pd2) = %i\n" , old_dentry, new_dentry, err);return err;
@@ -149,7 +149,7 @@ static inline int ovl_do_link(struct dentry *old_dentry, struct inode *dir,static inline int ovl_do_create (struct inode *dir,struct dentry *dentry,umode_t mode) { -int err =vfs_create (dir, dentry, mode, true); +int err =vfs_create (&init_user_ns, dir, dentry, mode, true);pr_debug ("create(%pd2, 0%o) = %i\n" , dentry, mode, err);return err;
@@ -158,7 +158,7 @@ static inline int ovl_do_create(struct inode *dir, struct dentry *dentry,static inline int ovl_do_mkdir (struct inode *dir,struct dentry *dentry,umode_t mode) { -int err =vfs_mkdir (dir, dentry, mode); +int err =vfs_mkdir (&init_user_ns, dir, dentry, mode);pr_debug ("mkdir(%pd2, 0%o) = %i\n" , dentry, mode, err);return err; }
@@ -166,7 +166,7 @@ static inline int ovl_do_mkdir(struct inode *dir, struct dentry *dentry,static inline int ovl_do_mknod (struct inode *dir,struct dentry *dentry,umode_t mode,dev_t dev) { -int err =vfs_mknod (dir, dentry, mode, dev); +int err =vfs_mknod (&init_user_ns, dir, dentry, mode, dev);pr_debug ("mknod(%pd2, 0%o, 0%o) = %i\n" , dentry, mode, dev, err);return err;
@@ -175,7 +175,7 @@ static inline int ovl_do_mknod(struct inode *dir, struct dentry *dentry,static inline int ovl_do_symlink (struct inode *dir,struct dentry *dentry,const char *oldname) { -int err =vfs_symlink (dir, dentry, oldname); +int err =vfs_symlink (&init_user_ns, dir, dentry, oldname);pr_debug ("symlink(\"%s\", %pd2) = %i\n" , oldname, dentry, err);return err;
@@ -215,8 +215,10 @@ static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry, {int err;struct renamedata rd = { + .old_mnt_userns = &init_user_ns, .old_dir = olddir, .old_dentry = olddentry, + .new_mnt_userns = &init_user_ns, .new_dir = newdir, .new_dentry = newdentry, .flags = flags,
@@ -233,14 +235,14 @@ static inline int ovl_do_rename(struct inode *olddir, struct dentry *olddentry,static inline int ovl_do_whiteout (struct inode *dir,struct dentry *dentry) { -int err =vfs_whiteout (dir, dentry); +int err =vfs_whiteout (&init_user_ns, dir, dentry);pr_debug ("whiteout(%pd2) = %i\n" , dentry, err);return err; }static inline struct dentry *ovl_do_tmpfile (struct dentry *dentry,umode_t mode) { -struct dentry *ret =vfs_tmpfile (dentry, mode,0 ); +struct dentry *ret =vfs_tmpfile (&init_user_ns, dentry, mode,0 );int err =PTR_ERR_OR_ZERO (ret);pr_debug ("tmpfile(%pd2, 0%o) = %i\n" , dentry, mode, err);
include/linux/fs.h +21 -11
@@ -1768,17 +1768,25 @@ bool inode_owner_or_capable(struct user_namespace *mnt_userns,/* * VFS helper functions.. */ -extern int vfs_create (struct inode *,struct dentry *,umode_t ,bool ); -extern int vfs_mkdir (struct inode *,struct dentry *,umode_t ); -extern int vfs_mknod (struct inode *,struct dentry *,umode_t ,dev_t ); -extern int vfs_symlink (struct inode *,struct dentry *,const char *); -extern int vfs_link (struct dentry *,struct inode *,struct dentry *,struct inode **); -extern int vfs_rmdir (struct inode *,struct dentry *); -extern int vfs_unlink (struct inode *,struct dentry *,struct inode **); +int vfs_create (struct user_namespace *,struct inode *, +struct dentry *,umode_t ,bool ); +int vfs_mkdir (struct user_namespace *,struct inode *, +struct dentry *,umode_t ); +int vfs_mknod (struct user_namespace *,struct inode *,struct dentry *, +umode_t ,dev_t ); +int vfs_symlink (struct user_namespace *,struct inode *, +struct dentry *,const char *); +int vfs_link (struct dentry *,struct user_namespace *,struct inode *, +struct dentry *,struct inode **); +int vfs_rmdir (struct user_namespace *,struct inode *,struct dentry *); +int vfs_unlink (struct user_namespace *,struct inode *,struct dentry *, +struct inode **);struct renamedata { +struct user_namespace *old_mnt_userns;struct inode *old_dir;struct dentry *old_dentry; +struct user_namespace *new_mnt_userns;struct inode *new_dir;struct dentry *new_dentry;struct inode **delegated_inode;
@@ -1787,13 +1795,15 @@ struct renamedata {int vfs_rename (struct renamedata *); -static inline int vfs_whiteout (struct inode *dir,struct dentry *dentry) +static inline int vfs_whiteout (struct user_namespace *mnt_userns, +struct inode *dir,struct dentry *dentry) { -return vfs_mknod (dir, dentry,S_IFCHR |WHITEOUT_MODE ,WHITEOUT_DEV ); +return vfs_mknod (mnt_userns, dir, dentry,S_IFCHR |WHITEOUT_MODE , +WHITEOUT_DEV ); } -extern struct dentry *vfs_tmpfile (struct dentry *dentry,umode_t mode, -int open_flag); +struct dentry *vfs_tmpfile (struct user_namespace *mnt_userns, +struct dentry *dentry,umode_t mode,int open_flag); int vfs_mkobj(struct dentry *, umode_t, int (*f)(struct dentry *, umode_t, void *),
ipc/mqueue.c +2 -1
@@ -965,7 +965,8 @@ SYSCALL_DEFINE1(mq_unlink, const char __user *, u_name) err = -ENOENT ; }else {ihold (inode); - err =vfs_unlink (d_inode (dentry->d_parent), dentry,NULL ); + err =vfs_unlink (&init_user_ns,d_inode (dentry->d_parent), + dentry,NULL ); }dput (dentry);
net/unix/af_unix.c +2 -1
@@ -996,7 +996,8 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)*/ err =security_path_mknod (&path, dentry, mode,0 );if (!err) { - err =vfs_mknod (d_inode (path.dentry), dentry, mode,0 ); + err =vfs_mknod (&init_user_ns,d_inode (path.dentry), dentry, + mode,0 );if (!err) { res->mnt =mntget (path.mnt); res->dentry =dget (dentry);
Signature · 7 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 15/40 open: handle idmapped mounts in do_truncate()
In reply to Christian BraunerWhen truncating files the vfs will verify that the caller is privileged over the inode. Extend it to handle idmapped mounts. If the inode is accessed through an idmapped mount it is mapped according to the mount's user namespace. Afterwards the permissions 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.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Remove local mnt_userns variable in favor of calling file_mnt_user_ns() directly.
--- fs/coredump.c | 10 +++++++--- fs/inode.c | 7 ++++--- fs/namei.c | 2 +- fs/open.c | 16 +++++++++------- include/linux/fs.h | 4 ++-- 5 files changed, 23 insertions(+), 16 deletions(-)
fs/coredump.c +7 -3
@@ -703,6 +703,7 @@ void do_coredump(const kernel_siginfo_t *siginfo) goto close_fail; } }else { +struct user_namespace *mnt_userns;struct inode *inode;int open_flags =O_CREAT |O_RDWR |O_NOFOLLOW |O_LARGEFILE |O_EXCL ;
@@ -780,13 +781,15 @@ void do_coredump(const kernel_siginfo_t *siginfo)* a process dumps core while its cwd is e.g. on a vfat * filesystem. */ -if (!uid_eq (inode->i_uid,current_fsuid ())) + mnt_userns =file_mnt_user_ns (cprm.file); +if (!uid_eq (i_uid_into_mnt (mnt_userns, inode),current_fsuid ())) goto close_fail;if ((inode->i_mode &0677 ) !=0600 ) goto close_fail;if (!(cprm.file->f_mode &FMODE_CAN_WRITE )) goto close_fail; -if (do_truncate (cprm.file->f_path.dentry,0 ,0 , cprm.file)) +if (do_truncate (mnt_userns, cprm.file->f_path.dentry, +0 ,0 , cprm.file)) goto close_fail; }
@@ -931,7 +934,8 @@ void dump_truncate(struct coredump_params *cprm)if (file->f_op->llseek && file->f_op->llseek != no_llseek) { offset = file->f_op->llseek (file,0 ,SEEK_CUR );if (i_size_read (file->f_mapping->host) < offset) -do_truncate (file->f_path.dentry, offset,0 , file); +do_truncate (file_mnt_user_ns (file), file->f_path.dentry, + offset,0 , file); } }EXPORT_SYMBOL (dump_truncate);
fs/inode.c +4 -3
@@ -1903,7 +1903,8 @@ int dentry_needs_remove_privs(struct dentry *dentry)return mask; } -static int __remove_privs (struct dentry *dentry,int kill) +static int __remove_privs (struct user_namespace *mnt_userns, +struct dentry *dentry,int kill) {struct iattr newattrs;
@@ -1912,7 +1913,7 @@ static int __remove_privs(struct dentry *dentry, int kill)* Note we call this on write, so notify_change will not * encounter any conflicting delegations: */ -return notify_change (&init_user_ns, dentry, &newattrs,NULL ); +return notify_change (mnt_userns, dentry, &newattrs,NULL ); }/*
@@ -1939,7 +1940,7 @@ int file_remove_privs(struct file *file)if (kill <0 )return kill;if (kill) - error =__remove_privs (dentry, kill); + error =__remove_privs (file_mnt_user_ns (file), dentry, kill);if (!error)inode_has_no_xattr (inode);
fs/namei.c +1 -1
@@ -3009,7 +3009,7 @@ static int handle_truncate(struct file *filp)if (!error) error =security_path_truncate (path);if (!error) { - error =do_truncate (path->dentry,0 , + error =do_truncate (&init_user_ns, path->dentry,0 ,ATTR_MTIME |ATTR_CTIME |ATTR_OPEN , filp); }
fs/open.c +9 -7
@@ -35,8 +35,8 @@#include "internal.h" -int do_truncate (struct dentry *dentry,loff_t length,unsigned int time_attrs, -struct file *filp) +int do_truncate (struct user_namespace *mnt_userns,struct dentry *dentry, +loff_t length,unsigned int time_attrs,struct file *filp) {int ret;struct iattr newattrs;
@@ -61,13 +61,14 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,inode_lock (dentry->d_inode);/* Note any delegations or leases have already been broken: */ - ret =notify_change (&init_user_ns, dentry, &newattrs,NULL ); + ret =notify_change (mnt_userns, dentry, &newattrs,NULL );inode_unlock (dentry->d_inode);return ret; }long vfs_truncate (const struct path *path,loff_t length) { +struct user_namespace *mnt_userns;struct inode *inode;long error;
@@ -83,7 +84,8 @@ long vfs_truncate(const struct path *path, loff_t length)if (error) goto out; - error =inode_permission (&init_user_ns, inode,MAY_WRITE ); + mnt_userns =mnt_user_ns (path->mnt); + error =inode_permission (mnt_userns, inode,MAY_WRITE );if (error) goto mnt_drop_write_and_out;
@@ -107,7 +109,7 @@ long vfs_truncate(const struct path *path, loff_t length)if (!error) error =security_path_truncate (path);if (!error) - error =do_truncate (path->dentry, length,0 ,NULL ); + error =do_truncate (mnt_userns, path->dentry, length,0 ,NULL ); put_write_and_out:put_write_access (inode);
@@ -186,13 +188,13 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small)/* Check IS_APPEND on real upper inode */ if (IS_APPEND (file_inode (f.file))) goto out_putf; -sb_start_write (inode->i_sb); error =locks_verify_truncate (inode, f.file, length);if (!error) error =security_path_truncate (&f.file->f_path);if (!error) - error =do_truncate (dentry, length,ATTR_MTIME |ATTR_CTIME , f.file); + error =do_truncate (file_mnt_user_ns (f.file), dentry, length, +ATTR_MTIME |ATTR_CTIME , f.file);sb_end_write (inode->i_sb); out_putf:fdput (f);
include/linux/fs.h +2 -2
@@ -2593,8 +2593,8 @@ static inline struct user_namespace *file_mnt_user_ns(struct file *file)return mnt_user_ns (file->f_path.mnt); }extern long vfs_truncate (const struct path *,loff_t ); -extern int do_truncate (struct dentry *,loff_t start,unsigned int time_attrs, -struct file *filp); +int do_truncate (struct user_namespace *,struct dentry *,loff_t start, +unsigned int time_attrs,struct file *filp);extern int vfs_fallocate (struct file *file,int mode,loff_t offset,loff_t len); extern long do_sys_open(int dfd, const char __user *filename, int flags,
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 15/40] open: handle idmapped mounts in do_truncate()
Looks good,
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 16/40 open: handle idmapped mounts
In reply to Christian BraunerFor core file operations such as changing directories or chrooting, determining file access, changing mode or ownership the vfs will verify that the caller is privileged over the inode. Extend the various helpers to handle idmapped mounts. If the inode is accessed through an idmapped mount map it into the mount's user namespace. Afterwards the permissions checks are identical to non-idmapped mounts. When changing file ownership we need to map the uid and gid 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.
---
/* v2 */
unchanged
/* v3 */
- David Howells <[email protected]>:
- Remove mnt_idmapped() check after removing mnt_idmapped() helper in earlier patches.
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Make use of new path_permission() helper.
--- fs/open.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/open.c +9 -4
@@ -438,7 +438,7 @@ static long do_faccessat(int dfd, const char __user *filename, int mode, int fla goto out_path_release; } - res =inode_permission (&init_user_ns, inode, mode |MAY_ACCESS ); + res =inode_permission (mnt_user_ns (path.mnt), inode, mode |MAY_ACCESS );/* SuS v2 requires we report a read only fs too */ if (res || !(mode &S_IWOTH ) ||special_file (inode->i_mode)) goto out_path_release;
@@ -582,8 +582,8 @@ int chmod_common(const struct path *path, umode_t mode) goto out_unlock; newattrs.ia_mode = (mode &S_IALLUGO ) | (inode->i_mode & ~S_IALLUGO ); newattrs.ia_valid =ATTR_MODE |ATTR_CTIME ; - error =notify_change (&init_user_ns, path->dentry, &newattrs, - &delegated_inode); + error =notify_change (mnt_user_ns (path->mnt), path->dentry, + &newattrs, &delegated_inode); out_unlock:inode_unlock (inode);if (delegated_inode) {
@@ -644,6 +644,7 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)int chown_common (const struct path *path,uid_t user,gid_t group) { +struct user_namespace *mnt_userns;struct inode *inode = path->dentry->d_inode;struct inode *delegated_inode =NULL ;int error;
@@ -654,6 +655,10 @@ int chown_common(const struct path *path, uid_t user, gid_t group) uid =make_kuid (current_user_ns (), user); gid =make_kgid (current_user_ns (), group); + mnt_userns =mnt_user_ns (path->mnt); + uid =kuid_from_mnt (mnt_userns, uid); + gid =kgid_from_mnt (mnt_userns, gid); + retry_deleg: newattrs.ia_valid =ATTR_CTIME ;if (user != (uid_t) -1 ) {
@@ -674,7 +679,7 @@ int chown_common(const struct path *path, uid_t user, gid_t group)inode_lock (inode); error =security_path_chown (path, uid, gid);if (!error) - error =notify_change (&init_user_ns, path->dentry, &newattrs, + error =notify_change (mnt_userns, path->dentry, &newattrs, &delegated_inode);inode_unlock (inode);if (delegated_inode) {
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 16/40] open: handle idmapped mounts
Quoted 10 lines · Christian Brauner
For core file operations such as changing directories or chrooting, determining file access, changing mode or ownership the vfs will verify that the caller is privileged over the inode. Extend the various helpers to handle idmapped mounts. If the inode is accessed through an idmapped mount map it into the mount's user namespace. Afterwards the permissions checks are identical to non-idmapped mounts. When changing file ownership we need to map the uid and gid 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.
Quoted 6 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 16/40] open: handle idmapped mounts
In reply to Christian BraunerLooks good,
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 17/40 af_unix: handle idmapped mounts
In reply to Christian BraunerWhen binding a non-abstract AF_UNIX socket it will gain a representation in the filesystem. Enable the socket infrastructure to handle idmapped mounts by passing down the user namespace of the mount the socket will be created from. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- net/unix/af_unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/unix/af_unix.c +2 -2
@@ -996,8 +996,8 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)*/ err =security_path_mknod (&path, dentry, mode,0 );if (!err) { - err =vfs_mknod (&init_user_ns,d_inode (path.dentry), dentry, - mode,0 ); + err =vfs_mknod (mnt_user_ns (path.mnt),d_inode (path.dentry), + dentry, mode,0 );if (!err) { res->mnt =mntget (path.mnt); res->dentry =dget (dentry);
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 17/40] af_unix: handle idmapped mounts
Quoted 6 lines · Christian Brauner
When binding a non-abstract
AF_UNIXsocket it will gain a representation in the filesystem. Enable the socket infrastructure to handle idmapped mounts by passing down the user namespace of the mount the socket will be created from. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 18/40 utimes: handle idmapped mounts
In reply to Christian BraunerEnable the vfs_utimes() helper to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Don't use unnecessary local variable just call mnt_user_ns() directly.
--- fs/utimes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/utimes.c +1 -1
@@ -62,7 +62,7 @@ int vfs_utimes(const struct path *path, struct timespec64 *times) } retry_deleg:inode_lock (inode); - error =notify_change (&init_user_ns, path->dentry, &newattrs, + error =notify_change (mnt_user_ns (path->mnt), path->dentry, &newattrs, &delegated_inode);inode_unlock (inode);if (delegated_inode) {
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 18/40] utimes: handle idmapped mounts
Quoted 5 lines · Christian Brauner
Enable the
vfs_utimes()helper to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 19/40 fcntl: handle idmapped mounts
In reply to Christian BraunerEnable the setfl() helper to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
patch introduced
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Use file_mnt_user_ns() helper.
--- fs/fcntl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fcntl.c +2 -1
@@ -25,6 +25,7 @@#include <linux/user_namespace.h> #include <linux/memfd.h> #include <linux/compat.h> +#include <linux/mount.h> #include <linux/poll.h> #include <asm/siginfo.h>
@@ -46,7 +47,7 @@ static int setfl(int fd, struct file * filp, unsigned long arg)/* O_NOATIME can only be set by the owner or superuser */ if ((arg &O_NOATIME ) && !(filp->f_flags &O_NOATIME )) -if (!inode_owner_or_capable (&init_user_ns, inode)) +if (!inode_owner_or_capable (file_mnt_user_ns (filp), inode))return -EPERM ;/* required for strict SunOS emulation */
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 19/40] fcntl: handle idmapped mounts
Quoted 11 lines · Christian Brauner
Enable the
setfl()helper to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 20/40 init: handle idmapped mounts
In reply to Christian BraunerEnable the init helpers to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
patch introduced
/* v3 */
unchanged
/* v4 */
unchanged
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Use new path_permission() helper.
--- fs/init.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
fs/init.c +11 -9
@@ -157,8 +157,8 @@ int __init init_mknod(const char *filename, umode_t mode, unsigned int dev) mode &= ~current_umask (); error =security_path_mknod (&path, dentry, mode, dev);if (!error) - error =vfs_mknod (&init_user_ns, path.dentry->d_inode, dentry, - mode,new_decode_dev (dev)); + error =vfs_mknod (mnt_user_ns (path.mnt), path.dentry->d_inode, + dentry, mode,new_decode_dev (dev));done_path_create (&path, dentry);return error; }
@@ -167,6 +167,7 @@ int __init init_link(const char *oldname, const char *newname) {struct dentry *new_dentry;struct path old_path, new_path; +struct user_namespace *mnt_userns;int error; error =kern_path (oldname,0 , &old_path);
@@ -181,14 +182,15 @@ int __init init_link(const char *oldname, const char *newname) error = -EXDEV ;if (old_path.mnt != new_path.mnt) goto out_dput; - error =may_linkat (&init_user_ns, &old_path); + mnt_userns =mnt_user_ns (new_path.mnt); + error =may_linkat (mnt_userns, &old_path);if (unlikely (error)) goto out_dput; error =security_path_link (old_path.dentry, &new_path, new_dentry);if (error) goto out_dput; - error =vfs_link (old_path.dentry, &init_user_ns, - new_path.dentry->d_inode, new_dentry,NULL ); + error =vfs_link (old_path.dentry, mnt_userns, new_path.dentry->d_inode, + new_dentry,NULL ); out_dput:done_path_create (&new_path, new_dentry); out:
@@ -207,8 +209,8 @@ int __init init_symlink(const char *oldname, const char *newname)return PTR_ERR (dentry); error =security_path_symlink (&path, dentry, oldname);if (!error) - error =vfs_symlink (&init_user_ns, path.dentry->d_inode, dentry, - oldname); + error =vfs_symlink (mnt_user_ns (path.mnt), path.dentry->d_inode, + dentry, oldname);done_path_create (&path, dentry);return error; }
@@ -231,8 +233,8 @@ int __init init_mkdir(const char *pathname, umode_t mode) mode &= ~current_umask (); error =security_path_mkdir (&path, dentry, mode);if (!error) - error =vfs_mkdir (&init_user_ns, path.dentry->d_inode, dentry, - mode); + error =vfs_mkdir (mnt_user_ns (path.mnt), path.dentry->d_inode, + dentry, mode);done_path_create (&path, dentry);return error; }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 20/40] init: handle idmapped mounts
Note that in the early init code the user namespace must be init_user_ns by definition. But passing on the information from the file/path seem ok just in case someone copy and pastes this code..
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 21/40 ioctl: handle idmapped mounts
In reply to Christian BraunerEnable generic ioctls to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
patch introduced
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Make use of file_permission() helper.
--- fs/remap_range.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/remap_range.c +5 -2
@@ -432,13 +432,16 @@ EXPORT_SYMBOL(vfs_clone_file_range);/* Check whether we are allowed to dedupe the destination file */ static bool allow_file_dedupe (struct file *file) { +struct user_namespace *mnt_userns =file_mnt_user_ns (file); +struct inode *inode =file_inode (file); +if (capable (CAP_SYS_ADMIN ))return true;if (file->f_mode &FMODE_WRITE )return true; -if (uid_eq (current_fsuid (),file_inode (file)->i_uid)) +if (uid_eq (current_fsuid (),i_uid_into_mnt (mnt_userns, inode)))return true; -if (!inode_permission (&init_user_ns,file_inode (file),MAY_WRITE )) +if (!inode_permission (mnt_userns, inode,MAY_WRITE ))return true;return false; }
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 21/40] ioctl: handle idmapped mounts
Quoted 11 lines · Christian Brauner
Enable generic ioctls to handle idmapped mounts by passing down the mount's user namespace. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 22/40 would_dump: handle idmapped mounts
In reply to Christian BraunerWhen determining whether or not to create a coredump the vfs will verify that the caller is privileged over the inode. Make the would_dump() helper handle idmapped mounts by passing down the mount's user namespace of the exec file. If the initial user namespace is passed nothing changes so non-idmapped mounts will see identical behavior as before.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
/* v6 */
unchanged
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
--- fs/exec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/exec.c +3 -3
@@ -1404,15 +1404,15 @@ EXPORT_SYMBOL(begin_new_exec);void would_dump (struct linux_binprm *bprm,struct file *file) {struct inode *inode =file_inode (file); -if (inode_permission (&init_user_ns, inode,MAY_READ ) <0 ) { +struct user_namespace *mnt_userns =file_mnt_user_ns (file); +if (inode_permission (mnt_userns, inode,MAY_READ ) <0 ) {struct user_namespace *old, *user_ns; bprm->interp_flags |=BINPRM_FLAGS_ENFORCE_NONDUMP ;/* Ensure mm->user_ns contains the executable */ user_ns = old = bprm->mm->user_ns;while ((user_ns != &init_user_ns) && - !privileged_wrt_inode_uidgid (user_ns, &init_user_ns, - inode)) + !privileged_wrt_inode_uidgid (user_ns, mnt_userns, inode)) user_ns = user_ns->parent;if (old != user_ns) {
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
PATCH v6 23/40 exec: handle idmapped mounts
In reply to Christian BraunerWhen 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.
---
/* v2 */
unchanged
/* v3 */
unchanged
/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent.
/* v5 */
unchanged
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
/* v6 */
base-commit: 19c329f6808995b142b3966301f217c831e7cf31
- Christoph Hellwig <[email protected]>:
- Use new file_mnt_user_ns() helper.
--- fs/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/exec.c +5 -2
@@ -1580,6 +1580,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)static void bprm_fill_uid (struct linux_binprm *bprm,struct file *file) {/* Handle suid and sgid on files */ +struct user_namespace *mnt_userns;struct inode *inode;unsigned int mode;kuid_t uid;
@@ -1596,13 +1597,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)if (!(mode & (S_ISUID |S_ISGID )))return ; + mnt_userns =file_mnt_user_ns (file); +/* Be careful if suid/sgid is set */ inode_lock (inode);/* reload atomically mode/uid/gid now that lock held */ mode = inode->i_mode; - uid = inode->i_uid; - gid = inode->i_gid; + uid =i_uid_into_mnt (mnt_userns, inode); + gid =i_gid_into_mnt (mnt_userns, inode);inode_unlock (inode);/* We ignore suid/sgid if there are no mappings for them in the ns */
Signature · 6 lines
2.30.0 _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 23/40] exec: handle idmapped mounts
Quoted 9 lines · Christian Brauner
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. Letbprm_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.
Quoted 7 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>
Signature · 7 lines
James Morris <[email protected]> _______________________________________________ Containers mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 23/40] exec: handle idmapped mounts
In reply to Christian BraunerQuoted 8 lines · Christian Brauner
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. Letbprm_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.
This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions.
Eric
Quoted 52 lines
Cc Christoph Hellwig <[email protected]>Cc David Howells <[email protected]>Cc Al Viro <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Christian Brauner <[email protected]>---
/* v2 */
unchanged/* v3 */
unchanged/* v4 */
- Serge Hallyn <[email protected]>:
- Use "mnt_userns" to refer to a vfsmount's userns everywhere to make terminology consistent./* v5 */
unchanged
base-commit:7c53f6b671f4aba70ff15e1b05148b10d58c2837/* v6 */
base-commit:19c329f6808995b142b3966301f217c831e7cf31- Christoph Hellwig <[email protected]>:
- Use newfile_mnt_user_ns()helper.--- fs/exec.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/exec.c +3
-0@@ -1580,6 +1580,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)static void bprm_fill_uid (struct linux_binprm *bprm,struct file *file) {/* Handle suid and sgid on files */ +struct user_namespace *mnt_userns;struct inode *inode;unsigned int mode;kuid_t uid;@@ -1596,13 +1597,15 @@ static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file)if (!(mode & (S_ISUID |S_ISGID )))return ; + mnt_userns =file_mnt_user_ns (file); +/* Be careful if suid/sgid is set */ inode_lock (inode);
fs/exec.c static void bprm_fill_uid(struct linux_binprm *bprm, struct file *file) · line 1611
Quoted 10 lines
fs/exec.c +2
-2/* reload atomically mode/uid/gid now that lock held */ mode = inode->i_mode; - uid = inode->i_uid; - gid = inode->i_gid; + uid =i_uid_into_mnt (mnt_userns, inode); + gid =i_gid_into_mnt (mnt_userns, inode);inode_unlock (inode);/* We ignore suid/sgid if there are no mappings for them in the ns */
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 23/40] exec: handle idmapped mounts
Quoted 11 lines · Eric W. Biederman
Quoted 8 lines · Christian Brauner
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. Letbprm_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.
Quoted 2 lines
This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions.
Thanks for looking. Vfs v3 caps are handled earlier in the series. I'm not sure what you're referring to here. There are tests in xfstests that verify vfs3 capability behavior.
Christian
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Serge E. Hallyn
maintainerRe: [PATCH v6 23/40] exec: handle idmapped mounts
Quoted 12 lines · Christian Brauner
Quoted 11 lines · Eric W. Biederman
Quoted 8 lines · Christian Brauner
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. Letbprm_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.
Quoted 6 lines
Quoted 2 lines
This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions.
Thanks for looking. Vfs v3 caps are handled earlier in the series. I'm not sure what you're referring to here. There are tests in xfstests that verify vfs3 capability behavior.
*just* to make sure i'm not misunderstanding - s/vfs3/v3/ right?
_______________________________________________
Containers mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Re: [PATCH v6 23/40] exec: handle idmapped mounts
Quoted 13 lines · Serge Hallyn
Quoted 12 lines · Christian Brauner
Quoted 11 lines · Eric W. Biederman
Quoted 8 lines · Christian Brauner
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. Letbprm_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.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions.
Thanks for looking. Vfs v3 caps are handled earlier in the series. I'm not sure what you're referring to here. There are tests in xfstests that verify vfs3 capability behavior.
*just* to make sure i'm not misunderstanding - s/vfs3/v3/ right?
Yes, in my mind it's always as "vfs v3 caps -> vfs3 caps". Sorry for the confusion.
_______________________________________________
Containers mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers
Serge E. Hallyn
maintainerRe: [PATCH v6 23/40] exec: handle idmapped mounts
In reply to Christian BraunerQuoted 12 lines · Christian Brauner
Quoted 11 lines · Eric W. Biederman
Quoted 8 lines · Christian Brauner
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. Letbprm_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.
Quoted 8 lines
Quoted 2 lines
This does not handle the v3 capabilites xattr with embeds a uid. So at least at that level you are missing some critical conversions.
Thanks for looking. Vfs v3 caps are handled earlier in the series. I'm not sure what you're referring to here. There are tests in xfstests that verify vfs3 capability behavior.
Christian
So fwiw I just tested it manually as well. Scenario:
uid 1000 user ubuntu
uid 1001 user u2
sudo ./mount-idmapped --map-mount b:1000:1001:1 /home/ubuntu/ /mnt su - u2
cp /usr/bin/id /mnt/
unshare -Urm
setcap cap_setuid=pe /mnt/id
At this point, from init_user_ns,
ubuntu@fscaps:~/mount-idmapped$ /home/u2/rcap /mnt/id v3, rootid is 1001 ubuntu@fscaps:~/mount-idmapped$ /home/u2/rcap //home/ubuntu/id v3, rootid is 1000
-serge
_______________________________________________
Containers mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/containers