Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp62561pxj; Thu, 20 May 2021 04:37:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGiupcdH/Z/3YfcToI56Zuw/3FC1NfbO1sfZuNyqFjAhPd6YLZJ13r067IXxJGapXHWYvx X-Received: by 2002:a17:906:4789:: with SMTP id cw9mr4263926ejc.325.1621510677759; Thu, 20 May 2021 04:37:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621510677; cv=none; d=google.com; s=arc-20160816; b=qiDE2rU2UCnY9XnNAvvE5f5swktsMK6kCJUhED0+YctsA5lAadMGWRaSKvseUh0si4 r515ghKoonCRHVd/e0SkbItoj+Oa1QgT2j52jePCY1W+yGb2lnkQxC6NERcP+S91aJIE j7s6YZhYAsa1egQCMnRmfEkX9LBSfXoeb2wbKJ4RVIPBn/0QMBxAhksZPZw43ZC8F2Zj vaiAwWHX526zFhgoLUJGshcjoDYa7DYjf6vdQN6eIXKLIzyKE5WPvpFC+8SlHuHB/4PG JWcXaEf04+opnfRISpG4wy7Ici2zNyL4OrXZ3ETLnSWY5MmEPxlg+1fEiE908v2xI4c8 mymQ== 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=f/w79ExLWY9FsT+ZpgJYehEEtYe3rRpR+lwpcYZaEPI=; b=j843mdElXGCwowyj4hZgg2rg4IwTZqmFh6p+XA4JCH9L+mZnLQIMozpUttjzPFmk/A 8PODllfnTt90CbMd64Jw5skwJ7olInhPXp2SjPI3YCu/0wpW9m1q38qj66mvpnQLdGy1 /Fo5+fbRXDaWDJWmiEpNW2McC49j+ivkW44RVUGEZPd50sUxwriKVJm/QdhmDEsR1Jkv KCQcCf9aO1nEi8en/FW6LvwcysYaz5nOeg2FCGEOY9phnNAIjsuIsE1rg8pe4sHhe9DK MPzURFOVb2onLK+FhbQRNd8xPND8LO/iqoJGZ9/H0XiiePWTcsPqcEeJRBp85ijoxL9J 7MSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=LtJXJwnw; 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 r27si2489172ejc.437.2021.05.20.04.37.34; Thu, 20 May 2021 04:37:57 -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=LtJXJwnw; 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 S234477AbhETLgL (ORCPT + 99 others); Thu, 20 May 2021 07:36:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38992 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239672AbhETLQE (ORCPT ); Thu, 20 May 2021 07:16:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D414F61D62; Thu, 20 May 2021 10:09:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505353; bh=WtBkKHd+k+PkU0zsp/jSe/KDWIbE0F3MD8nIeaF0SwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LtJXJwnw6b4eH6/cKn/mNZMtIyUrP3R+cTpYb2/o7nI914hKrWK0BvXMAPyR0PgOV TvDjZ3oFHE9RZnLQk33YJxjy3lzQqA5NdQXIioxYWNww0l+SKpeDqUKa4ijokH22k4 7Yc8tmvyb1OdQXFvgCLFy4VruYCf5nyjSzkFjF+M= 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.4 096/190] ttyprintk: Add TTY hangup callback. Date: Thu, 20 May 2021 11:22:40 +0200 Message-Id: <20210520092105.374261561@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092102.149300807@linuxfoundation.org> References: <20210520092102.149300807@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 e265bace57d7..50031a215a66 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -166,12 +166,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 struct tty_port_operations null_ops = { }; -- 2.30.2