udev: apply access mode/ownership to device nodes with O_PATH
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Sep 2020 19:58:40 +0000 (21:58 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 28 Sep 2020 16:45:54 +0000 (18:45 +0200)
commita7fdc6cbd399acdb1a975a7f72b9be4504a38c7c
tree496863f76868074f79a1445108fd1b4fd5ed66b4
parentf25bff5eaf6881717e873f27c26f2e8264517c16
udev: apply access mode/ownership to device nodes with O_PATH

Let's open the device node to modify with O_PATH, and then adjust it
only after verifying everything is in order. This fixes a race where the
a device appears, disappears and quickly reappers, while we are still
running the rules for the first appearance: when going by path we'd
possibly adjust half of the old and half of the new node. By O_PATH we
can pin the node while we operate on it, thus removing the race.

Previously, we'd do a superficial racey check if the device node changed
undearneath us, and would propagate EEXIST in that case, failing the
rule set. With this change we'll instead gracefully handle this, exactly
like in the pre-existing case when the device node disappeared in the
meantime.
src/udev/udev-node.c