Skip to contentSkip to conversation

avoid Oops in net/core/dev.c

TRIVIAL Dan Aloni 2 participants 3 messages Jun 28, 2003 Networking

lore
Share & tools
lore

Dan Aloni

author
#0 lore raw

Linus, please apply.
Patrick, please read on.

This fixes the kernel crash in the case when we do an SIOCSIFNAME ioctl on /proc/net/dev to rename a network interface, and we supply a string such as "foo%sbar".

BTW, I've seen more places of this phenomenon, but they are not with strings that come right from userspace like this one.

BTW2, the attempt to rename the device here doesn't affect sysfs. Patrick, we need a class_device_* interface that does this.

net/core/dev.c +1 -1
@@ -2346,7 +2346,7 @@
 				return -EEXIST;
 			memcpy(dev->name, ifr->ifr_newname, IFNAMSIZ);
 			dev->name[IFNAMSIZ - 1] = 0;
-			snprintf(dev->class_dev.class_id, BUS_ID_SIZE, dev->name);
+			strlcpy(dev->class_dev.class_id, dev->name, BUS_ID_SIZE);
 			notifier_call_chain(&netdev_chain,
 					    NETDEV_CHANGENAME, dev);
 			return 0;
Signature · 2 lines
Dan Aloni
[email protected]
#1 lore raw
Quoted 4 lines · Dan Aloni

BTW2, the attempt to rename the device here doesn't affect sysfs. Patrick, we need a class_device_* interface that does this.

That's a good idea (I'm the person to blame for the class_device code, not Pat.) Care to send a patch?

thanks,

greg k-h

author
#2 lore raw
Quoted 8 lines · Greg KH
Quoted 4 lines · Dan Aloni

BTW2, the attempt to rename the device here doesn't affect sysfs. Patrick, we need a class_device_* interface that does this.

That's a good idea (I'm the person to blame for the class_device code, not Pat.) Care to send a patch?

I have no patch, but I thought of either using lookup_one_len() and then d_move() to create a new dentry or to rip out some code out of vfs_rename_dir(). Anyway, I'm no VFS expert, so no patch any time soon.

Signature · 2 lines
Dan Aloni
[email protected]