From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E45D3C433ED for ; Thu, 22 Apr 2021 10:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF2EA61426 for ; Thu, 22 Apr 2021 10:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbhDVKDg (ORCPT ); Thu, 22 Apr 2021 06:03:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:37742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235755AbhDVKD3 (ORCPT ); Thu, 22 Apr 2021 06:03:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 02D2161131; Thu, 22 Apr 2021 10:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1619085754; bh=HkPE5rnmVLS4AHdydPD62qofAjx8DHdPJ968fhV+dxI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=131JaMt1q/KG3BQZw49Ze+akwz3yKn4UWo9wEiavnX7LVkZKxz1TNGfj9EfVAKjkv fSSA4/TEgVeCjGmmcPaIZIo0T6RCdR5QUHBjyLcEqrl66GB3BLtbezhz3G57EIITN1 VmmjnvzskU9KPZ0LQAqRPrwDujTSjAno9FyB2Z68= Date: Thu, 22 Apr 2021 12:02:31 +0200 From: Greg Kroah-Hartman To: Samo =?utf-8?B?UG9nYcSNbmlr?= Cc: Tetsuo Handa , Jiri Slaby , Petr Mladek , Sergey Senozhatsky , Steven Rostedt , John Ogness , linux-kernel@vger.kernel.org, syzkaller-bugs Subject: Re: [PATCH] ttyprintk: Add TTY hangup callback. Message-ID: References: <051b550c-1cdd-6503-d2b7-0877bf0578fc@i-love.sakura.ne.jp> <32e75be6-6e9f-b33f-d585-13db220519da@i-love.sakura.ne.jp> <095d5393-b212-c4d8-5d6d-666bd505cc3d@i-love.sakura.ne.jp> <31a4dec3d36ed131402244693cae180816ebd4d7.camel@t-2.net> <17e0652d-89b7-c8c0-fb53-e7566ac9add4@i-love.sakura.ne.jp> <8043d41d48a0f4f13bd891b4c3e9ad28c76b430e.camel@t-2.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8043d41d48a0f4f13bd891b4c3e9ad28c76b430e.camel@t-2.net> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 18, 2021 at 01:16:05PM +0200, Samo Pogačnik wrote: > Dne 15.04.2021 (čet) ob 09:22 +0900 je Tetsuo Handa napisal(a): > > syzbot is reporting hung task due to flood of > > > > tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__, > > port->count); > > > > message [1], for ioctl(TIOCVHANGUP) prevents tty_port_close() from > > decrementing port->count due to tty_hung_up_p() == true. > > > > ---------- > > #include > > #include > > #include > > #include > > #include > > > > int main(int argc, char *argv[]) > > { > > int i; > > int fd[10]; > > > > for (i = 0; i < 10; i++) > > fd[i] = open("/dev/ttyprintk", O_WRONLY); > > ioctl(fd[0], TIOCVHANGUP); > > for (i = 0; i < 10; i++) > > close(fd[i]); > > close(open("/dev/ttyprintk", O_WRONLY)); > > return 0; > > } > > ---------- > > > > When TTY hangup happens, port->count needs to be reset via > > "struct tty_operations"->hangup callback. > > > > [1] > > https://syzkaller.appspot.com/bug?id=39ea6caa479af471183997376dc7e90bc7d64a6a > > > > Reported-by: syzbot > > Reported-by: syzbot > > Tested-by: syzbot > > Signed-off-by: Tetsuo Handa > > Fixes: 24b4b67d17c308aa ("add ttyprintk driver") > > --- > > drivers/char/ttyprintk.c | 11 +++++++++++ > > 1 file changed, 11 insertions(+) > > > > diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c > > index 6a0059e508e3..93f5d11c830b 100644 > > --- a/drivers/char/ttyprintk.c > > +++ b/drivers/char/ttyprintk.c > > @@ -158,12 +158,23 @@ static int tpk_ioctl(struct tty_struct *tty, > > return 0; > > } > > > > +/* > > + * TTY operations hangup function. > > + */ > > +static void tpk_hangup(struct tty_struct *tty) > > +{ > > + struct ttyprintk_port *tpkp = tty->driver_data; > > + > > + tty_port_hangup(&tpkp->port); > > +} > > + > > static const struct tty_operations ttyprintk_ops = { > > .open = tpk_open, > > .close = tpk_close, > > .write = tpk_write, > > .write_room = tpk_write_room, > > .ioctl = tpk_ioctl, > > + .hangup = tpk_hangup, > > }; > > > > static const struct tty_port_operations null_ops = { }; > > Using the supplied test code, i've tested the patch on my desktop running the > 5.4 kernel. After applying the patch, the kernel warnings like "ttyprintk: > tty_port_close_start: tty->count = 1 port count = 11" do not appear any more, > when the test code is run. > I think the patch is ok. Thanks for the review, I'll go queue this up. greg k-h