Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp317114pxj; Thu, 20 May 2021 10:00:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLVfKlTCE5tKh3Iy5Px4EDiFASbVAvxEZIU+v4ZCEXMpnoTLQ+h4dR2mIpJd4WfVSTM/e0 X-Received: by 2002:a05:6638:14ce:: with SMTP id l14mr7049536jak.90.1621530012390; Thu, 20 May 2021 10:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621530012; cv=none; d=google.com; s=arc-20160816; b=nycbIl5ZzvB+ceIjQ1VBxbR1kMaXjRsyMgEswihpVAI6GCgArukjNX1y9mOez7Sz4x tRQ4BkRr6ZF0CPasX8p2Q/4kIxQsw1w/Ntsrl8wOzEt0vPwC0WvPrnQoFyXKoGBj/fmX GRmB0XgLuu29VwbRBddvmqbUzmNDUvkx5K+8Ukhapmu2Yjta6Ewezn5qnYJJZqUNaSg+ Id/Kbt3VsTlZo8MHDmJzpREjGTudauxkIwb7/EEyXn6oRD99RxqK1BooaC8yv5dAmLFd FRHGg8DcTHts527oPbzE4vFfbqQQWm6ePANZhowqJd/IufkpkEwK5wdJFUaVlLvkGWSU h2pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=93X3NLFN3++wZkAcGsyWHT4o9lw46qBODtjUe6ae1FM=; b=q2zyi3mJhWKD3hbuEP717Hl74uEPomfFMBt5tM3GSwPO5dW11ijI1ldOzS9Y0PtiKM 08rP7rjm+plnZ/KdxmtSS9tT1PeJ91A5oSrP8dP8SXBlO0/bMmRWDfA5PMmSY8nt7qma xEXyuFnxr+jutTKtyHIyTU7xvQyuHZK6FV4s9D7/H/zWjsOrsNLQUEqxW3kiAMTd/3m9 rj8NpbD2OEhEnIqJwEx87J5iupcUnCarSwVckksEGyNfUnQmUbkex8z0+x+fmLRyspZq B2Ma3j65I7BLugIAJRRXdF5wmIqenplwCm2jd9u10TJ060im0Xyxd3EfWOjDmY3nJkgk jlqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=atPnf5+W; 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 p9si2662382iov.92.2021.05.20.09.59.58; Thu, 20 May 2021 10:00:12 -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=atPnf5+W; 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 S235511AbhETKFK (ORCPT + 99 others); Thu, 20 May 2021 06:05:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:32852 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235106AbhETJ7Z (ORCPT ); Thu, 20 May 2021 05:59:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A7D9616E8; Thu, 20 May 2021 09:38:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503520; bh=XmTnRO0tUxq1mQAVmgbpfEFX1Y1/wMsQYo/kVpIRatg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=atPnf5+WAt0xeg7/pVjkMIxLxdL//QjII5jnX/65+HXwBzFy871lcjYepymrm521I GONdGQloKt5p7n30kEL8HitqxOmCxJ6SjmDHIjOb31VGf2woQqbnoqthsSUyi4NjSp jL7r9eL2hta9R6F+QWgEoV+K3YEAN5WB/Kp4b8rc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot , syzbot , Tetsuo Handa , Sasha Levin Subject: [PATCH 4.19 224/425] ttyprintk: Add TTY hangup callback. Date: Thu, 20 May 2021 11:19:53 +0200 Message-Id: <20210520092138.783405415@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tetsuo Handa [ Upstream commit c0070e1e60270f6a1e09442a9ab2335f3eaeaad2 ] 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") Link: https://lore.kernel.org/r/17e0652d-89b7-c8c0-fb53-e7566ac9add4@i-love.sakura.ne.jp Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/char/ttyprintk.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index 774748497ace..e56ac5adb5fc 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -159,12 +159,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 = { }; -- 2.30.2