linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe
@ 2022-04-04 14:38 Miaoqian Lin
  2022-04-04 14:45 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2022-04-04 14:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Joel Stanley, Andrew Jeffery,
	Zev Weiss, Johan Hovold, Yang Guang, Miaoqian Lin, linux-serial,
	linux-arm-kernel, linux-aspeed, linux-kernel

platform_get_resource() may fail and return NULL, so we should
better check it's return value to avoid a NULL pointer dereference.

Fixes: 54da3e381c2b ("serial: 8250_aspeed_vuart: use UPF_IOREMAP to set up register mapping")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 drivers/tty/serial/8250/8250_aspeed_vuart.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
index 93fe10c680fb..9d2a7856784f 100644
--- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
+++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
@@ -429,6 +429,8 @@ static int aspeed_vuart_probe(struct platform_device *pdev)
 	timer_setup(&vuart->unthrottle_timer, aspeed_vuart_unthrottle_exp, 0);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res)
+		return -EINVAL;
 
 	memset(&port, 0, sizeof(port));
 	port.port.private_data = vuart;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe
  2022-04-04 14:38 [PATCH] serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe Miaoqian Lin
@ 2022-04-04 14:45 ` Greg Kroah-Hartman
  2022-04-04 15:25   ` Miaoqian Lin
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2022-04-04 14:45 UTC (permalink / raw)
  To: Miaoqian Lin
  Cc: Jiri Slaby, Joel Stanley, Andrew Jeffery, Zev Weiss,
	Johan Hovold, Yang Guang, linux-serial, linux-arm-kernel,
	linux-aspeed, linux-kernel

On Mon, Apr 04, 2022 at 02:38:40PM +0000, Miaoqian Lin wrote:
> platform_get_resource() may fail and return NULL, so we should
> better check it's return value to avoid a NULL pointer dereference.
> 
> Fixes: 54da3e381c2b ("serial: 8250_aspeed_vuart: use UPF_IOREMAP to set up register mapping")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> ---
>  drivers/tty/serial/8250/8250_aspeed_vuart.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> index 93fe10c680fb..9d2a7856784f 100644
> --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
> +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> @@ -429,6 +429,8 @@ static int aspeed_vuart_probe(struct platform_device *pdev)
>  	timer_setup(&vuart->unthrottle_timer, aspeed_vuart_unthrottle_exp, 0);
>  
>  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -EINVAL;

How did you test this change was correct?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe
  2022-04-04 14:45 ` Greg Kroah-Hartman
@ 2022-04-04 15:25   ` Miaoqian Lin
  0 siblings, 0 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-04-04 15:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Jiri Slaby, Joel Stanley, Andrew Jeffery, Zev Weiss,
	Johan Hovold, Yang Guang, linux-serial, linux-arm-kernel,
	linux-aspeed, linux-kernel

On Mon, Apr 04, 2022 at 04:45:50PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Apr 04, 2022 at 02:38:40PM +0000, Miaoqian Lin wrote:
> > platform_get_resource() may fail and return NULL, so we should
> > better check it's return value to avoid a NULL pointer dereference.
> > 
> > Fixes: 54da3e381c2b ("serial: 8250_aspeed_vuart: use UPF_IOREMAP to set up register mapping")
> > Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
> > ---
> >  drivers/tty/serial/8250/8250_aspeed_vuart.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> > index 93fe10c680fb..9d2a7856784f 100644
> > --- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
> > +++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
> > @@ -429,6 +429,8 @@ static int aspeed_vuart_probe(struct platform_device *pdev)
> >  	timer_setup(&vuart->unthrottle_timer, aspeed_vuart_unthrottle_exp, 0);
> >  
> >  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > +	if (!res)
> > +		return -EINVAL;
> 
> How did you test this change was correct?

Hi,

   I look into the implementation of platform_get_resource(),
and do cross-check the usages of it in the codebase, especially
the usages in other probe function. 
And I go through some simliar bugfix commits in the revision history——
add check for return value of platform_get_resource() in probe
functions,to learn the way to fix this kind of bugs. 
But sorry I don't have the corresponding device for running test.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-04 15:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-04 14:38 [PATCH] serial: 8250_aspeed_vuart: Fix potential NULL dereference in aspeed_vuart_probe Miaoqian Lin
2022-04-04 14:45 ` Greg Kroah-Hartman
2022-04-04 15:25   ` Miaoqian Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).