Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp647054ybh; Tue, 10 Mar 2020 05:48:53 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvgGTEkf0oPck8dLbfKIUuQp3Z9Rj9rPv3+eisPELvEveOWgXBYv/KMtulaay9m1DpYyJVG X-Received: by 2002:a9d:178:: with SMTP id 111mr17482888otu.238.1583844533025; Tue, 10 Mar 2020 05:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583844533; cv=none; d=google.com; s=arc-20160816; b=TJH9cYFnGsk6cyVirsSvsIEady4051X/oBJ8jWLlzeqUf9jdTymp6sJEY6tjCb4SVy y2t0ClCT9RO+1aj7yNY1MolN16Sz//Yqwy8va8u3sGbYIerdorgbbEq3pDo7fFxZhYjM tCYG8PGxDJ31IEChk050poDX+Gn7y0r/1h5dh2iB1YGn5sKdprN9zB85jfzRsZAJVpa6 Le+5uI0oNTcS0EdFiZvr5A/uh1NHkLdYKVtj2keS8WMFaupLcO7YkVO0cKNLdAT0bQKA 8AkDHIW1PTu5ijNRW7srxHac5blbth4XJ51ntWlPMm9tBWdJRE8KJIThTnPa1W15ALTp vYOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d4XZipr/wbiOiX+W9F5Yao9tEobwba2RM471SUvcljg=; b=cONTdWq4gjJD0MP2RYT1Dlz0y73LI8U5gawoDZNdufB2o0O54j8ygx2+hfS35/pNOB EXD/jEeWyqrvlmcCgXhNebproAwoP/Ds4ViPa4OwS0o0kSQofmtyen4hiWrrNwP663rU Ss2FR60JFlOooVgP+KhrbWA64Gm8+LbgLfXQskP2yKg90XmKtsgk3yHUBTHEhmnpcuG1 dTOG/kIdkswMhCpOgsqZGi8K91yOH8vciRNTdYtU7OwlUzvql8h1ddQMP54Ul65o+cy+ iGrtODv6Yk2xLcTDI4tqE1zb8rH6ePvlQQqu2UiGRvBHcjBi78MjKSlfmOJdBjm4dwFx FVRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1iofb3we; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b21si389839otp.79.2020.03.10.05.48.40; Tue, 10 Mar 2020 05:48:53 -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=@kernel.org header.s=default header.b=1iofb3we; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728252AbgCJMsA (ORCPT + 99 others); Tue, 10 Mar 2020 08:48:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:51950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727828AbgCJMr7 (ORCPT ); Tue, 10 Mar 2020 08:47:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C0A5420674; Tue, 10 Mar 2020 12:47:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844479; bh=mT4Is3gTXjJnNKGVbzohHzQbJiVs/z0vEr6I06JIZJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1iofb3weVLYfv6jvSE/24cvIbxAkUCtR2HgkT/ETQtHpUm544kfZ8kGogLIrALwO+ pS+RUF8HNuUh+/qFhuSje0qqiCG0e0Qi42msXhIF8TSO8VALArsQacljz7Bwm/OFvR iLuq1MhABnz/Puh/kNKXhqfqVj6G5dOe9/zBVw4w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby Subject: [PATCH 4.9 72/88] vt: selection, push console lock down Date: Tue, 10 Mar 2020 13:39:20 +0100 Message-Id: <20200310123623.463360507@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123606.543939933@linuxfoundation.org> References: <20200310123606.543939933@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") Cc: stable Link: https://lore.kernel.org/r/20200228115406.5735-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- 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 @@ -2690,9 +2690,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);