]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-node: do not create symlink to a non-existing device node 24691/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 13 Sep 2022 21:07:09 +0000 (06:07 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 16 Sep 2022 14:08:07 +0000 (23:08 +0900)
Previously, the stack directory contains empty regular files named with
device ID, and we create sd_device object from the device name.
Hence, we implicitly checked the existence of the device node.

However, now the files in the stack directory are symlink, and we
retrieve the path to the device node and its priority from the symlink.
Hence, the existence of the device node is not checked.
Let's check if the device node is still exist.

src/udev/udev-node.c

index 7a98b02176f0dae69fa1f76b30e511532b12bf49..f3da48862bc1ecab6d61fd51851df0b40b159ab7 100644 (file)
@@ -146,6 +146,13 @@ static int stack_directory_read_one(int dirfd, const char *id, bool is_symlink,
 
                 *colon = '\0';
 
+                /* Of course, this check is racy, but it is not necessary to be perfect. Even if the device
+                 * node will be removed after this check, we will receive 'remove' uevent, and the invalid
+                 * symlink will be removed during processing the event. The check is just for shortening the
+                 * timespan that the symlink points to a non-existing device node. */
+                if (access(colon + 1, F_OK) < 0)
+                        return -errno;
+
                 r = safe_atoi(buf, &tmp_prio);
                 if (r < 0)
                         return r;