All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: fwserial: Fix potential NULL pointer dereferences
@ 2021-05-21 11:43 Evgeny Novikov
  2021-05-21 11:52 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Evgeny Novikov @ 2021-05-21 11:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Evgeny Novikov, Johan Hovold, Nikolay Kyx, Dinghao Liu,
	Abheek Dhawan, Lee Gibson, linux-staging, linux-kernel,
	ldv-project

If fwtty_install() will be invoked with such tty->index that will be
not less than MAX_TOTAL_PORTS then fwtty_port_get() will return NULL and
fwtty_install() will either assign it to tty->driver_data or dereference
in fwtty_port_put() (if tty_standard_install() will fail). The similar
situation is with fwloop_install(). The patch fixes both cases.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
---
 drivers/staging/fwserial/fwserial.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 1ee6382cafc4..d0810896511e 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1069,6 +1069,9 @@ static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty)
 	struct fwtty_port *port = fwtty_port_get(tty->index);
 	int err;
 
+	if (!port)
+		return -ENODEV;
+
 	err = tty_standard_install(driver, tty);
 	if (!err)
 		tty->driver_data = port;
@@ -1082,6 +1085,9 @@ static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty)
 	struct fwtty_port *port = fwtty_port_get(table_idx(tty->index));
 	int err;
 
+	if (!port)
+		return -ENODEV;
+
 	err = tty_standard_install(driver, tty);
 	if (!err)
 		tty->driver_data = port;
-- 
2.26.2


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

* Re: [PATCH] staging: fwserial: Fix potential NULL pointer dereferences
  2021-05-21 11:43 [PATCH] staging: fwserial: Fix potential NULL pointer dereferences Evgeny Novikov
@ 2021-05-21 11:52 ` Greg Kroah-Hartman
       [not found]   ` <219911622016850@mail.yandex.ru>
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-05-21 11:52 UTC (permalink / raw)
  To: Evgeny Novikov
  Cc: Johan Hovold, Nikolay Kyx, Dinghao Liu, Abheek Dhawan,
	Lee Gibson, linux-staging, linux-kernel, ldv-project

On Fri, May 21, 2021 at 02:43:39PM +0300, Evgeny Novikov wrote:
> If fwtty_install() will be invoked with such tty->index that will be
> not less than MAX_TOTAL_PORTS then fwtty_port_get() will return NULL and
> fwtty_install() will either assign it to tty->driver_data or dereference
> in fwtty_port_put() (if tty_standard_install() will fail). The similar
> situation is with fwloop_install(). The patch fixes both cases.

But how can those cases ever happen?

> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
> ---
>  drivers/staging/fwserial/fwserial.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
> index 1ee6382cafc4..d0810896511e 100644
> --- a/drivers/staging/fwserial/fwserial.c
> +++ b/drivers/staging/fwserial/fwserial.c
> @@ -1069,6 +1069,9 @@ static int fwtty_install(struct tty_driver *driver, struct tty_struct *tty)
>  	struct fwtty_port *port = fwtty_port_get(tty->index);
>  	int err;
>  
> +	if (!port)
> +		return -ENODEV;

there's already a valid tty pointer here, so the index can not be "too
big".

> +
>  	err = tty_standard_install(driver, tty);
>  	if (!err)
>  		tty->driver_data = port;
> @@ -1082,6 +1085,9 @@ static int fwloop_install(struct tty_driver *driver, struct tty_struct *tty)
>  	struct fwtty_port *port = fwtty_port_get(table_idx(tty->index));
>  	int err;
>  
> +	if (!port)
> +		return -ENODEV;
> +

Same here, how can this ever happen?

thanks,

greg k-h

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

* Re: [PATCH] staging: fwserial: Fix potential NULL pointer dereferences
       [not found]   ` <219911622016850@mail.yandex.ru>
@ 2021-05-26  8:45     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2021-05-26  8:45 UTC (permalink / raw)
  To: Evgeny Novikov
  Cc: Johan Hovold, Nikolay Kyx, Dinghao Liu, Abheek Dhawan,
	Lee Gibson, linux-staging, linux-kernel, ldv-project

On Wed, May 26, 2021 at 11:21:36AM +0300, Evgeny Novikov wrote:
> Now I see that we need to restrict in specifications those values that
> can be passed to the install callback of tty_operations according to
> a first actual argument of tty_alloc_driver(). Thank you for pointing
> this out.

I do not understand what you mean here at all, sorry.

What "specifications"?

confused,

greg k-h

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

end of thread, other threads:[~2021-05-26  8:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-21 11:43 [PATCH] staging: fwserial: Fix potential NULL pointer dereferences Evgeny Novikov
2021-05-21 11:52 ` Greg Kroah-Hartman
     [not found]   ` <219911622016850@mail.yandex.ru>
2021-05-26  8:45     ` Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.