Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4607575pxj; Wed, 12 May 2021 09:08:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynW46ojQJVy3MBTM012dNA7d2TpOixIRcPEgtLlbLtffSisSf9Qo+8xjziilqc0Zrsjxex X-Received: by 2002:a17:906:85da:: with SMTP id i26mr38924411ejy.287.1620835724069; Wed, 12 May 2021 09:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835724; cv=none; d=google.com; s=arc-20160816; b=b3dmJPfh0cr0V6aXTJ/vSP5z/P+OJ29hWcn7+F6mfZOhym8t9IedNwT73+mhGE+nyB WwbqtZjB49AMwf0/ror6JYZqTnTzonZDx55/JtjEE3Gvv9Kj4rj4Di898rbzgyrHZnf4 Y4lGrwIAc3VOKu7IhDZsBlN9GSZyJxpF7jdX+2nol6ekfgbvh/+sZw+kkVUP2M1pTQVa n8oRjwETS27Nx9+RQIcclsTO93zvxHrjA8qe7jH37SZbAEId9oa+d+xFnhU2lZ42Cz8K KrWSyb7Y/T0e8JI5z+yNkJcf7ZBw4vUMc2y/oFquQQ1G9D72YPu3cDD/6WfOFm2vTjNg 723g== 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=1hNFiGXiiEuTd2eMlt3Jm9ZI3B6/3xkZCsFAtTt9q+A=; b=TFsHxXeIOjMfZJsBsZ/8cT7qk1CAPB0p3SHl5YfuAbO7F8zbhKYbLmsi/4+46QEXdz U+krn5NU9o4FsvikXoSo9eLos+lLG5ggj0HDmNBiuKElWTNR+Mq87abuAWZdP7gCo+ec 6KyB/mYq/mZW1v+fnujE0vhYIYnr3bdbUFaiMz/MTrD9gc65ih9/08Ipm0ro0yEyl/Hn 9JqTLFmWurs3ofNwtVpuKbj87KXrq9+2El5HHpiz5LhNrmiEy7kwCykGiOHUuMXKonGA 58XbBKAIPdgY51NUvMIKUoRN8Kq8hOvzvh0tyBU2pDJx6bEC2CHUSByJ58Nq0416Youf qoeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zq31a5gf; 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 i26si97259edr.106.2021.05.12.09.08.20; Wed, 12 May 2021 09:08:44 -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=Zq31a5gf; 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 S236925AbhELQDA (ORCPT + 99 others); Wed, 12 May 2021 12:03:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235528AbhELP20 (ORCPT ); Wed, 12 May 2021 11:28:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6B9C461C22; Wed, 12 May 2021 15:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832417; bh=iWNDfoUDEKCdn6VdGg6dGYxQtn8n50whwoK3Cj+ioVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zq31a5gfz7ylWp49oJIPjBnKypPIpdsGgVzMV9v6yw4VGIIGXwPCMtyH8CVRJhwlE N6u3WLdxZvLvK3JVpKQbvXWX9SEXGC0UJHQWuKHDZGIEboUEHfeOIK6PPoAm9XVkD+ O/XFklKhKPZ9RW8picxsvDtddNaCREv6aC2cP1yc= 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 5.10 272/530] ttyprintk: Add TTY hangup callback. Date: Wed, 12 May 2021 16:46:22 +0200 Message-Id: <20210512144828.749215929@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@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 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 = { }; -- 2.30.2