Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp443204pxj; Thu, 20 May 2021 13:03:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhJJxCfBbodXAi1BdLpmmR8vR+7qQHqQVe4uahzLQBoUbxLJFIzG7/LPYKxM2V+QZNpsGY X-Received: by 2002:aa7:dd57:: with SMTP id o23mr6762808edw.98.1621541000908; Thu, 20 May 2021 13:03:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621541000; cv=none; d=google.com; s=arc-20160816; b=SSiNroPUNOg5PlkrSgBu3dg4sOlH/en5ikYe5TXSD6k+74utRFrqjHgTUOhEYcW3DB 9xTC/h6RGnF6A5gz5UuOPmKWuYkBiGh7m4C8JM+meOSyU99l4Rr+bINM/sa5B6zfv5ry aGjINat6N7Y1UfcoePflfdNPlTL0FqtLWM3R0gQn7EOgHtkcBTkLuJ+Kze67IxE9w+so yBdl9BIx8nFQgJ3alRy0TYjGdWZvB/8+P8KbI8ZQZ8zoGhRHPpePz/Oe8OKVABOsg3Aw AMDe3/NxSqQm15TbsfkbPh/ltVfLuZS7YKctzQo0uCeuh7HUv2YaxFlYXdx3lgWahaOp KQyg== 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=IuqGOPGhdkzk7xjp4BAc/xuDxomHcirTa90NhfKDoL1Y85Hrd40spZu0WwA40/iKAU Q8gblmfGLOKFLRVcVBMHNMMJxFUsafaDla/pXyyTzgAeRLcIdNWgW8USIzvup8bChodh CGhI6dXakWMZWgMVY1BYUgKKI1C1WR7JXm2Ou0KC09JE06zKdduJ1nfaJIP+HzdxalBh UKb9nRMB+YM3K+Fh6oL2dikpuRA2WpiV+/RcGygfx9Voe6/pzkY0BMrklAyIlEyIJ2El t+17K+nHnz7lHU8/xauFeRqAAVE3OPaPWyjaFkzB26/4m6XZjN+0yu3HyjwhQ3IaHPZ4 1JrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AFVGHhe0; 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 ay17si3847371ejb.736.2021.05.20.13.02.43; Thu, 20 May 2021 13:03:20 -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=AFVGHhe0; 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 S234089AbhETKpa (ORCPT + 99 others); Thu, 20 May 2021 06:45:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:60414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237068AbhETK3c (ORCPT ); Thu, 20 May 2021 06:29:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A6B7561261; Thu, 20 May 2021 09:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504288; bh=XmTnRO0tUxq1mQAVmgbpfEFX1Y1/wMsQYo/kVpIRatg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AFVGHhe0SvV/IR6IhLjrIOlO0mj9mrYT9PLnuHuJiaYGo9kBQAYcGKTJVyFHBFZy+ SbtfK995207g9YCmWCln/FrU+YYTHuuDJryI0mlOpvInwsGuXrUso62jz332SRjJW6 sToZ5bsg6pe774whG13PSp9HxsPe/u8B24DSNbxs= 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.14 178/323] ttyprintk: Add TTY hangup callback. Date: Thu, 20 May 2021 11:21:10 +0200 Message-Id: <20210520092126.213216729@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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