mdev accidently erases previously created nodes while trying to rename nodes

Denys Vlasenko vda.linux at googlemail.com
Wed Jun 17 20:02:36 UTC 2009


On Wed, Jun 17, 2009 at 3:52 PM, Jean Wolter<jw5 at os.inf.tu-dresden.de> wrote:
> while using mdev to create device nodes for the capi subsystem mdev
> accidently deletes a previously created node. Assume the following
> lines in mdev.conf:
>
> capi            0:0 0660 =capi20
> capi([0-9])     0:0 0660 =capi20.0%1
> capi([0-9]*)    0:0 0660 =capi20.%1
>
> After loading the capi module the kernel generate a number of hotplug
> events, starting with capi, followed by capi0-capi32. mdev creates
> /dev/capi, and renames it to /dev/capi20.

This seems to be ok.

> When the event  "add tty /class/tty/capi0" comes in, mdev executes
>
>    unlink /dev/capi20
>    mknod /dev/capi20
>    rename(/dev/capi20,/dev/capi20.20)
>
> and erases the original /dev/capi20 device while doing this.

This is the corresponding code:

                /* "Execute" the line we found */
                if (!delete && major >= 0) {
                        if (ENABLE_FEATURE_MDEV_RENAME)
                                unlink(device_name);
                        if (mknod(device_name, mode | type,
makedev(major, minor)) && errno != EEXIST)
                                bb_perror_msg_and_die("mknod %s", device_name);
                        if (major == root_major && minor == root_minor)
                                symlink(device_name, "root");
                        if (ENABLE_FEATURE_MDEV_CONF) {
                                chmod(device_name, mode);
                                chown(device_name, ugid.uid, ugid.gid);
                        }
                        if (ENABLE_FEATURE_MDEV_RENAME && alias) {
                                alias = build_alias(alias, device_name);
                                /* move the device, and optionally
                                 * make a symlink to moved device node */
                                if (rename(device_name, alias) == 0 &&
aliaslink == '>')
                                        symlink(alias, device_name);
                                free(alias);
                        }

You say that /dev/capi20 is unlinked. Why? In event
"add tty /class/tty/capi0" device_name == "capi0",
thus unlink(device_name) won't delete "capi20". I'm confused.

> So to me it looks like mdev should try to do the renaming before
> actually creating the device node (or deleting it for a remove hotplug
> event). The attached patch against git (head?) tries to fix this. It
> is adapted from a patch against 1.14.1 and did not get much testing so
> far.

Please describe how failure happens on the code level.

--
vda


More information about the busybox mailing list