Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1188343ybf; Thu, 27 Feb 2020 06:32:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwiweob7uNbTx8CatvvA0hWI+JMJmWrrukuRT48iGWeNnHMLOZ4ZqjXfloo1gHb+oiU7W6S X-Received: by 2002:a05:6808:50:: with SMTP id v16mr3332305oic.133.1582813934718; Thu, 27 Feb 2020 06:32:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582813934; cv=none; d=google.com; s=arc-20160816; b=q9HHd9F5MZhgewLjvidokKxsMuCW2cgB08TUj94C/5uOGPFdj0a2XaRH+cAjo7MOtd V8bVYRTtBnXYbQfuhsql6SQesow3V4MFn47iWD3VcUYHUJzJD4uqnq5FRuKnIkstBs51 haoHVrPDrwqpPLhdt36Jc7pgvKuscmHmRuITmE2BIHBgyPgPRH+4KSeIjbzBmeEwAtoY YP+8HxREZXjMe2yfJ+w++QhQCEVy45kzmOB5f19c1ghN4P33Jc1YJm4voJsnctJUHU5E XkaMNJDoBXCiN84ctbtQdgQaK8G33iYGfJbn0XwBoWysr6F1X+f7xHB7nfUHPBfaduw9 Pcag== 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=QTZaXD9gdy8f4/DnGCMYOGLQZoUrzVw7GDExy0HT6m4=; b=ncXTifzoDKcNEFghSNG1YgdB5hKXhWz3ueDnL/DWnw6zRj61XGZbcbsX55u2H3omi9 8Uw3h7i2vuZGMeL69ywRfV7Ggo1c3PwavOpyIkT2Ztd/1Lgbpi6KLGNmzMBPr8xLmPdx 3ddEgGTT6DyKbznEgeyKMonySVtTlTOXTXfrkAvx5Yj88DxlpOp/QFF1JIP56rybSn/X QVFfkLv1K1KZMLWztSFYO6I4OXI/g7/mKcJR2O8snLQai98a+Wn9SX4Ib1jH+eWCnXky KkhIf8yexyXJ4Ae8vyd0aKse9ufpwTC1wjT3gZ7UtchaZckLFfhk/qR3TeR0Kq945Q+/ zdVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rex8Rmtd; 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 d14si1689719ote.195.2020.02.27.06.32.02; Thu, 27 Feb 2020 06:32:14 -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=rex8Rmtd; 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 S1733237AbgB0OC5 (ORCPT + 99 others); Thu, 27 Feb 2020 09:02:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:37874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733231AbgB0OCz (ORCPT ); Thu, 27 Feb 2020 09:02:55 -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 D2F2320578; Thu, 27 Feb 2020 14:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812175; bh=13f2Vkppxdi7zojv/bOid2hScaXK2veow//40ND5q4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rex8RmtdjJo3ThONP2RajNv8S0SyzFyn/njqnXpLdbJ4+N7/TYg+N/vnJhiQ89zR1 1ACrp2EEkM6FZlV4KD9ScBts/7Cx/NC+KV/SUNwAksMLShJmzwbCi3i7BI2F56WfXR WqOzhJEVnKrzv7oOUMxoblTZnafqt47UQODZrum4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby Subject: [PATCH 4.19 14/97] vt: selection, handle pending signals in paste_selection Date: Thu, 27 Feb 2020 14:36:22 +0100 Message-Id: <20200227132216.953577340@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132214.553656188@linuxfoundation.org> References: <20200227132214.553656188@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 @@ -27,6 +27,8 @@ #include #include +#include + /* Don't take this from : 011-015 on the screen aren't spaces */ #define isspace(c) ((c) == ' ') @@ -337,6 +339,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(); @@ -350,6 +353,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; @@ -365,5 +372,5 @@ int paste_selection(struct tty_struct *t tty_buffer_unlock_exclusive(&vc->port); tty_ldisc_deref(ld); - return 0; + return ret; }