Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp786491imm; Mon, 21 May 2018 14:26:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZotBFE715nN7wQF8iOBwphSSFCTVZa3psZ7wBnAVvgbLh6rhIHasBuyt995asT6KeyGDUOm X-Received: by 2002:a17:902:a986:: with SMTP id bh6-v6mr22297747plb.245.1526937966411; Mon, 21 May 2018 14:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526937966; cv=none; d=google.com; s=arc-20160816; b=tkFuAKC++4y/hrkX3HOEzehPW/kVL/ikpDFaz9dBq2Y8RBbgVodaZH9CZ4/M+p2z/k x8ss+32ji6Xs7s39oaTaV/hjGq/sNa4IG289F+bBpRAaKOktqqpSlpC/eD2ieIsOArAm DUTL3tpYsLej+Zfcl8lLZouyvSu1bzc1doX/3jkbgY9/BqKWaKv/XU3TpONUYa5DEgKk S0hwgnNzJ5gTxg0VsPo26ipnrlcTG0F3g8zAAYCVBZ7/LD1q4mD5MdXCXwzyqBW6eROR HNTDYI2fgHhPY0e+1nblsI594Q+Ng/i0mtrBVtYxy3vzIrjJEE+xzyx8AL7su4QEK3a3 5DDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=hJs9aYnYwGuDTxPyxAjM/Ntkwj7c5/i6QhWleA8tQx4=; b=QLR3tyezWIt/8Hxag2sixofxX7RahwAEhbmiDc0jHjbHUs2Er2Noel6BfXgtSuHZjy QEQXugFH8Y4mB3+2Vno0GaR68dWZZUgX8AzjNJ0ZlgPt1c1X0MWs7dqNQEyGzmhOAmZB FQVkdw5tOha47bJdMFvs9x7qtGk7TgOJyiY1LccH6QL1qi5qVkyxY7E4kOW4wCyEuv5v ydG8yl+5DGWLEWaUtqcQLdgvhwLMBLgY7JUoRbNFrZrqu4l6OixNdkvMCuS5+ENDOnia ScyaUU4EnwtFgYSiwreJJ3oHLecRWpmtQ2DQuH3rFIEoiC62gzCR1Cyl435s0kIuxTAY /v+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rm+vBqV2; 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 u68-v6si15117654pfb.42.2018.05.21.14.25.52; Mon, 21 May 2018 14:26:06 -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=rm+vBqV2; 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 S932201AbeEUVZi (ORCPT + 99 others); Mon, 21 May 2018 17:25:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:40338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932408AbeEUVZ3 (ORCPT ); Mon, 21 May 2018 17:25:29 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 9A10920875; Mon, 21 May 2018 21:25:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937929; bh=JKqrM6miMEJI2n1NgswGbKfonJbGNxMLlDGHN4EEC4w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rm+vBqV2RXzYoYlg/46JmW1gQsYiOKSIoYs3FVs0RoZv1j/Il3SgiCwKEYiDQIAj/ v3PBRkEpRh9/VyVx0rXfWe1p2cn0Y9CXNl3LcG6Yg2oYqVdzv3WWsWTnyHYlTAgNNN fRf2hBh6kHTaKJjglCNkZ4nVg8Qdz0LVKnpElsRI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kees Cook , Thomas Gleixner Subject: [PATCH 4.16 078/110] nospec: Allow getting/setting on non-current task Date: Mon, 21 May 2018 23:12:15 +0200 Message-Id: <20180521210512.997790253@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180521210503.823249477@linuxfoundation.org> References: <20180521210503.823249477@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kees Cook commit 7bbf1373e228840bb0295a2ca26d548ef37f448e upstream Adjust arch_prctl_get/set_spec_ctrl() to operate on tasks other than current. This is needed both for /proc/$pid/status queries and for seccomp (since thread-syncing can trigger seccomp in non-current threads). Signed-off-by: Kees Cook Signed-off-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 27 ++++++++++++++++----------- include/linux/nospec.h | 7 +++++-- kernel/sys.c | 9 +++++---- 3 files changed, 26 insertions(+), 17 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -530,31 +530,35 @@ static void ssb_select_mitigation() #undef pr_fmt -static int ssb_prctl_set(unsigned long ctrl) +static int ssb_prctl_set(struct task_struct *task, unsigned long ctrl) { - bool rds = !!test_tsk_thread_flag(current, TIF_RDS); + bool rds = !!test_tsk_thread_flag(task, TIF_RDS); if (ssb_mode != SPEC_STORE_BYPASS_PRCTL) return -ENXIO; if (ctrl == PR_SPEC_ENABLE) - clear_tsk_thread_flag(current, TIF_RDS); + clear_tsk_thread_flag(task, TIF_RDS); else - set_tsk_thread_flag(current, TIF_RDS); + set_tsk_thread_flag(task, TIF_RDS); - if (rds != !!test_tsk_thread_flag(current, TIF_RDS)) + /* + * If being set on non-current task, delay setting the CPU + * mitigation until it is next scheduled. + */ + if (task == current && rds != !!test_tsk_thread_flag(task, TIF_RDS)) speculative_store_bypass_update(); return 0; } -static int ssb_prctl_get(void) +static int ssb_prctl_get(struct task_struct *task) { switch (ssb_mode) { case SPEC_STORE_BYPASS_DISABLE: return PR_SPEC_DISABLE; case SPEC_STORE_BYPASS_PRCTL: - if (test_tsk_thread_flag(current, TIF_RDS)) + if (test_tsk_thread_flag(task, TIF_RDS)) return PR_SPEC_PRCTL | PR_SPEC_DISABLE; return PR_SPEC_PRCTL | PR_SPEC_ENABLE; default: @@ -564,24 +568,25 @@ static int ssb_prctl_get(void) } } -int arch_prctl_spec_ctrl_set(unsigned long which, unsigned long ctrl) +int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which, + unsigned long ctrl) { if (ctrl != PR_SPEC_ENABLE && ctrl != PR_SPEC_DISABLE) return -ERANGE; switch (which) { case PR_SPEC_STORE_BYPASS: - return ssb_prctl_set(ctrl); + return ssb_prctl_set(task, ctrl); default: return -ENODEV; } } -int arch_prctl_spec_ctrl_get(unsigned long which) +int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which) { switch (which) { case PR_SPEC_STORE_BYPASS: - return ssb_prctl_get(); + return ssb_prctl_get(task); default: return -ENODEV; } --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -7,6 +7,8 @@ #define _LINUX_NOSPEC_H #include +struct task_struct; + /** * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 otherwise * @index: array element index @@ -57,7 +59,8 @@ static inline unsigned long array_index_ }) /* Speculation control prctl */ -int arch_prctl_spec_ctrl_get(unsigned long which); -int arch_prctl_spec_ctrl_set(unsigned long which, unsigned long ctrl); +int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which); +int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which, + unsigned long ctrl); #endif /* _LINUX_NOSPEC_H */ --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2192,12 +2192,13 @@ static int propagate_has_child_subreaper return 1; } -int __weak arch_prctl_spec_ctrl_get(unsigned long which) +int __weak arch_prctl_spec_ctrl_get(struct task_struct *t, unsigned long which) { return -EINVAL; } -int __weak arch_prctl_spec_ctrl_set(unsigned long which, unsigned long ctrl) +int __weak arch_prctl_spec_ctrl_set(struct task_struct *t, unsigned long which, + unsigned long ctrl) { return -EINVAL; } @@ -2413,12 +2414,12 @@ SYSCALL_DEFINE5(prctl, int, option, unsi case PR_GET_SPECULATION_CTRL: if (arg3 || arg4 || arg5) return -EINVAL; - error = arch_prctl_spec_ctrl_get(arg2); + error = arch_prctl_spec_ctrl_get(me, arg2); break; case PR_SET_SPECULATION_CTRL: if (arg4 || arg5) return -EINVAL; - error = arch_prctl_spec_ctrl_set(arg2, arg3); + error = arch_prctl_spec_ctrl_set(me, arg2, arg3); break; default: error = -EINVAL;