Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2333618ybz; Thu, 23 Apr 2020 16:12:49 -0700 (PDT) X-Google-Smtp-Source: APiQypIZuEK/EVvGC2R3QBdcoL8Asb9p6OLMU12tm15Od4wa5iGyDf/MucX8vAv5pma9JmmcqQh1 X-Received: by 2002:a17:906:2458:: with SMTP id a24mr4619450ejb.239.1587683569130; Thu, 23 Apr 2020 16:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587683569; cv=none; d=google.com; s=arc-20160816; b=VrN/gkxGa7QSxxofRsy3KxABTJlopOXh6Tj/N2SukObSXB4mpBKZClsPVRCtuRoekg Ve2/gRPbLhLwCrDeeVE5EzZR3lGEey3UO5yCNGlWmd+Bwh24qJX/alSwzjxVm2Lq5FbO 3xKiITgy3jSme8xAs1ZMODHZLonejCZ89sgUK1WuMRLx0LmhcHfLgw6p+cVUrjb7Dmq9 bWssG7dft5k9a3QPn5ASHmgu3YKegyU18TP6p5+3VTP6h4dYXNZXaYVrVuVAV7wQTsSZ ZsPKdB6jPBQG6GqJyxhnVgPZvo2O3nOgVrFWCmFR0g1dCQ6pFf1hip5ibNO8OufqWxT1 ZGwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Q/GJs8UmFzTmqq9aG7xi3TXOJ0Rv8aMcsPgRyb9HtgA=; b=kgQGUUTOY0S4tecu9nvjjRvHXuNT+IATZin/Qmq58xUsF1aMpyMieczKHPy3KC8gr9 gCb+qwMRmxGONupnhjNIAowrWdQ7+siT6+IRqv4Zz6WHFqoMnjFy83G64FoE/++f6hZN p9TMXc1FqSrRf4dAu+ra8FwZLANwd1eI+Xtnrscb3OPeBXY73atpPKvb83YVYxHIxlft fbOqSbOVifEDPI5E2bEVDR1pTwpRmTGB2GmAFgu8DCAoRT0w++uhFqJJtopoXW/A7gDZ +q8dc4FkoL/cN1AtDmp1Jb344bo394MWQVvULFQdDKzJ5JzTYovdD3cLWm37R0r/mltV DJOg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si2082183ejb.97.2020.04.23.16.12.25; Thu, 23 Apr 2020 16:12:49 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729104AbgDWXJ6 (ORCPT + 99 others); Thu, 23 Apr 2020 19:09:58 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50686 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728153AbgDWXGz (ORCPT ); Thu, 23 Apr 2020 19:06:55 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvi-0004w7-Sl; Fri, 24 Apr 2020 00:06:51 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkve-00E726-9V; Fri, 24 Apr 2020 00:06:46 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "Jiri Slaby" Date: Fri, 24 Apr 2020 00:07:29 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 222/245] vt: selection, push console lock down In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Slaby commit 4b70dd57a15d2f4685ac6e38056bad93e81e982f upstream. We need to nest the console lock in sel_lock, so we have to push it down a bit. Fortunately, the callers of set_selection_* just lock the console lock around the function call. So moving it down is easy. In the next patch, we switch the order. Signed-off-by: Jiri Slaby Fixes: 07e6124a1a46 ("vt: selection, close sel_buffer race") Link: https://lore.kernel.org/r/20200228115406.5735-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/tty/vt/selection.c | 13 ++++++++++++- drivers/tty/vt/vt.c | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -158,7 +158,7 @@ static int store_utf8(u16 c, char *p) * The entire selection process is managed under the console_lock. It's * a lot under the lock but its hardly a performance path */ -int set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) +static int __set_selection(const struct tiocl_selection __user *sel, struct tty_struct *tty) { struct vc_data *vc = vc_cons[fg_console].d; int sel_mode, new_sel_start, new_sel_end, spc; @@ -334,6 +334,17 @@ unlock: return ret; } +int set_selection(const struct tiocl_selection __user *v, struct tty_struct *tty) +{ + int ret; + + console_lock(); + ret = __set_selection(v, tty); + console_unlock(); + + return ret; +} + /* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl(). --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -2670,9 +2670,7 @@ int tioclinux(struct tty_struct *tty, un switch (type) { case TIOCL_SETSEL: - console_lock(); ret = set_selection((struct tiocl_selection __user *)(p+1), tty); - console_unlock(); break; case TIOCL_PASTESEL: ret = paste_selection(tty);