Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 911723 - sys-apps/systemd-254: tmpfiles/udev race causing broken permissions (app-emulation/libvirt-9.6.0 cannot use PCI passthru due to wrong perms on /dev/vfio/vfio)
Summary: sys-apps/systemd-254: tmpfiles/udev race causing broken permissions (app-emul...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Gentoo systemd Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-04 19:26 UTC by Anton Gubarkov
Modified: 2023-08-17 01:08 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Gubarkov 2023-08-04 19:26:13 UTC
After upgrading to libvirt-9.6.0 noticed that I can no longer start my VM with my PCI wifi adapter given to it.

The diag was about not authorized to open /dev/vfio/vfio

When I examined the permissions on /dev/vfio/vfio I've seen:

PF16W6Y2 ~ # ls -l /dev/vfio/vfio
crw------- 1 root root 10, 196 авг  3 08:34 /dev/vfio/vfio


Naturally, chgrp qemu /dev/vfio/vfio && chmod g+rw /dev/vfio/vfio gave me the desired result immediately.

I've searched thru the udev directories and I found that the only udev rule for vfio is:

PF16W6Y2 /etc/udev/rules.d # grep -r vfio /usr/lib/udev/rules.d/ /run/udev/ /etc/udev/
/usr/lib/udev/rules.d/50-udev-default.rules:KERNEL=="vfio", MODE="0666", OPTIONS+="static_node=vfio/vfio"

apparently when /dev/vfio/vfio is supposed to be world-read/writable,I should have no problems. 
I wonder who/what may have changed the perms...
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-08-04 19:36:27 UTC
... https://github.com/systemd/systemd/issues/28653, maybe?
Comment 2 Michal Prívozník 2023-08-04 19:57:06 UTC
Interesting. This is qemu:///system URI, I assume. In that case, by default, libvirt would create a private /dev (see namespaces in /etc/libvirt/qemu.conf) and inside it, /dev/vfio/vfio; but it assumes the correct seclabel is set. IOW, libvirt should not change ownership of the /dev/vfio/vfio file.

You can see if it's udev by manually attaching the PCI device to vfio, e.g. like this:

  virsh nodedev-detach pci_XXX....

if /dev/vfio/vfio ownership changes after this step then it's udev. Or if you want to take libvirt out of the picture completely, you can:

  echo vfio-pci > /sys/bus/pci/devices/$PCI_ADDRESS/driver_override
  echo $PCI_ADDRESS > /sys/bus/pci/drivers_probe

This is essentially what libvirt does under the hood anyways.
BTW: I don't have that udev rule file, but I'm running openrc. Is this systemd?
Comment 3 Michal Prívozník 2023-08-05 04:43:01 UTC
Yep, looks like systemd issue:

https://github.com/yuwata/systemd/commit/33b91308c26ca5d512e43b6b32d596a2c9237d04

(follow links in the commit message)

Thanks Sam for pointing us in the right direction!
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-08-05 23:04:50 UTC
I'll backport the fix.
Comment 5 Larry the Git Cow gentoo-dev 2023-08-05 23:07:07 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=939a1468f8957a670026888a01d4601a00f17142

commit 939a1468f8957a670026888a01d4601a00f17142
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-08-05 23:06:46 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-08-05 23:06:54 +0000

    sys-apps/systemd: backport tmpfiles/udev permissions race fix
    
    Closes: https://bugs.gentoo.org/911723
    Signed-off-by: Sam James <sam@gentoo.org>

 .../systemd/files/systemd-254-tmpfiles-udev.patch  |  88 ++++
 sys-apps/systemd/systemd-254-r2.ebuild             | 528 +++++++++++++++++++++
 2 files changed, 616 insertions(+)
Comment 6 Anton Gubarkov 2023-08-06 17:08:15 UTC
systemd-254-r2 didn't fix this for me... I still have to manually modify the perms on /dev/vfio/vfio
Comment 8 Larry the Git Cow gentoo-dev 2023-08-09 21:06:29 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f5eda40dae56a34f3d44e3973e88aafbabc97998

commit f5eda40dae56a34f3d44e3973e88aafbabc97998
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-08-09 21:05:44 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-08-09 21:05:44 +0000

    sys-apps/systemd: add 254.1
    
    Bug: https://bugs.gentoo.org/911723
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-apps/systemd/Manifest             |   1 +
 sys-apps/systemd/systemd-254.1.ebuild | 525 ++++++++++++++++++++++++++++++++++
 2 files changed, 526 insertions(+)
Comment 9 Piotr Chmura 2023-08-16 17:56:01 UTC
systemd-254.1

I've got similar problem, but with /dev/rfkill

After boot it has permissions 600 (defined in /run/tmpfiles.d/static-nodes.conf)

$ cat /run/tmpfiles.d/static-nodes.conf 
c! /dev/ppp 0600 - - - 108:0
d /dev/snd 0755 - - -
c! /dev/snd/timer 0600 - - - 116:33
d /dev/snd 0755 - - -
c! /dev/snd/seq 0600 - - - 116:1
c! /dev/rfkill 0600 - - - 10:242


after
# udevadm test /dev/rfkill

udev sets permissions to proper value of 644, as defined in /lib/udev/rules.d/50-udev-default.rules:101
Comment 10 Mike Gilbert gentoo-dev 2023-08-16 18:35:53 UTC
I have linked several PRs from upstream. Rather than attempting to backport the changes, I'm waiting for a new stable release.
Comment 11 Piotr Chmura 2023-08-16 20:09:19 UTC
I just checked git version (systemd-9999) - works fine for me.
Comment 12 Larry the Git Cow gentoo-dev 2023-08-17 01:08:07 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2dcfd6ce1952b2c37fefd04fe11cfbb1ef8ebe41

commit 2dcfd6ce1952b2c37fefd04fe11cfbb1ef8ebe41
Author:     Mike Gilbert <floppym@gentoo.org>
AuthorDate: 2023-08-17 01:07:13 +0000
Commit:     Mike Gilbert <floppym@gentoo.org>
CommitDate: 2023-08-17 01:07:13 +0000

    sys-apps/systemd: backport tmpfiles/udev fix
    
    Closes: https://bugs.gentoo.org/911723
    Signed-off-by: Mike Gilbert <floppym@gentoo.org>

 .../systemd-254.1-tmpfiles-setup-dev-early.patch   | 252 +++++++++++++++++++++
 ...ystemd-254.1.ebuild => systemd-254.1-r1.ebuild} |   1 +
 2 files changed, 253 insertions(+)