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

From: Greg KH
Date: Mon Sep 19 2022 - 05:45:12 EST


On Mon, Sep 19, 2022 at 02:38:01AM -0700, Hyunwoo Kim wrote:
> A race condition may occur if the user physically removes the
> pcmcia device while calling open() for this char device node.
>
> This is a race condition between the scr24x_open() function and
> the scr24x_remove() function, which may eventually result in UAF.
>
> So, add a mutex to the scr24x_open() and scr24x_remove() functions
> to avoid race contidion of krefs.
>
> Signed-off-by: Hyunwoo Kim <imv4bel@xxxxxxxxx>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>

The robot did not report this original problem :(

> ---
> drivers/char/pcmcia/scr24x_cs.c | 73 +++++++++++++++++++++++----------
> 1 file changed, 52 insertions(+), 21 deletions(-)

You failed to put below the --- line what changed from previous versions
as the documentation asks for.

thanks,

greg k-h