* [PATCH] protect against buggy drivers @ 2004-10-08 16:53 Stephen Hemminger 2004-10-08 16:21 ` Alan Cox 2004-10-08 17:14 ` Greg KH 0 siblings, 2 replies; 11+ messages in thread From: Stephen Hemminger @ 2004-10-08 16:53 UTC (permalink / raw) To: linus, akpm; +Cc: linux-kernel # This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/10/08 09:52:03-07:00 shemminger@zqx3.pdx.osdl.net # Protect against bad driver writers who pass invalid names when # setting up character devices. # # fs/char_dev.c # 2004/10/08 09:51:52-07:00 shemminger@zqx3.pdx.osdl.net +5 -0 # Protect against bad driver writers who pass invalid names when # setting up character devices. # diff -Nru a/fs/char_dev.c b/fs/char_dev.c --- a/fs/char_dev.c 2004-10-08 09:52:15 -07:00 +++ b/fs/char_dev.c 2004-10-08 09:52:15 -07:00 @@ -196,6 +196,11 @@ char *s; int err = -ENOMEM; + if (name == NULL || *name == '\0' || + strlen(name) >= KOBJ_NAME_LEN || + !strcmp(name, ".") || !strcmp(name, "..")) + return -EINVAL; + cd = __register_chrdev_region(major, 0, 256, name); if (IS_ERR(cd)) return PTR_ERR(cd); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 16:53 [PATCH] protect against buggy drivers Stephen Hemminger @ 2004-10-08 16:21 ` Alan Cox 2004-10-08 17:14 ` Greg KH 1 sibling, 0 replies; 11+ messages in thread From: Alan Cox @ 2004-10-08 16:21 UTC (permalink / raw) To: Stephen Hemminger; +Cc: linus, akpm, Linux Kernel Mailing List On Gwe, 2004-10-08 at 17:53, Stephen Hemminger wrote: > # fs/char_dev.c > # 2004/10/08 09:51:52-07:00 shemminger@zqx3.pdx.osdl.net +5 -0 > # Protect against bad driver writers who pass invalid names when > # setting up character devices. > # And how many badly mannered people check the return on this ? Shouldn't it just BUG() ? ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 16:53 [PATCH] protect against buggy drivers Stephen Hemminger 2004-10-08 16:21 ` Alan Cox @ 2004-10-08 17:14 ` Greg KH 2004-10-08 17:29 ` Richard B. Johnson 2004-10-08 18:27 ` Stephen Hemminger 1 sibling, 2 replies; 11+ messages in thread From: Greg KH @ 2004-10-08 17:14 UTC (permalink / raw) To: Stephen Hemminger; +Cc: linus, akpm, linux-kernel On Fri, Oct 08, 2004 at 09:53:41AM -0700, Stephen Hemminger wrote: > + strlen(name) >= KOBJ_NAME_LEN || There's no need for this check, if we fix the other usage of cdev->kobj.name in this file to use the proper kobject_name() and kobject_set_name() functions. thanks, greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 17:14 ` Greg KH @ 2004-10-08 17:29 ` Richard B. Johnson 2004-10-08 17:50 ` Greg KH 2004-10-08 18:27 ` Stephen Hemminger 1 sibling, 1 reply; 11+ messages in thread From: Richard B. Johnson @ 2004-10-08 17:29 UTC (permalink / raw) To: Greg KH; +Cc: Stephen Hemminger, linus, akpm, linux-kernel On Fri, 8 Oct 2004, Greg KH wrote: > On Fri, Oct 08, 2004 at 09:53:41AM -0700, Stephen Hemminger wrote: >> + strlen(name) >= KOBJ_NAME_LEN || > > There's no need for this check, if we fix the other usage of > cdev->kobj.name in this file to use the proper kobject_name() and > kobject_set_name() functions. > > thanks, > > greg k-h Well the module name is passed in register/unregister_chrdev(). It was not documented as the allowed length of the name so it was possible to install a device and then only "partially" uninstall the device so a subsequent open of the device-file would crash the kernel. A device name of : "Octrangle Contrabulator" 23 characters ... in a test program was sufficiently-long to kill the kernel. I recommend truncating any name to an acceptable length. This would show up in /proc/iomem, etc., prompting the developer to shorten the name. Also, the new length of 20 characters is probably too short. There was no such limitation on 2.4.x, where many modules are being ported from. Cheers, Dick Johnson Penguin : Linux version 2.6.8 on an i686 machine (5537.79 BogoMips). Note 96.31% of all statistics are fiction. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 17:29 ` Richard B. Johnson @ 2004-10-08 17:50 ` Greg KH 2004-10-08 18:31 ` Richard B. Johnson 2004-10-08 19:32 ` Richard B. Johnson 0 siblings, 2 replies; 11+ messages in thread From: Greg KH @ 2004-10-08 17:50 UTC (permalink / raw) To: Richard B. Johnson; +Cc: Stephen Hemminger, linus, akpm, linux-kernel On Fri, Oct 08, 2004 at 01:29:40PM -0400, Richard B. Johnson wrote: > On Fri, 8 Oct 2004, Greg KH wrote: > > >On Fri, Oct 08, 2004 at 09:53:41AM -0700, Stephen Hemminger wrote: > >>+ strlen(name) >= KOBJ_NAME_LEN || > > > >There's no need for this check, if we fix the other usage of > >cdev->kobj.name in this file to use the proper kobject_name() and > >kobject_set_name() functions. > > Well the module name is passed in register/unregister_chrdev(). It > was not documented as the allowed length of the name so it was > possible to install a device and then only "partially" uninstall > the device so a subsequent open of the device-file would crash > the kernel. A device name of : > > "Octrangle Contrabulator" 23 characters > > ... in a test program was sufficiently-long to kill the kernel. > I recommend truncating any name to an acceptable length. This > would show up in /proc/iomem, etc., prompting the developer > to shorten the name. > > Also, the new length of 20 characters is probably too short. > There was no such limitation on 2.4.x, where many modules > are being ported from. That's why I said this check should not go in, and the cdev code fixed to use the proper functions. That would enable you to have as long as a name as you wanted to. thanks, greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 17:50 ` Greg KH @ 2004-10-08 18:31 ` Richard B. Johnson 2004-10-08 18:35 ` Greg KH 2004-10-08 19:32 ` Richard B. Johnson 1 sibling, 1 reply; 11+ messages in thread From: Richard B. Johnson @ 2004-10-08 18:31 UTC (permalink / raw) To: Greg KH; +Cc: Stephen Hemminger, linus, akpm, linux-kernel On Fri, 8 Oct 2004, Greg KH wrote: > On Fri, Oct 08, 2004 at 01:29:40PM -0400, Richard B. Johnson wrote: >> On Fri, 8 Oct 2004, Greg KH wrote: >> >>> On Fri, Oct 08, 2004 at 09:53:41AM -0700, Stephen Hemminger wrote: >>>> + strlen(name) >= KOBJ_NAME_LEN || >>> >>> There's no need for this check, if we fix the other usage of >>> cdev->kobj.name in this file to use the proper kobject_name() and >>> kobject_set_name() functions. >> >> Well the module name is passed in register/unregister_chrdev(). It >> was not documented as the allowed length of the name so it was >> possible to install a device and then only "partially" uninstall >> the device so a subsequent open of the device-file would crash >> the kernel. A device name of : >> >> "Octrangle Contrabulator" 23 characters >> >> ... in a test program was sufficiently-long to kill the kernel. >> I recommend truncating any name to an acceptable length. This >> would show up in /proc/iomem, etc., prompting the developer >> to shorten the name. >> >> Also, the new length of 20 characters is probably too short. >> There was no such limitation on 2.4.x, where many modules >> are being ported from. > > That's why I said this check should not go in, and the cdev code fixed > to use the proper functions. That would enable you to have as long as a > name as you wanted to. > > thanks, > > greg k-h > In the meantime, can we do something like: --- linux-2.6.8/fs/char_dev.c.orig 2004-10-08 14:24:03.838389344 -0400 +++ linux-2.6.8/fs/char_dev.c 2004-10-08 14:26:51.059967800 -0400 @@ -206,7 +206,7 @@ cdev->owner = fops->owner; cdev->ops = fops; - strcpy(cdev->kobj.name, name); + strncpy(cdev->kobj.name, name, KOBJ_NAME_LEN-1); for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/')) *s = '!'; Cheers, Dick Johnson Penguin : Linux version 2.6.8 on an i686 machine (5537.79 BogoMips). Note 96.31% of all statistics are fiction. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 18:31 ` Richard B. Johnson @ 2004-10-08 18:35 ` Greg KH 0 siblings, 0 replies; 11+ messages in thread From: Greg KH @ 2004-10-08 18:35 UTC (permalink / raw) To: Richard B. Johnson; +Cc: Stephen Hemminger, linus, akpm, linux-kernel On Fri, Oct 08, 2004 at 02:31:27PM -0400, Richard B. Johnson wrote: > > In the meantime, can we do something like: > > --- linux-2.6.8/fs/char_dev.c.orig 2004-10-08 14:24:03.838389344 -0400 > +++ linux-2.6.8/fs/char_dev.c 2004-10-08 14:26:51.059967800 -0400 > @@ -206,7 +206,7 @@ > > cdev->owner = fops->owner; > cdev->ops = fops; > - strcpy(cdev->kobj.name, name); > + strncpy(cdev->kobj.name, name, KOBJ_NAME_LEN-1); > for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/')) > *s = '!'; No, that's still wrong. Use Stephen's other patch instead. thanks, greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 17:50 ` Greg KH 2004-10-08 18:31 ` Richard B. Johnson @ 2004-10-08 19:32 ` Richard B. Johnson 1 sibling, 0 replies; 11+ messages in thread From: Richard B. Johnson @ 2004-10-08 19:32 UTC (permalink / raw) To: Greg KH; +Cc: Stephen Hemminger, linus, akpm, Linux kernel On Fri, 8 Oct 2004, Greg KH wrote: > On Fri, Oct 08, 2004 at 01:29:40PM -0400, Richard B. Johnson wrote: >> On Fri, 8 Oct 2004, Greg KH wrote: >> >>> On Fri, Oct 08, 2004 at 09:53:41AM -0700, Stephen Hemminger wrote: >>>> + strlen(name) >= KOBJ_NAME_LEN || >>> >>> There's no need for this check, if we fix the other usage of >>> cdev->kobj.name in this file to use the proper kobject_name() and >>> kobject_set_name() functions. >> >> Well the module name is passed in register/unregister_chrdev(). It >> was not documented as the allowed length of the name so it was >> possible to install a device and then only "partially" uninstall >> the device so a subsequent open of the device-file would crash >> the kernel. A device name of : >> >> "Octrangle Contrabulator" 23 characters >> >> ... in a test program was sufficiently-long to kill the kernel. >> I recommend truncating any name to an acceptable length. This >> would show up in /proc/iomem, etc., prompting the developer >> to shorten the name. >> >> Also, the new length of 20 characters is probably too short. >> There was no such limitation on 2.4.x, where many modules >> are being ported from. > > That's why I said this check should not go in, and the cdev code fixed > to use the proper functions. That would enable you to have as long as a > name as you wanted to. > > thanks, > > greg k-h Okay. Thanks. Updating sources now. Cheers, Dick Johnson Penguin : Linux version 2.6.8 on an i686 machine (5537.79 BogoMips). Note 96.31% of all statistics are fiction. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 17:14 ` Greg KH 2004-10-08 17:29 ` Richard B. Johnson @ 2004-10-08 18:27 ` Stephen Hemminger 2004-10-08 18:36 ` Greg KH 2004-10-22 20:58 ` Greg KH 1 sibling, 2 replies; 11+ messages in thread From: Stephen Hemminger @ 2004-10-08 18:27 UTC (permalink / raw) To: Greg KH; +Cc: linus, akpm, linux-kernel Here is a better fix (thanks Greg) that allows long names for character device objects. Signed-off-by: Stephen Hemminger <shemminger@osdl.org> diff -Nru a/fs/char_dev.c b/fs/char_dev.c --- a/fs/char_dev.c 2004-10-08 11:14:29 -07:00 +++ b/fs/char_dev.c 2004-10-08 11:14:29 -07:00 @@ -207,8 +207,8 @@ cdev->owner = fops->owner; cdev->ops = fops; - strcpy(cdev->kobj.name, name); - for (s = strchr(cdev->kobj.name, '/'); s; s = strchr(s, '/')) + kobject_set_name(&cdev->kobj, "%s", name); + for (s = strchr(kobject_name(&cdev->kobj),'/'); s; s = strchr(s, '/')) *s = '!'; err = cdev_add(cdev, MKDEV(cd->major, 0), 256); ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 18:27 ` Stephen Hemminger @ 2004-10-08 18:36 ` Greg KH 2004-10-22 20:58 ` Greg KH 1 sibling, 0 replies; 11+ messages in thread From: Greg KH @ 2004-10-08 18:36 UTC (permalink / raw) To: Stephen Hemminger; +Cc: linus, akpm, linux-kernel On Fri, Oct 08, 2004 at 11:27:25AM -0700, Stephen Hemminger wrote: > Here is a better fix (thanks Greg) that allows long names for character > device objects. > > Signed-off-by: Stephen Hemminger <shemminger@osdl.org> Thanks, I'll add this to my trees, and send it to Linus after 2.6.9 is out (no in-kernel modules need this, so it isn't a real rush.) thanks again, greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] protect against buggy drivers 2004-10-08 18:27 ` Stephen Hemminger 2004-10-08 18:36 ` Greg KH @ 2004-10-22 20:58 ` Greg KH 1 sibling, 0 replies; 11+ messages in thread From: Greg KH @ 2004-10-22 20:58 UTC (permalink / raw) To: Stephen Hemminger; +Cc: linus, akpm, linux-kernel On Fri, Oct 08, 2004 at 11:27:25AM -0700, Stephen Hemminger wrote: > Here is a better fix (thanks Greg) that allows long names for character > device objects. > > Signed-off-by: Stephen Hemminger <shemminger@osdl.org> Applied, thanks. greg k-h ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2004-10-22 21:08 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-10-08 16:53 [PATCH] protect against buggy drivers Stephen Hemminger 2004-10-08 16:21 ` Alan Cox 2004-10-08 17:14 ` Greg KH 2004-10-08 17:29 ` Richard B. Johnson 2004-10-08 17:50 ` Greg KH 2004-10-08 18:31 ` Richard B. Johnson 2004-10-08 18:35 ` Greg KH 2004-10-08 19:32 ` Richard B. Johnson 2004-10-08 18:27 ` Stephen Hemminger 2004-10-08 18:36 ` Greg KH 2004-10-22 20:58 ` Greg KH
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox