[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240623172101.5874-E-hca@linux.ibm.com>
Date: Sun, 23 Jun 2024 19:21:01 +0200
From: Heiko Carstens <hca@...ux.ibm.com>
To: yskelg@...il.com
Cc: Harald Freudenberger <freude@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>, shjy180909@...il.com,
linux-s390@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] s390/raw3270: handle memory allocation failure in
'raw3270_setup_console()'
On Sun, Jun 23, 2024 at 09:24:49PM +0900, yskelg@...il.com wrote:
> From: Yunseong Kim <yskelg@...il.com>
>
> This patch handle potential null pointer dereference in
> 'raw3270_setup_device()', When 'raw3270_setup_console()' fails to
> allocate memory for 'rp' or 'ascebc'.
>
> Signed-off-by: Yunseong Kim <yskelg@...il.com>
> ---
> drivers/s390/char/raw3270.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
> index c57694be9bd3..4e81040eea81 100644
> --- a/drivers/s390/char/raw3270.c
> +++ b/drivers/s390/char/raw3270.c
> @@ -812,7 +812,13 @@ struct raw3270 __init *raw3270_setup_console(void)
> return ERR_CAST(cdev);
>
> rp = kzalloc(sizeof(*rp), GFP_KERNEL | GFP_DMA);
> + if (!rp)
> + return ERR_PTR(-ENOMEM);
> ascebc = kzalloc(256, GFP_KERNEL);
> + if (!ascebc) {
> + kfree(rp);
> + return ERR_PTR(-ENOMEM);
> + }
> rc = raw3270_setup_device(cdev, rp, ascebc);
> if (rc)
> return ERR_PTR(rc);
This is kind of pointless since such allocations won't fail.. but
anyway: please make allocation and error handling like it is already
done in raw3270_create_device(); this will also prevent a memory leak
of rp and ascebc in case raw3270_setup_device() fails.
Powered by blists - more mailing lists