From mboxrd@z Thu Jan 1 00:00:00 1970 From: John K Luebs Date: Tue, 08 Mar 2005 05:59:53 +0000 Subject: [PATCH] prevent unlinking moved symlinks Message-Id: <20050308055953.GA17994@luebsphoto.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org Here's a fairly obvious fix; so someone please check it carefully. This patch causes the remove handler to check that each symlink actually points to the correct devnode and skip it if it does not. The current policy for symlinks in devnode add handling is to "move" the link if it exists, so when an old devnode is being removed its stored symlink entries might be stale. Signed-off-by: John K. Luebs diff -pur udev-054/udev_remove.c udev-054-new/udev_remove.c --- udev-054/udev_remove.c 2005-02-25 22:18:21.000000000 -0500 +++ udev-054-new/udev_remove.c 2005-03-08 00:13:46.000000000 -0500 @@ -90,6 +90,31 @@ static int delete_node(struct udevice *u return -1; } + foreach_strpart(udev->symlink, " ", pos, len) { + char linkname[NAME_SIZE]; + char linkpath[NAME_SIZE]; + + strfieldcpymax(linkname, pos, len+1); + snprintf(linkpath, NAME_SIZE, "%s/%s", udev_root, linkname); + linkpath[NAME_SIZE-1] = '\0'; + + if ((stat(linkpath, &stats) != 0) || (stats.st_rdev != udev->devt)) + continue; + + dbg("unlinking symlink '%s'", linkpath); + retval = unlink(linkpath); + if (errno = ENOENT) + retval = 0; + if (retval) { + dbg("unlink(%s) failed with error '%s'", + linkpath, strerror(errno)); + return retval; + } + if (strchr(udev->symlink, '/')) { + delete_path(linkpath); + } + } + info("removing device node '%s'", filename); retval = unlink_secure(filename); if (retval) @@ -114,27 +139,6 @@ static int delete_node(struct udevice *u if (strchr(udev->name, '/')) delete_path(filename); - foreach_strpart(udev->symlink, " ", pos, len) { - char linkname[NAME_SIZE]; - - strfieldcpymax(linkname, pos, len+1); - snprintf(filename, NAME_SIZE, "%s/%s", udev_root, linkname); - filename[NAME_SIZE-1] = '\0'; - - dbg("unlinking symlink '%s'", filename); - retval = unlink(filename); - if (errno = ENOENT) - retval = 0; - if (retval) { - dbg("unlink(%s) failed with error '%s'", - filename, strerror(errno)); - return retval; - } - if (strchr(udev->symlink, '/')) { - delete_path(filename); - } - } - return retval; } ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel