lkml.org 
[lkml]   [2019]   [May]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] tty_io: Fix a missing-check bug in drivers/tty/tty_io.c
From
Date
On 22. 05. 19, 3:40, Gen Zhang wrote:
> In alloc_tty_struct(), tty->dev is assigned by tty_get_device(). And it
> calls class_find_device(). And class_find_device() may return NULL.
> And tty->dev is dereferenced in the following codes. When
> tty_get_device() returns NULL, dereferencing this tty->dev null pointer
> may cause the kernel go wrong. Thus we should check tty->dev.
> Further, if tty_get_device() returns NULL, we should free tty and
> return NULL.
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
>
> ---
> diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
> index 033ac7e..1444b59 100644
> --- a/drivers/tty/tty_io.c
> +++ b/drivers/tty/tty_io.c
> @@ -3008,6 +3008,10 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
> tty->index = idx;
> tty_line_name(driver, idx, tty->name);
> tty->dev = tty_get_device(tty);
> + if (!tty->dev) {
> + kfree(tty);
> + return NULL;
> + }

This is incorrect, you introduced an ldisc reference leak.

And can this happen at all?

thanks,
--
js
suse labs

\
 
 \ /
  Last update: 2019-05-22 06:26    [W:0.076 / U:0.644 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site