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, 30 Jan 2019 09:29:29 +0000
From:   "Li,Rongqing" <lirongqing@...du.com>
To:     "Kohli, Gaurav" <gkohli@...eaurora.org>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        "jslaby@...e.com" <jslaby@...e.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
CC:     Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        "linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>
Subject: 答复: [PATCH][v4] tty: fix race between flush_to_ldisc and tty_open



> -----邮件原件-----
> 发件人: Kohli, Gaurav [mailto:gkohli@...eaurora.org]
> 发送时间: 2019年1月18日 20:51
> 收件人: Li,Rongqing <lirongqing@...du.com>; gregkh@...uxfoundation.org;
> jslaby@...e.com; linux-kernel@...r.kernel.org
> 主题: Re: [PATCH][v4] tty: fix race between flush_to_ldisc and tty_open
> 
> 
> 
> On 1/18/2019 2:57 PM, Li RongQing wrote:
> > There still is a race window after the commit b027e2298bd588
> > ("tty: fix data race between tty_init_dev and flush of buf"), and we
> > encountered this crash issue if receive_buf call comes before tty
> > initialization completes in n_tty_open and
> > tty->driver_data may be NULL.
> >
> > CPU0                                    CPU1
> > ----                                    ----
> >                                   n_tty_open
> >                                     tty_init_dev
> >                                       tty_ldisc_unlock
> >                                         schedule flush_to_ldisc
> >   receive_buf
> >    tty_port_default_receive_buf
> >     tty_ldisc_receive_buf
> >      n_tty_receive_buf_common
> >        __receive_buf
> >         uart_flush_chars
> >          uart_start
> >          /*tty->driver_data is NULL*/
> >                                     tty->ops->open
> >                                     /*init tty->driver_data*/
> >
> > it can be fixed by extending ldisc semaphore lock in tty_init_dev to
> > driver_data initialized completely after tty->ops->open(), but this
> > will lead to put lock on one function and unlock in some other
> > function, and hard to maintain, so fix this race only by checking
> > tty->driver_data when receiving, and return if tty->driver_data
> > is NULL
> >
> > Signed-off-by: Wang Li <wangli39@...du.com>
> > Signed-off-by: Zhang Yu <zhangyu31@...du.com>
> > Signed-off-by: Li RongQing <lirongqing@...du.com>
> > ---
> > V4: add version information
> > V3: not used ldisc semaphore lock, only checking tty->driver_data with
> > NULL
> > V2: fix building error by EXPORT_SYMBOL tty_ldisc_unlock
> > V1: extend ldisc lock to protect that tty->driver_data is inited
> >
> > drivers/tty/tty_port.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c index
> > 044c3cbdcfa4..86d0bec38322 100644
> > --- a/drivers/tty/tty_port.c
> > +++ b/drivers/tty/tty_port.c
> > @@ -31,6 +31,9 @@ static int tty_port_default_receive_buf(struct tty_port
> *port,
> >   	if (!tty)
> >   		return 0;
> >
> > +	if (!tty->driver_data)
> > +		return 0;
> > +
> >   	disc = tty_ldisc_ref(tty);
> >   	if (!disc)
> >   		return 0;
> >
> Acked-by: Gaurav Kohli <gkohli@...eaurora.org>
> 
> It looks good to me w.r.t previous approach, but Let's Maintainer decide once.
> 

Thanks for your review, this one is simple and safe, it is used as live-patch online

-RongQing


> Regards
> Gaurav
> --
> Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
> is a member of the Code Aurora Forum, a Linux Foundation Collaborative
> Project.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ