"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 | static int lirc_cdev_add(struct irctl *ir) | 158 | static int lirc_cdev_add(struct irctl *ir) |
| 159 | { | 159 | { |
| 160 | int retval = -ENOMEM; | ||
| 161 | struct lirc_driver *d = &ir->d; | 160 | struct lirc_driver *d = &ir->d; |
| 162 | struct cdev *cdev; | 161 | struct cdev *cdev; |
| 162 | int retval; | ||
| 163 | 163 | ||
| 164 | cdev = cdev_alloc(); | 164 | cdev = cdev_alloc(); |
| 165 | if (!cdev) | 165 | if (!cdev) |
| 166 | goto err_out; | 166 | return -ENOMEM; |
| 167 | 167 | ||
| 168 | if (d->fops) { | 168 | if (d->fops) { |
| 169 | cdev->ops = d->fops; | 169 | cdev->ops = d->fops; |
| @@ -177,10 +177,8 @@ static int lirc_cdev_add(struct irctl *ir) · 7 unmodified lines | |||
| 177 | goto err_out; | 177 | goto err_out; |
| 178 | 178 | ||
| 179 | retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); | 179 | retval = cdev_add(cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); |
| 180 | if (retval) { | 180 | if (retval) |
| 181 | kobject_put(&cdev->kobj); | ||
| 182 | goto err_out; | 181 | goto err_out; |
| 183 | } | ||
| 184 | 182 | ||
| 185 | ir->cdev = cdev; | 183 | ir->cdev = cdev; |
| 186 | 184 | ||