Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp793978imm; Mon, 21 May 2018 14:35:19 -0700 (PDT) X-Google-Smtp-Source: AB8JxZreOoW488PCvDcxWvtibjrPZgED3MFT3s8+GU8mOmHQbRIePYOi5eTdm+nSyy2PszWBsuta X-Received: by 2002:a62:d352:: with SMTP id q79-v6mr21875884pfg.45.1526938519484; Mon, 21 May 2018 14:35:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526938519; cv=none; d=google.com; s=arc-20160816; b=Our1s6ihBc+06dcx96rfHXr+mf83yAB2LdspPMkKFKvKW04j0cU1Lew3zl8Ndu1bEI gPxL2Nn7m2KSFGm2clUty3g0bIwqzgdfxsjjWEdk0Q5k8p4BaVwXq77umAaIpcr+/OpY lkyn1Z3Lj2WsW/9/NY6n9ZAoI6zRrQ9mabSHRT70NnOO7nZdCeLbACfqw4qLLFUcY99/ YzdibkSjVzKZyRB5y8ygMkKkoPdWmrFw+fISI4cn6xq5qSYOkDtjkx4Z9j2EsZ8c1SX/ Ced4e2F/0k0LO8xXQ5DdnoMZtEyz89mTnsAqHvfu4OQUKBWTEyIZSaWeHlfgJQrJ52ar W+Xw== 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=Lu9BCzksub3Nel+vzTVqLqi6IWq8DnlKT/xKw82nIH0=; b=LBxy+QjVYKGsncFJUhwBJelaEo2bbCGoyjNBqZRK77ngTtUqAqd+CscYVc+FzHiwpQ ZaYnQKIRFS11KblX8XJaJphvu8+VdCqotg1eJqJhHGqQRmaTB/IPjTQccPXxJqABFRul xD37Pru/92O0OYkFIMDDZPXJSH3nUnuZdvWYziyeTxuS6WVdA+r9IOfkF17spLhPQzSs m7DlVGeFq0UrW0v1H5f/XghUAN+IBFqt78P+8Yup7tAHE1FAl+ZXLv0HyeEYfzmJzYZK wVc7XQNVlBSxuOcnPwVkd72F8gvnQ37SKlMSDrk0bQQKp+d0EjCU15Mzg8Hj+GC/VOvY ruIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lqjQpg8D; 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 h10-v6si8905104pgq.131.2018.05.21.14.35.04; Mon, 21 May 2018 14:35:19 -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=lqjQpg8D; 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 S1754486AbeEUVey (ORCPT + 99 others); Mon, 21 May 2018 17:34:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:40680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932480AbeEUVZv (ORCPT ); Mon, 21 May 2018 17:25:51 -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 3744520877; Mon, 21 May 2018 21:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526937950; bh=pg1Ee3oiZDceEF7RBgQXYaZLgdN6LgCzTcc8KBSH8KY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqjQpg8DNjo4jltnYdaUV8ptNX12fg4iCTUuIPNNVllPKpKj4Jq8OQxtNX3Di8VeW 4e+nIXVqxwLLpE3Hxgq/oZzhpL3LglAsDfqcPsg59uCL5dPUizy2iAdPWpmp1ZfWcv yDZk1R1f4kqUvQv39K77BZA+zXbeKowIWOudWPXA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner Subject: [PATCH 4.16 085/110] seccomp: Move speculation migitation control to arch code Date: Mon, 21 May 2018 23:12:22 +0200 Message-Id: <20180521210513.688318412@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: Thomas Gleixner commit 8bf37d8c067bb7eb8e7c381bdadf9bd89182b6bc upstream The migitation control is simpler to implement in architecture code as it avoids the extra function call to check the mode. Aside of that having an explicit seccomp enabled mode in the architecture mitigations would require even more workarounds. Move it into architecture code and provide a weak function in the seccomp code. Remove the 'which' argument as this allows the architecture to decide which mitigations are relevant for seccomp. Signed-off-by: Thomas Gleixner Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/bugs.c | 29 ++++++++++++++++++----------- include/linux/nospec.h | 2 ++ kernel/seccomp.c | 15 ++------------- 3 files changed, 22 insertions(+), 24 deletions(-) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -569,6 +569,24 @@ static int ssb_prctl_set(struct task_str return 0; } +int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which, + unsigned long ctrl) +{ + switch (which) { + case PR_SPEC_STORE_BYPASS: + return ssb_prctl_set(task, ctrl); + default: + return -ENODEV; + } +} + +#ifdef CONFIG_SECCOMP +void arch_seccomp_spec_mitigate(struct task_struct *task) +{ + ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE); +} +#endif + static int ssb_prctl_get(struct task_struct *task) { switch (ssb_mode) { @@ -587,17 +605,6 @@ static int ssb_prctl_get(struct task_str } } -int arch_prctl_spec_ctrl_set(struct task_struct *task, unsigned long which, - unsigned long ctrl) -{ - switch (which) { - case PR_SPEC_STORE_BYPASS: - return ssb_prctl_set(task, ctrl); - default: - return -ENODEV; - } -} - int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which) { switch (which) { --- a/include/linux/nospec.h +++ b/include/linux/nospec.h @@ -62,5 +62,7 @@ static inline unsigned long array_index_ 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); +/* Speculation control for seccomp enforced mitigation */ +void arch_seccomp_spec_mitigate(struct task_struct *task); #endif /* _LINUX_NOSPEC_H */ --- a/kernel/seccomp.c +++ b/kernel/seccomp.c @@ -229,18 +229,7 @@ static inline bool seccomp_may_assign_mo return true; } -/* - * If a given speculation mitigation is opt-in (prctl()-controlled), - * select it, by disabling speculation (enabling mitigation). - */ -static inline void spec_mitigate(struct task_struct *task, - unsigned long which) -{ - int state = arch_prctl_spec_ctrl_get(task, which); - - if (state > 0 && (state & PR_SPEC_PRCTL)) - arch_prctl_spec_ctrl_set(task, which, PR_SPEC_FORCE_DISABLE); -} +void __weak arch_seccomp_spec_mitigate(struct task_struct *task) { } static inline void seccomp_assign_mode(struct task_struct *task, unsigned long seccomp_mode, @@ -256,7 +245,7 @@ static inline void seccomp_assign_mode(s smp_mb__before_atomic(); /* Assume default seccomp processes want spec flaw mitigation. */ if ((flags & SECCOMP_FILTER_FLAG_SPEC_ALLOW) == 0) - spec_mitigate(task, PR_SPEC_STORE_BYPASS); + arch_seccomp_spec_mitigate(task); set_tsk_thread_flag(task, TIF_SECCOMP); }