Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] cdev: cdev_put oops

While fixing an oops in the st driver in a dirty release path, I
encountered an oops in cdev_put for cdevs allocated using cdev_alloc. If
cdev_del is called when the cdev kobject still has an open user, when the
last cdev_put is called, the cdev_put will call kobject_put, which will end
up ultimately releasing the cdev in cdev_dynamic_release. Patch fixes the
oops by preventing cdev_put from accessing freed memory.

Signed-off-by: Brian King <brking@us.ibm.com>
Cc: <viro@parcelfarce.linux.theplanet.co.uk>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Brian King and committed by
Linus Torvalds
7da6844c 50a52234

+2 -1
+2 -1
fs/char_dev.c
··· 277 277 void cdev_put(struct cdev *p) 278 278 { 279 279 if (p) { 280 + struct module *owner = p->owner; 280 281 kobject_put(&p->kobj); 281 - module_put(p->owner); 282 + module_put(owner); 282 283 } 283 284 } 284 285