]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-uaccess: open device node with O_PATH
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Jul 2025 23:15:51 +0000 (08:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 3 Jul 2025 03:46:35 +0000 (12:46 +0900)
Some device node refuses to be opened with read-write mode.
Let's not open with O_RDWR, but open with O_PATH, and use
FORMAT_PROC_FD_PATH().

Follow-up for 1abb592f2f886913492e4967cc96816c167177a9.

Fixes #38033.

src/udev/udev-builtin-uaccess.c

index 9a9ba43b1c955bf38f3c1915a29973af75365482..bd2f77c69d67b317cabdccb79af70000ce87a893 100644 (file)
@@ -19,7 +19,7 @@ static int devnode_acl(int fd, uid_t uid) {
         assert(fd >= 0);
 
         _cleanup_(acl_freep) acl_t acl = NULL;
-        acl = acl_get_fd(fd);
+        acl = acl_get_file(FORMAT_PROC_FD_PATH(fd), ACL_TYPE_ACCESS);
         if (!acl)
                 return -errno;
 
@@ -99,7 +99,7 @@ static int devnode_acl(int fd, uid_t uid) {
         if (acl_calc_mask(&acl) < 0)
                 return -errno;
 
-        if (acl_set_fd(fd, acl) < 0)
+        if (acl_set_file(FORMAT_PROC_FD_PATH(fd), ACL_TYPE_ACCESS, acl) < 0)
                 return -errno;
 
         return 0;
@@ -120,7 +120,7 @@ static int builtin_uaccess(UdevEvent *event, int argc, char *argv[]) {
         if (!logind_running())
                 return 0;
 
-        _cleanup_close_ int fd = sd_device_open(dev, O_CLOEXEC|O_RDWR);
+        _cleanup_close_ int fd = sd_device_open(dev, O_CLOEXEC|O_PATH);
         if (fd < 0)
                 return log_device_error_errno(dev, fd, "Failed to open device node: %m");