lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3a3db304-9725-6a90-65ac-dff09ef31aae@suse.cz>
Date:   Wed, 22 May 2019 10:15:56 +0200
From:   Jiri Slaby <jslaby@...e.cz>
To:     Gen Zhang <blackgod016574@...il.com>
Cc:     linux-kernel@...r.kernel.org
Subject: Re: [PATCH] tty_io: Fix a missing-check bug in drivers/tty/tty_io.c

On 22. 05. 19, 10:06, Gen Zhang wrote:
> On Wed, May 22, 2019 at 06:25:36AM +0200, Jiri Slaby wrote:
>> 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@...il.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.
> Thanks for your reply, Jiri!
> And what do you mean by an ldisc reference leak? I did't get the reason
> of introducing it.

Look at the top of alloc_tty_struct: there is tty_ldisc_init. If
tty_get_device fails here, you have to call tty_ldisc_deinit. Better,
you should add a failure-handling tail to this function and "goto" there.

>> And can this happen at all?
> I think tty_get_device() may happen to return NULL. Because it calls 
> class_find_device() and there's a chance class_find_device() returns
> NULL.

Sure, but can class_find_device return NULL in this tty case here?

thanks,
-- 
js
suse labs

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ