Re: [PATCH] char: pcmcia: scr24x_cs: Fix use-after-free in scr24x_fops

From: Arnd Bergmann
Date: Fri Sep 16 2022 - 03:00:31 EST


On Fri, Sep 16, 2022, at 7:00 AM, Hyunwoo Kim wrote:
> @@ -298,9 +300,10 @@ static void scr24x_remove(struct pcmcia_device *link)
> cdev_del(&dev->c_dev);
> clear_bit(dev->devno, scr24x_minors);
> dev->dev = NULL;
> - mutex_unlock(&dev->lock);
>
> kref_put(&dev->refcnt, scr24x_delete);
> +
> + mutex_unlock(&dev->lock);
> }

This appears to introduce a new use-after-free, when the kref_put()
frees the 'dev' structure and you unlock the mutex in that structure
afterwards.

Arnd