Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp169862imm; Tue, 28 Aug 2018 19:25:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYnaEXkz45W5tFvcpKXdURTmrNZ4lx/gIIiJqI10Bl+ts5ZCevN7SB7y905A5Y3T5ebidfY X-Received: by 2002:a17:902:ab93:: with SMTP id f19-v6mr3903084plr.252.1535509549327; Tue, 28 Aug 2018 19:25:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535509549; cv=none; d=google.com; s=arc-20160816; b=YweTNpe7wR1/0Q1Bbg/2R80dhC88YuWImZQYhT37HCyiDnoZIGOSjPlDXVHgv7qGSs 2maaskDZQ0yS0PxRoUtPsoo8euGC9wXoEkV5QydGgH02LEkUeJ7uKEbqqnFluJzGjX7G Hj8mb32XscfFTd70aAl27aKqENseW7rw7l0b2khY8vR0Di9gKTv4DU/CzS0EMmPby1Tn pF5Na9k49tsqGzp1bKJIcs8UsgjmjX2dwPztEThFF0poRhdQYjRAUgmfO6EcZQSKM7cS c3QdsEAUFShwE45Hwx7X9KN50MEXtcDsD6tu/uiWjlSWZfAjHvtHJEumom992Mqisq1i FU2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=h2rsiF9P7p4ynflggwgQAjCIBGcKV6Izc/9GngY6csc=; b=kQTtXiZYxR/yyGFXCSJUoSiqAhwlbxhJFp6ffRDOEQDVDsG1zc5Vhkcn5KDxXUk3MP X95EdkwXKh52fTyQExhAMG6VHTmJQzkeR/7T9S4yEVwJw1hB0j6pKi1qboy1xchh0Tch yQ3WCtIVjcFxWAKQiZwwQYZpjAtmfo13zVavi9HUMlb3sE7rEShMn+/APhRDaOsmvw9b +N5x8HYuCvWk4nSLWl8dyGgkH41i/WD70BIoXMIDVoUVJ5YjvV18C7TWjyxcP9LEFEvX dP1YqsHRPERKSZPi1CZ75th2sH3rahUAF9fQ61HgnGTe4xd8vPB/x8NnkIL98zEFMb0X 5PHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=isqoiePY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7-v6si2436304pgc.233.2018.08.28.19.25.34; Tue, 28 Aug 2018 19:25:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=googlenew header.b=isqoiePY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbeH2GS3 (ORCPT + 99 others); Wed, 29 Aug 2018 02:18:29 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40557 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725199AbeH2GS2 (ORCPT ); Wed, 29 Aug 2018 02:18:28 -0400 Received: by mail-ed1-f68.google.com with SMTP id e19-v6so2774748edq.7 for ; Tue, 28 Aug 2018 19:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h2rsiF9P7p4ynflggwgQAjCIBGcKV6Izc/9GngY6csc=; b=isqoiePYDPMoVP/o8d00tZRP2sQ/VhKkInY30WDLQEPiDInVt1wvjSXMc0MJrWuo52 4U6PFk+AJzsfyJo4sj0rwZ6NHITnJDl4aukOdDCl/Ge52V7NsE1pXIqLTuD/MCcuTSlH 4lo04m9LeQYTm6NBIMDgtrejHvezq77Ycq5mraSpljPR2iVVinH+s+DnMxtx1QDWVkgm AlePicT4FBJK27EZlxIl/roh0EuS9oJ8D86tXq2WsAOpX/j8jznwKmt0C3Al6UFv9W1z AOK+BHWS53Q8gGOI6CGA52IMfLTlfqlmdGRl9wDXNP/slbtRDxT2XpMf5LjzmNNFIzeN 9nPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h2rsiF9P7p4ynflggwgQAjCIBGcKV6Izc/9GngY6csc=; b=VN6OF56tICt5K8YKCE6gEX8odoJhBCruUDBLxtX5fH6IjRklyrkU8l/BKo+/9leWER oPkcI80FFrruwfVrzGo0ZevTsFGSb7dqCt4ZNkVzZBQ2xoLKABYYlF/DChvlULdjLPBk n9qVYaCpGt3oh5Bd/XvZhe1C9pmIi/bD0ooBr2p/qAbNfw9L5ot0r6uN9rlLVgWwyd9Z imKJIPKvEOj8KS5WKsVb0PoKm2RrB5xSNDZpDIncBsUl93+E4iMHrFKEW3tYKz+BkQYO k5+TSmJTo1ecJU4VJsAHbNkIFj70j7w5uWaOjd29kZrITSBIDiVp6LK1yES99pgvh4bQ VJyw== X-Gm-Message-State: APzg51B9Arxc8QfIPfBrGQdIai+fCc7lCR4Kg35o+43qAXOoFTHVzyTc Li9fcy5Mr7mE0OzRC9rlMvDjM5T9TWE= X-Received: by 2002:a50:aa3b:: with SMTP id o56-v6mr5199849edc.23.1535509436176; Tue, 28 Aug 2018 19:23:56 -0700 (PDT) Received: from dhcp.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id f26-v6sm1236367edb.28.2018.08.28.19.23.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Aug 2018 19:23:55 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: Dmitry Safonov <0x7f454c46@gmail.com>, Dmitry Safonov , Daniel Axtens , Dmitry Vyukov , Michael Neuling , Mikulas Patocka , =?UTF-8?q?Pasi=20K=C3=A4rkk=C3=A4inen?= , Peter Hurley , Sergey Senozhatsky , Tan Xiaojun , Greg Kroah-Hartman , Jiri Slaby , stable@vger.kernel.org Subject: [PATCH 1/4] tty: Drop tty->count on tty_reopen() failure Date: Wed, 29 Aug 2018 03:23:50 +0100 Message-Id: <20180829022353.23568-2-dima@arista.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180829022353.23568-1-dima@arista.com> References: <20180829022353.23568-1-dima@arista.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of tty_ldisc_reinit() failure, tty->count should be decremented back, otherwise we will never release_tty(). Never seen it in the real life, but it seems not really hard to hit. Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: stable@vger.kernel.org Signed-off-by: Dmitry Safonov --- drivers/tty/tty_io.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c index 32bc3e3fe4d3..5e5da9acaf0a 100644 --- a/drivers/tty/tty_io.c +++ b/drivers/tty/tty_io.c @@ -1255,6 +1255,7 @@ static void tty_driver_remove_tty(struct tty_driver *driver, struct tty_struct * static int tty_reopen(struct tty_struct *tty) { struct tty_driver *driver = tty->driver; + int retval; if (driver->type == TTY_DRIVER_TYPE_PTY && driver->subtype == PTY_TYPE_MASTER) @@ -1268,10 +1269,14 @@ static int tty_reopen(struct tty_struct *tty) tty->count++; - if (!tty->ldisc) - return tty_ldisc_reinit(tty, tty->termios.c_line); + if (tty->ldisc) + return 0; - return 0; + retval = tty_ldisc_reinit(tty, tty->termios.c_line); + if (retval) + tty->count--; + + return retval; } /** -- 2.13.6