kern/161912: kernel sends incorrect notify to devctl about device changes

Yuriy Taraday yorik.sar at gmail.com
Sun Oct 23 00:40:06 UTC 2011


>Number:         161912
>Category:       kern
>Synopsis:       kernel sends incorrect notify to devctl about device changes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Oct 23 00:40:05 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Yuriy Taraday
>Release:        8.1-RELEASE-p2
>Organization:
>Environment:
FreeBSD greater 8.1-RELEASE-p2 FreeBSD 8.1-RELEASE-p2 #0: Sun Oct 23 04:13:10 MSD 2011     root at greater:/usr/obj/usr/src/sys/MYCONF  amd64

>Description:
When new device node is created or destroyed, kernel sends notify to devctl in this form:
  !system=DEVFS subsystem=CDEV type=DESTROY cdev=<DEVICE NAME>
where <DEVICE NAME> is being substituted with the name  of device.
If device name contains whitespaces, devd scraps out everything but the part before the first space in cdev parameter, so we can not correctly handle device name in devd.
>How-To-Repeat:
I found out the problem when I was looking into what happens in devd when I insert my USB flash drive. System eventually creates "msdosfs/ADATA UFD" device, but devd handles it as "msdosfs/ADATA" device.
>Fix:
See attached patch. It wraps <DEVICE NAME> in double quotes so that devd ignores spaces in it.

Patch attached with submission follows:

--- ./sys/kern/kern_conf.c.orig	2011-10-23 03:55:45.000000000 +0400
+++ ./sys/kern/kern_conf.c	2011-10-23 04:10:57.000000000 +0400
@@ -510,19 +510,21 @@
 static void
 notify(struct cdev *dev, const char *ev, int flags)
 {
-	static const char prefix[] = "cdev=";
+	static const char prefix[] = "cdev=\"";
 	char *data;
 	int namelen;
 
 	if (cold)
 		return;
 	namelen = strlen(dev->si_name);
-	data = malloc(namelen + sizeof(prefix), M_TEMP,
+	data = malloc(namelen + sizeof(prefix) + 1, M_TEMP,
 	     (flags & MAKEDEV_NOWAIT) ? M_NOWAIT : M_WAITOK);
 	if (data == NULL)
 		return;
 	memcpy(data, prefix, sizeof(prefix) - 1);
-	memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen + 1);
+	memcpy(data + sizeof(prefix) - 1, dev->si_name, namelen);
+	data[sizeof(prefix) + namelen - 1] = '"';
+	data[sizeof(prefix) + namelen] = '\0';
 	devctl_notify("DEVFS", "CDEV", ev, data);
 	free(data, M_TEMP);
 }


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list