From 69928b4f152d3a282a7103720ae89cdb2517ef77 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 14 Sep 2022 06:07:09 +0900 Subject: [PATCH] udev-node: do not create symlink to a non-existing device node 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index 7a98b02176f..f3da48862bc 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -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;