Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp324304pxy; Thu, 22 Apr 2021 03:04:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1eXZqmlWP3wWmqkaP4Jetxbh5nOHgFQ6h0EBgGZQ5osrU7IF2o9BEc9KI5E+TyeHut73j X-Received: by 2002:a05:6402:3591:: with SMTP id y17mr2784406edc.67.1619085867644; Thu, 22 Apr 2021 03:04:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619085867; cv=none; d=google.com; s=arc-20160816; b=YCQONTVfNil7eaSLkheweD0sDRG7Y6iJqnqMkFgNaWRek74cyyFlKbMikpQGDZW/TL LVurD2YplAusc51AYT73DquRlJSEg2nVZVMWzEmMawpsi0xWSK6lZmIRGGU956WTTXVz 0/GZMW8s/YsgxPudPwUW4EHUoqvxoZ5EvtHrCE30l5uy4d3NAae2CeUbk9puCjT0phg5 bRuZ3myQWWX7m9iE6vsrPOw7zUURbAwqipvjomz6fCaAaLkZqoLWsG5vzSdoC9ftuUn1 iknvqNpcSznCq50a5/MODwqqM2MuSzQxyeTOI7ILEhgAh1JqIxdkM0iClIK++ALvfEcJ cy7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=an+uw3gghxZzjPlzdgguHtKmy2SrB3/Qe5t+JQXx15w=; b=Ytqp2rQZIdJOfM+hLZ2jeTHtvSgmcKuw/EeSrJttXgLhZk1cy/3dWfnNJ3ZU9IyNOl Q5GLiBOmbmWA/7quxnIkhAFPNqIYK/h8Mt36JJQJldUd4gglCwKwSGfvJoUCy9I8G3pt m9GMmNI7kjTdQyHUZfvQIbR2R7Wh8DQHNUoz0ZEkG2VjBN+wpoQQ5kz0jm5TEx0HiEm3 2a2dRxZnCvsUbhj4Kk6IJmx8QLm8kv7+GPik1uhd1f8UuLmGYBgGlDIXBrlzXmIzxhni VsYYq+rGVlAgJBEFfpjuzf4pKcW/TF+NGhik7hMZBUiyJW/Ska1nuMqgVblOUs046rPq abRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=131JaMt1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id za11si1702874ejb.272.2021.04.22.03.04.03; Thu, 22 Apr 2021 03:04:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=131JaMt1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235798AbhDVKDf (ORCPT + 99 others); Thu, 22 Apr 2021 06:03:35 -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