Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4556113pxj; Wed, 12 May 2021 08:08:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFuiUeLF787uwI5f/CDaWBivYiQuFSClDeh3+Auz+QTH+ziG4KJ97+LkKD6FAxQ/YIsNA6 X-Received: by 2002:a05:6808:13d5:: with SMTP id d21mr11008944oiw.31.1620832083569; Wed, 12 May 2021 08:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620832083; cv=none; d=google.com; s=arc-20160816; b=iu+MG1ftxDAcf1tVB12h3ELV5ktGzFJjPxpQs2CKuuEw6pDPsyE189rDB5y+XDRHEo +kr1c7v9hktpgLpXigB9nrpPXiv/p+YxWrH0w3O1nbOEimHdDkCNyKNpvxpdR8dBgf1b 8G/e0TSVMnnM9QMjcu3aOims63yMTFW9DUCKLhPDt3ke/5tl446oMaXHlX0VuEXeJct4 FQzz9JhovUPigUDqSu4eaChkSw+eiuoO2pyXk8mWN4nF9V6rElIqqQLsgV9xExVTtVK3 l3Rf6c690lZIyl6RIEtUVPAbOLteg9o+hQgj0Q2xw2IJKZfbS9zrkki12ygiDx+3JP+z um4w== 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=EYLkPSUos1T4jQct4UBtfZLziv2Xv0LPGy9o91oDwQs=; b=fOYvgp2zah00u5MK7xlxnu1omH8n3sWmDDEVqII1zn/04es2vscWi4rv2Vo0cOTNzB 7eWE9+DVhiqcrvGiBfamGuH9ADpDIhwuvwxiLr2fe48wMp6exMixEl3UMXNE4xc1RqQa tJ7qBPkY1tS5ZdOfuhdZtGPPX0jnWUGBcUowSanb+ciaQh7BKUXoR+HzYz591EpR2T0p wdWW6qJBtNgGQ0y5J5PcDmD4DJooZB1l7PmXOMOF3INHxq09Ta8d1wrpk1KXadNYkJCC 5BWtOsXJ1un6ULEwCzyr7oWgZhfK5zMW3B8A34yV8kMzAfINZKgtJokR6mgW56j1K4zc sEdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fDG+RAp+; 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 j18si114398otr.271.2021.05.12.08.07.48; Wed, 12 May 2021 08:08:03 -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=fDG+RAp+; 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 S232890AbhELPGl (ORCPT + 99 others); Wed, 12 May 2021 11:06:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:59200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232305AbhELPC1 (ORCPT ); Wed, 12 May 2021 11:02:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 601E761606; Wed, 12 May 2021 14:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620831482; bh=Sl9J4FmfshQnMQ+ttl0PmjLR+IgCq1VozA8vqwdlxBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fDG+RAp+sGess7Yhx6mZApnTcfJL6qQM5am4vnjuVsMu/+XmdyDCKgpF+47c534ly UxsBaI9/jIP0XaRGGDLSUDAkN/PsRNRQj4HY7ChzuIQ2i2mWYaz+wt39sViyhBB+Ed a7bxEBMMY59V02qjzdsPnQncpsLlEz/AxDVMtsOU= 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.4 137/244] ttyprintk: Add TTY hangup callback. Date: Wed, 12 May 2021 16:48:28 +0200 Message-Id: <20210512144747.396185804@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144743.039977287@linuxfoundation.org> References: <20210512144743.039977287@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 56db949a7b70..e6258b4485dc 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