2020-11-06 19:29:02

by Dan Carpenter

[permalink] [raw]
Subject: [PATCH] auxdisplay: fix use after free in lcd2s_i2c_remove()

The kfree() needs to be moved down a line to prevent a use after free.

Fixes: 8c9108d014c5 ("auxdisplay: add a driver for lcd2s character display")
Signed-off-by: Dan Carpenter <[email protected]>
---
drivers/auxdisplay/lcd2s.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
index cfa5f86deeef..3eb7f04db6cb 100644
--- a/drivers/auxdisplay/lcd2s.c
+++ b/drivers/auxdisplay/lcd2s.c
@@ -348,8 +348,8 @@ static int lcd2s_i2c_remove(struct i2c_client *i2c)
{
struct lcd2s_data *lcd2s = i2c_get_clientdata(i2c);

- kfree(lcd2s->charlcd);
charlcd_unregister(lcd2s->charlcd);
+ kfree(lcd2s->charlcd);
return 0;
}

--
2.28.0


2020-11-09 09:36:59

by Lars Poeschel

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: fix use after free in lcd2s_i2c_remove()

On Fri, Nov 06, 2020 at 10:24:15PM +0300, Dan Carpenter wrote:
> The kfree() needs to be moved down a line to prevent a use after free.
>
> Fixes: 8c9108d014c5 ("auxdisplay: add a driver for lcd2s character display")
> Signed-off-by: Dan Carpenter <[email protected]>
> ---
> drivers/auxdisplay/lcd2s.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/auxdisplay/lcd2s.c b/drivers/auxdisplay/lcd2s.c
> index cfa5f86deeef..3eb7f04db6cb 100644
> --- a/drivers/auxdisplay/lcd2s.c
> +++ b/drivers/auxdisplay/lcd2s.c
> @@ -348,8 +348,8 @@ static int lcd2s_i2c_remove(struct i2c_client *i2c)
> {
> struct lcd2s_data *lcd2s = i2c_get_clientdata(i2c);
>
> - kfree(lcd2s->charlcd);
> charlcd_unregister(lcd2s->charlcd);
> + kfree(lcd2s->charlcd);
> return 0;
> }

Reviewed-by: Lars P?schel <[email protected]>

Thanks,
Lars

2020-11-09 09:48:57

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH] auxdisplay: fix use after free in lcd2s_i2c_remove()

On Fri, Nov 6, 2020 at 8:26 PM Dan Carpenter <[email protected]> wrote:
>
> The kfree() needs to be moved down a line to prevent a use after free.

Thanks Dan for catching this one up while in -next. I'll pick it up.

Cheers,
Miguel