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]
Date:   Wed, 25 Jul 2018 21:35:10 +0900
From:   Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>
To:     Greg KH <gregkh@...uxfoundation.org>
Cc:     jslaby@...e.com,
        syzbot <syzbot+3aa9784721dfb90e984d@...kaller.appspotmail.com>,
        linux-kernel@...r.kernel.org, syzkaller-bugs@...glegroups.com,
        Alexander Viro <viro@...iv.linux.org.uk>,
        linux-fsdevel <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH v2] n_tty: Protect tty->disc_data using refcount.

On 2018/07/25 17:06, Greg KH wrote:
> On Wed, Jul 25, 2018 at 12:22:16AM +0900, Tetsuo Handa wrote:
>> >From 118c64e86641a97d44dec39e313a95b12d9bc3b2 Mon Sep 17 00:00:00 2001
>> From: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
>> Date: Wed, 25 Jul 2018 00:15:18 +0900
>> Subject: [PATCH v2] n_tty: Protect tty->disc_data using refcount.
>>
>> syzbot is reporting NULL pointer dereference at n_tty_set_termios() [1].
>> This is because ioctl(TIOCVHANGUP) versus ioctl(TCSETS) can race.
>>
>> Since we don't want to introduce new locking dependency, this patch
>> converts "struct n_tty_data *ldata = tty->disc_data;" in individual
>> function into a function argument which follows "struct tty *", and
>> holds tty->disc_data at each "struct tty_ldisc_ops" hook using refcount
>> in order to ensure that memory which contains "struct n_tty_data" will
>> not be released while processing individual function.
>>
>> [1] https://syzkaller.appspot.com/bug?id=1e850009fca0b64ce49dc16499bda4f7de0ab1a5
>>
>> Signed-off-by: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
>> ---
>>  drivers/tty/n_tty.c | 511 ++++++++++++++++++++++++++++++++--------------------
>>  1 file changed, 314 insertions(+), 197 deletions(-)
> 
> What changed from v1?  I haven't had the chance to review your first
> patch, sorry, it's still in my queue.  I was hoping that someone else
> would help out with that as well :)
> 

Just added a check in case I overlooked a subtle race condition that
n_tty_close() is _somehow_ called twice.

  25,26c20,21
  <  1 file changed, 308 insertions(+), 195 deletions(-)
  >  1 file changed, 314 insertions(+), 197 deletions(-)
  872,873c867,869
  <       struct n_tty_data *ldata = tty->disc_data;
  > -     struct n_tty_data *ldata = tty->disc_data;
  > +     struct n_tty_data *ldata = xchg(&tty->disc_data, NULL);
  >
  878,879c874,880
  <       tty->disc_data = NULL;
  < +     put_n_tty(ldata);
  > -     tty->disc_data = NULL;
  > +     /*
  > +      * The xchg() above and this NULL test are rather paranoid checks.
  > +      * Caller should not allow calling close() twice.
  > +      */
  > +     if (ldata)
  > +             put_n_tty(ldata);
  1194c1195
  < +     if (!ldata) /* What value is most appropriate for this case? */
  > +     if (!ldata)

If n_tty_close() is _somehow_ called twice, v1 patch will trigger NULL
pointer dereference. If you are sure that n_tty_close() is never called
twice, you can ignore v2.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ