Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp315691imm; Wed, 29 Aug 2018 22:43:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdanSdhFnaRLvkHWUSxDgZX8lSpOgfCjQFgPMh+XPmz2JtqH4iJLENleV6zEegDcP8sgneZu X-Received: by 2002:a62:2744:: with SMTP id n65-v6mr9048387pfn.125.1535607786854; Wed, 29 Aug 2018 22:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535607786; cv=none; d=google.com; s=arc-20160816; b=wmRqRcEGJCzBAaOyyZjG5JW+5bwHeuVEhsf4a5Bg2OChdRebHdSxq0UAY69EcJVnbc K1eJvOBUMHRoO/tvikuAhJIRQkcwey+nbuRRxRtdjhbXBdhHjlZApIO6S8cphS1D4tHh 0c2yhxTs+MaeMsjAWHB+UUdrRR8OID2Q6GPH/BLL9Qxw9ZX2fTaZliWMWsKOHX2ELEUI 9/a9iSFUbCbq70D6Q64W+853Zk4MkWf5xQYUg8S4hZsCFp6f4ExrbvTReeHIHvK5ZC2s Wb1o0yPxdpETt2jZrFAK0q46iK41XuJlfZQpW0z1sIUbpZHnsbkucRi3WJpbiyYTIn22 aXrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=gVnCH4s+YKteS15mbWhDu/8mPyvJBOx83NbUS/QjkrI=; b=HebeohtCdFeJeZvhJYLVDV76s64U9TEl8D66wlo80pXRqNec6vSBxWVoD9uNX5zK7d PY/1i8lCTx7CSkMeohTFlB/xJ2eYhKlM1FQfPa6ge2X+4eZZVUWhLZ3x1G2o9GFIRwZd A6cnoZg5RivpiccSxcD28Zg2e4RDlrmgosfSZ5dlZHPFBbV45Tka8VfJMwcbT7Wzu7gq A+T1G/DMj792VMeCO1gWSyDxPF3bM4eixx+L6tuvimQAzRa+/l7+rwnWn7/OVZqEKOQl WcjKotW+OQInKNEPx9oxn8Gbo8pEKkTGsfyAyKK6G1Z+l5zgW87zM3bTckFgvTTZgTHp d+gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d24-v6si5966285pgb.226.2018.08.29.22.42.38; Wed, 29 Aug 2018 22:43:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727248AbeH3JlM (ORCPT + 99 others); Thu, 30 Aug 2018 05:41:12 -0400 Received: from gate.crashing.org ([63.228.1.57]:58898 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbeH3JlM (ORCPT ); Thu, 30 Aug 2018 05:41:12 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id w7U5GtDj013461; Thu, 30 Aug 2018 00:16:56 -0500 Message-ID: Subject: Re: [PATCH 2/4] tty: Hold tty_ldisc_lock() during tty_reopen() From: Benjamin Herrenschmidt To: Sergey Senozhatsky , Dmitry Safonov Cc: linux-kernel@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>, Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , Pasi =?ISO-8859-1?Q?K=E4rkk=E4inen?= , Peter Hurley , Tan Xiaojun , Greg Kroah-Hartman , Jiri Slaby , stable@vger.kernel.org Date: Thu, 30 Aug 2018 15:16:55 +1000 In-Reply-To: <20180829043430.GB13049@jagdpanzerIV> References: <20180829022353.23568-1-dima@arista.com> <20180829022353.23568-3-dima@arista.com> <20180829043430.GB13049@jagdpanzerIV> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-1.fc28) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2018-08-29 at 13:34 +0900, Sergey Senozhatsky wrote: > Hi, > > Cc-ing Benjamin on this. > > On (08/29/18 03:23), Dmitry Safonov wrote: > > BUG: unable to handle kernel paging request at 0000000000002260 > > IP: [..] n_tty_receive_buf_common+0x5f/0x86d > > Workqueue: events_unbound flush_to_ldisc > > Call Trace: > > [..] n_tty_receive_buf2 > > [..] tty_ldisc_receive_buf > > [..] flush_to_ldisc > > [..] process_one_work > > [..] worker_thread > > [..] kthread > > [..] ret_from_fork > > Seems that you are not the first one to hit this NULL deref. > > > I think, tty_ldisc_reinit() should be called with ldisc_sem hold for > > writing, which will protect any reader against line discipline changes. > > Per https://lore.kernel.org/patchwork/patch/777220/ > > : Note that we noticed one path that called reinit without the ldisc lock > : held for writing, we added that, but it didn't fix the problem. > > And I guess that Ben meant the same reinit path which you patched: This is too old for me to remember buit yes, there definitely was a bug there... > > @@ -1267,15 +1267,20 @@ static int tty_reopen(struct tty_struct *tty) > > if (test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) > > return -EBUSY; > > > > - tty->count++; > > + retval = tty_ldisc_lock(tty, 5 * HZ); > > + if (retval) > > + return retval; > > > > + tty->count++; > > if (tty->ldisc) > > - return 0; > > + goto out_unlock; > > > > retval = tty_ldisc_reinit(tty, tty->termios.c_line); > > if (retval) > > tty->count--; > > > > +out_unlock: > > + tty_ldisc_unlock(tty); > > return retval; > > } > > -ss