Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1184527ybf; Thu, 27 Feb 2020 06:28:55 -0800 (PST) X-Google-Smtp-Source: APXvYqy8vlXMyB6BBU6Gbv1/o+Os6VYes9icLHvbrIkbTWIL/q1TmRsfiP2LQ5SfRzU4aoFqNrrt X-Received: by 2002:a05:6830:1657:: with SMTP id h23mr3430907otr.299.1582813735349; Thu, 27 Feb 2020 06:28:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813735; cv=none; d=google.com; s=arc-20160816; b=L9xIeMCYXS0Vthl1vWDR4s6iNAn7HCYcbwZMQUlS66qRZCatJrsU87sojy1qzo9r55 CWD8YSPzng+Y/7lWc2UP1z4i9bhIHHu2d0G/hJ3wW9Rce/vm9Yqgrp/9jhH+UjUDpum3 Opms9ci2qKH68ccSyD+VBCH4E5I1HvIuwRFGq8/9C9S4zas16TlIx42ZvVITlXIR1lyq Kfs2qH2MGS6J+8J3jGNtZzCLxh8ERuBH48zLrQEaW0oqXcQiJdYMvukJcVne/MT0eJmi IPAJDrsOMCt7z63Jdjo6do17BbiELchwAZ3aAHjDNPmqArNteu0Cnf4jwxkR7MS1WA+2 jLlA== 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=PARBlU6e4J8Y8gfCt2kzViN/UnRjDv6mgtUm0LwN2JU=; b=SsgAFbRn5eLOfROcACaf3jPf7SFKyAcF+IgOYutu2wAY5SWHjNWTiOAxgrIoyuO1O3 FBZ/x+z/1+biFgEOsVL2vqNBGbbY5sG0rDS5AuzkvxiC06cTU0F8R/aNQ6hT3S66oSiI rd+LsUxV0g6H69aGPqL3M46fcpmM3ILSLHJaO1aaT6HfnsL0Za+vtNM98+enVswDuhKx uvzfw5yrZRyGf4CQTzQuf3TE4fbsdKuNDD0T6e5wXjpNEcXdFeGa5JhcfQkBZCfibLL+ 5dKI9RWaj9342N4bCwH58jgMXR33ZWe8X+1TFfUJANN4V4gpTxiIiWOi82tzBT90vypU uOtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ydF+M/dO"; 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 x14si1589034otj.322.2020.02.27.06.28.43; Thu, 27 Feb 2020 06:28:55 -0800 (PST) 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="ydF+M/dO"; 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 S2388379AbgB0O2g (ORCPT + 99 others); Thu, 27 Feb 2020 09:28:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:44762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388073AbgB0OHT (ORCPT ); Thu, 27 Feb 2020 09:07:19 -0500 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 E452521D7E; Thu, 27 Feb 2020 14:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812438; bh=NjFPG8xSrKgimw87UF2CW1b5ud1z43xOcu4dU/Mnkqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ydF+M/dOA10Ppxp5xgb2VlP3a/024ypJA89FT5INSdfkDOABaYb6eNNh7qdenpf7h T8XqYtFYEZJ4cni3+AfLBxYxXMNU6QX/hz4NxjiYt+P2z9JSQoIz+6wWSrRRkqRLfa Nuqoec+EyhUqmyP8sMbLR+OkH7cNsL7JvC/9VubA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby Subject: [PATCH 5.4 018/135] vt: selection, handle pending signals in paste_selection Date: Thu, 27 Feb 2020 14:35:58 +0100 Message-Id: <20200227132232.006860598@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@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 687bff0cd08f790d540cfb7b2349f0d876cdddec upstream. When pasting a selection to a vt, the task is set as INTERRUPTIBLE while waiting for a tty to unthrottle. But signals are not handled at all. Normally, this is not a problem as tty_ldisc_receive_buf receives all the goods and a user has no reason to interrupt the task. There are two scenarios where this matters: 1) when the tty is throttled and a signal is sent to the process, it spins on a CPU until the tty is unthrottled. schedule() does not really echedule, but returns immediately, of course. 2) when the sel_buffer becomes invalid, KASAN prevents any reads from it and the loop simply does not proceed and spins forever (causing the tty to throttle, but the code never sleeps, the same as above). This sometimes happens as there is a race in the sel_buffer handling code. So add signal handling to this ioctl (TIOCL_PASTESEL) and return -EINTR in case a signal is pending. Signed-off-by: Jiri Slaby Cc: stable Link: https://lore.kernel.org/r/20200210081131.23572-1-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/tty/vt/selection.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/drivers/tty/vt/selection.c +++ b/drivers/tty/vt/selection.c @@ -29,6 +29,8 @@ #include #include +#include + /* Don't take this from : 011-015 on the screen aren't spaces */ #define isspace(c) ((c) == ' ') @@ -350,6 +352,7 @@ int paste_selection(struct tty_struct *t unsigned int count; struct tty_ldisc *ld; DECLARE_WAITQUEUE(wait, current); + int ret = 0; console_lock(); poke_blanked_console(); @@ -363,6 +366,10 @@ int paste_selection(struct tty_struct *t add_wait_queue(&vc->paste_wait, &wait); while (sel_buffer && sel_buffer_lth > pasted) { set_current_state(TASK_INTERRUPTIBLE); + if (signal_pending(current)) { + ret = -EINTR; + break; + } if (tty_throttled(tty)) { schedule(); continue; @@ -378,6 +385,6 @@ int paste_selection(struct tty_struct *t tty_buffer_unlock_exclusive(&vc->port); tty_ldisc_deref(ld); - return 0; + return ret; } EXPORT_SYMBOL_GPL(paste_selection);