Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3351305pxk; Mon, 7 Sep 2020 10:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqIiR0ujdcGMtSMbcwM6OIpEPRqiGIQq2k2GwYKeOclkodwpqxFgKGsK/bOJhENCF0hcfh X-Received: by 2002:a17:906:4a51:: with SMTP id a17mr12463650ejv.381.1599499186235; Mon, 07 Sep 2020 10:19:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599499186; cv=none; d=google.com; s=arc-20160816; b=YPFwfZjkzWbBs92/rzPvJkdE/HW0ozxkvHhOcHquhFChq/DVNkwg6F1yuERmC6Uyx4 kGDYhcr8lS/aC6jPOn8UbsNbmvyWfkYX1Xjh6jX2UaGUIRMOEDmkTubIPbzrKzBZKV09 XGMH+zSXzSELvT869rw5ho2Vuu9SUOTwEf0MQElXoqH3EIISxufIi3GT0R5F8czlwcdW W1KjIRLEFBuOP7lQY+sy1wS9F1V+vlxcNrEEgVaqWYxm95w6SK1lTuWyqMFb1CVKDCGK JmTtDI5NXGEzBpu/WWQJJdrpmqJig+EplCtuL8tTY4fFXe8wsvdIH6fPhT7cnERT/hG9 4iGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xYTzkTOO4NASBCczbFikDD++2jWnNiZ2B6dquEwbp+8=; b=BEpNH6Id7ttByIF1bO2OK9kUzd1KT7zsr6h7aYfdkl2YxWC1+wQaM/Ysv10JeTH2Py 8I434ukgZPdpPD00y4jatvdD5yspfEwxuiCeSMebSehXN4ZbVMsA5zZGGfu09en/shOW M6Sr2DpS7I0aBoZa88oKNULBtpITXuczfRu/a0iaIDV86/RiHQOo5Yp2oPj4SN09pbsG 73z6lbNRikHAkzfrl6TYLJjFeXN8/Sb8uLeZVK1tswpyJYu40/hO7IHinNoAnysbxt39 AuUM+fVG3bXbFHMDNST7EAvBq5/y2NUmaYJKoj+ROoai+okXNd5GV+mf/kQiN7bUFBaO 7w/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dl/DUE0p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g16si8200941ejs.187.2020.09.07.10.19.23; Mon, 07 Sep 2020 10:19:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="dl/DUE0p"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730607AbgIGRSo (ORCPT + 99 others); Mon, 7 Sep 2020 13:18:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:41762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729766AbgIGRSa (ORCPT ); Mon, 7 Sep 2020 13:18:30 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 44444206B8; Mon, 7 Sep 2020 17:18:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599499110; bh=IEZaBZy+wF6qUv3LytCsSz8WDwJL0KEc1L1DPsZ6+7o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dl/DUE0pmefb4/xQ/Jr74SJHnHU31J7Hd7ut34f2DJhWbmQFq+lWETrJEIQKn/Bg7 Hbx32NmMYECK6tCKnlKhXtF4evW0YXDidJ4/wCDBYJs6ImumYLxSZAhvDARqjL4CNq eEtMnw5Lfa5MQxvgU8aIN+cJ3uEZNWtPARKxxQy4= Date: Mon, 7 Sep 2020 18:18:25 +0100 From: Will Deacon To: Anthony Steinhauser Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, maz@kernel.org Subject: Re: [PATCH] PR_SPEC_DISABLE_NOEXEC support for arm64. Message-ID: <20200907171825.GB13281@willie-the-truck> References: <20200717110532.238533-1-asteinhauser@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200717110532.238533-1-asteinhauser@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 17, 2020 at 04:05:32AM -0700, Anthony Steinhauser wrote: > For x64 it was already implemented in: > https://github.com/torvalds/linux/commit/71368af > > The rationale is the same as for the x64 implementation. > > Signed-off-by: Anthony Steinhauser > --- > > It's actively attempted by OpenJDK on arm64 CentOS and Fedora: > https://git.centos.org/rpms/java-11-openjdk/blob/c8s/f/SOURCES/rh1566890-CVE_2018_3639-speculative_store_bypass.patch > > arch/arm64/include/asm/ssbd.h | 28 ++++++++++++++++++++++++++++ > arch/arm64/kernel/process.c | 13 +++++++++++++ > arch/arm64/kernel/ssbd.c | 34 +++++++++++++++++----------------- > 3 files changed, 58 insertions(+), 17 deletions(-) > create mode 100644 arch/arm64/include/asm/ssbd.h As a heads up: I'm currently reworking most of this, and hope to post something within the next two weeks. > diff --git a/arch/arm64/include/asm/ssbd.h b/arch/arm64/include/asm/ssbd.h > new file mode 100644 > index 000000000000..68c716dc5811 > --- /dev/null > +++ b/arch/arm64/include/asm/ssbd.h > @@ -0,0 +1,28 @@ > +/* SPDX-License-Identifier: GPL-2.0-only */ > +/* > + * Copyright (C) 2020 Google LLC. > + */ > +#ifndef __ASM_SSBD_H > +#define __ASM_SSBD_H > + > +#include > +#include > +#include > + > +static inline void ssbd_ssbs_enable(struct task_struct *task) > +{ > + u64 val = is_compat_thread(task_thread_info(task)) ? > + PSR_AA32_SSBS_BIT : PSR_SSBS_BIT; > + > + task_pt_regs(task)->pstate |= val; > +} > + > +static inline void ssbd_ssbs_disable(struct task_struct *task) > +{ > + u64 val = is_compat_thread(task_thread_info(task)) ? > + PSR_AA32_SSBS_BIT : PSR_SSBS_BIT; > + > + task_pt_regs(task)->pstate &= ~val; > +} I'd prefer to keep these where they are and have an out-of-line call if necessary. We should try to keep the SSBD stuff in one place. > + > +#endif /* __ASM_SSBD_H */ > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index 6089638c7d43..ad3c67c86c4c 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -54,6 +54,7 @@ > #include > #include > #include > +#include > #include > > #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_STACKPROTECTOR_PER_TASK) > @@ -588,6 +589,18 @@ void arch_setup_new_exec(void) > current->mm->context.flags = is_compat_task() ? MMCF_AARCH32 : 0; > > ptrauth_thread_init_user(current); > + > + /* > + * Don't inherit TIF_SSBD across exec boundary when > + * PR_SPEC_DISABLE_NOEXEC is used. > + */ > + if (test_thread_flag(TIF_SSBD) && > + task_spec_ssb_noexec(current)) { > + clear_thread_flag(TIF_SSBD); > + task_clear_spec_ssb_disable(current); > + task_clear_spec_ssb_noexec(current); > + ssbd_ssbs_enable(current); > + } How is this supposed to work with CPUs that expose SSBS directly to userspace? I suppose we should be using PR_SPEC_DISABLE_NOEXEC to decide what we set the SSBS bit to on exec, but the logic here requires TIF_SSBD to be set and so won't trigger afaict. Will