"c77d17c0 [media] lirc: use-after free" introduces two problems: cdev_del() can be called with a NULL argument, and the kobject_put() path will cause a double free.
Showing the changes to drivers/media/rc/lirc_dev.c (1 of 1 file). Show all
Unified · Split
| @@ -157,13 +157,13 @@ static const struct file_operations lirc_dev_fops = { · 156 unmodified lines | ||
| 157 | 157 | |
| 158 | 158 | static int lirc_cdev_add(struct irctl *ir) |
| 159 | 159 | { |
| 160 | − int retval = -ENOMEM; | |
| 161 | 160 | struct lirc_driver *d = &ir->d; |
| 162 | 161 | struct cdev *cdev; |
| 162 | + int retval; | |
| 163 | 163 | |
| 164 | 164 | cdev = cdev_alloc(); |
| 165 | 165 | if (!cdev) |
| 166 | − goto err_out; | |
| 166 | + return -ENOMEM; | |
| 167 | 167 | |
| 168 | 168 | if (d->fops) { |
| 169 | 169 | cdev->ops = d->fops; |
| @@ -177,10 +177,8 @@ static int lirc_cdev_add(struct irctl *ir) · 7 unmodified lines | ||
| 177 | 177 | goto err_out; |
| 178 | 178 | |
| 179 | 179 | retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); |
| 180 | − if (retval) { | |
| 181 | − kobject_put(&cdev->kobj); | |
| 180 | + if (retval) | |
| 182 | 181 | goto err_out; |
| 183 | − } | |
| 184 | 182 | |
| 185 | 183 | ir->cdev = cdev; |
| 186 | 184 | |