Skip to contentSkip to conversation

net/9p/usbg: require an exact match for device tags

PATCH In review Jackie Liu 2 participants 2 messages Jul 19 – Sep 13 9P file system

lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 net/9p/usbg: require an exact match for device tags

From: Jackie Liu <[email protected]>

p9_usbg_create() compares only strlen(devname) bytes while looking up the configfs instance named by the mount source. A source that is a prefix of an instance name therefore selects that instance. For example, source "foo" binds the "foobar" channel instead of failing with -ENOENT.

The configfs layer passes the instance name to usb9pfs_set_inst_tag(), and the transport already uses full string comparisons to keep these names unique. Use an exact match for mount lookup too.

Fixes a3be076dc174 ("net/9p/usbg: Add new usb gadget function transport")
---
 net/9p/trans_usbg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/9p/trans_usbg.c +1 -1
index 419cda13a7b5..884d6f4af50c 100644
@@ -391,7 +391,7 @@ static int p9_usbg_create(struct p9_client *client, struct fs_context *fc)
 	guard(mutex)(&usb9pfs_lock);
 
 	list_for_each_entry(dev, &usbg_instance_list, usb9pfs_instance) {
-		if (!strncmp(devname, dev->tag, strlen(devname))) {
+		if (!strcmp(devname, dev->tag)) {
 			if (!dev->inuse) {
 				dev->inuse = true;
 				found = 1;
Signature · 1 line
2.54.0
#1 lore raw

Jackie Liu wrote on Sun, Jul 19, 2026 at 12:03:46PM +0800:

Quoted 7 lines

From: Jackie Liu <[email protected]>

p9_usbg_create() compares only strlen(devname) bytes while looking up the configfs instance named by the mount source. A source that is a prefix of an instance name therefore selects that instance. For example, source "foo" binds the "foobar" channel instead of failing with -ENOENT.

Quoted 7 lines

The configfs layer passes the instance name to usb9pfs_set_inst_tag(), and the transport already uses full string comparisons to keep these names unique. Use an exact match for mount lookup too.

Fixes a3be076dc174 ("net/9p/usbg: Add new usb gadget function transport")

Thank you, there was another identical patch earlier that I hadn't picked up yet so I'm taking their patch instead, but I've added you as co-developed-by to the commit instead.

It should get in 7.4

https://lore.kernel.org/r/[email protected]
https://github.com/martinetd/linux/commit/9ee83ef8d24f11feb55fd0d222c0ec19f09dbd3f

Signature · 1 line
Dominique Martinet | Asmadeus