Re: [RFC] PCI: allow sysfs file owner to read the config space with CAP_SYS_RAWIO

From: Allen
Date: Mon Oct 19 2020 - 09:21:54 EST


> > > >
> > > > Access to pci config space is explictly checked with CAP_SYS_ADMIN
> > > > in order to read configuration space past the frist 64B.
> > > >
> > > > Since the path is only for reading, could we use CAP_SYS_RAWIO?
> > >
> > > Why? What needs this reduced capability?
> >
> > Thanks for the review.
> >
> > We need read access to /sys/bus/pci/devices/, We need write access to config,
> > remove, rescan & enable files under the device directory for each PCIe
> > functions & the downstream PCIe port.
> >
> > We need r/w access to sysfs to unbind and rebind the root complex.
>
> That didn't answer my question at all.

Sorry about that, breaking it down:

When the machine first boots, the VFIO device bindings under /dev/vfio
are not present.

root@localhost:/tmp# ls -l /dev/vfio/
total 0
crw-rw-rw-. 1 root root 10, 196 Jan 5 01:47 vfio

We have an agent which needs to run the following commands (We get
access denied here and need permissions to do this).
echo -n xxxx yyyy > /sys/module/vfio_pci/drivers/pci:vfio-pci/new_id
echo -n xxxx yyyy > /sys/module/vfio_pci/drivers/pci:vfio-pci/new_id

And we want to avoid handing CAP_SYS_ADMIN here. Which is why the
thought about CAP_SYS_RAWIO.
>
> Why can't you have the process that wants to do all of the above, have
> admin rights as well? Doing all of that is _very_ low-level and can
> cause all sorts of horrible things to happen to your machine, and is not
> really "raw io" in the traditional sense at all, right?


If the above approach is going to cause the system to do horrible things,
then I'll drop the idea.

--
- Allen