crosvm/seccomp/arm
Chirantan Ekbote 814a8da0ed devices: fs: Use 2 stage create and mkdir
When creating a file or directory the virtio-fs server changes its
effective uid and gid to the uid and gid of the process that made the
call.  This ensures that the file or directory has the correct owner and
group when it is created and also serves as an access check to ensure
that the process that made the call has permission to modify the parent
directory.

However, this causes an EACCES error when the following conditions are
met:

  * The parent directory has g+rw permissions with gid A
  * The process has gid B but has A in its list of supplementary groups

In this case the fuse context only contains gid B, which doesn't have
permission to modify the parent directory.

Unfortunately there's no way for us to detect this on the server side so
instead we just have to rely on the permission checks carried out by the
kernel driver. If the server receives a create call, then assume that
the kernel has verified that the process is allowed to create that
file/directory and just create it without changing the server thread's
uid and gid.

Additionally, in order to ensure that a newly created file appears
atomically in the parent directory with the proper owner and group,
change the create implementation to use `O_TMPFILE` and `linkat` as
described in the open(2) manpage.  There is no `O_TMPFILE` equivalent
for directories so create a "hidden" directory with a randomly generated
name, modify the uid/gid and mode, and then rename it into place.

BUG=b:156696212
TEST=tast run $DUT vm.Virtiofs
TEST=Create a test directory with group wayland and permissions g+rw.
     Then run `su -s /bin/bash -c 'touch ${dir}/foo' - crosvm` and
     `su -s /bin/bash -c 'mkdir ${dir}/bar' - crosvm`.

Change-Id: If5fbcb1b011664c7c1ac29542a2f90d129c34962
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2217534
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
2020-06-04 12:49:49 +00:00
..
9p_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
balloon_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
block_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
common_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
cras_audio_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
fs_device.policy devices: fs: Use 2 stage create and mkdir 2020-06-04 12:49:49 +00:00
gpu_device.policy seccomp: gpu: allow sysinfo 2020-04-24 16:02:12 +00:00
input_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
net_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
null_audio_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
pmem_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
rng_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
serial.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
tpm_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
vhost_net_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
vhost_vsock_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
wl_device.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00
xhci.policy seccomp: remove redundant unconditional arm/arm64 rules 2020-02-04 23:27:21 +00:00