Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3526596ybg; Mon, 28 Oct 2019 14:21:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzb2GbHnR+yPapySYktaVjyT0cC6vQFUGW3m5IjA9/e/Ovhqm1LS4BpHPmpN4Fhza+54Ldy X-Received: by 2002:a17:906:d72:: with SMTP id s18mr18887199ejh.29.1572297696573; Mon, 28 Oct 2019 14:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572297696; cv=none; d=google.com; s=arc-20160816; b=qcJdsHGW6XC102OSW4zoJScNRbhngC128Xy+MpnFZ/f4m5uCST1DlpmdNs51QzCd+B WLM4bWFtadW+6EZmdq8Skr6bqU+UEiY3PXj0P9H3gxEEnrGExeRIBrY6w1AOKEfJc554 QFi4BeXB644tOPkfW0mWCvenlfoaTFi83VJ4y6nGzECqP/UwbUUvW2cQiPXfgwRHDq1r P32ttbQPtV8dmBOo6mbYkx2lmk3Yc9Ti3TNCtuMWsCi9a1PWKfpJTJlQurDVdBzKuoJc eGahhkdkK7kbZFic/3G8uoJoQ8DjL7gHxjGmUGghvbim+sdxJQlt4g8k0uzF2X65ViTN O57Q== 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; bh=rK9tZTfRvsJnpqoIEwidY1Vn67XTqUZeKZIlW9bC/e0=; b=vCbQIPnGsGSuMpcst3tBdiWSS6CKeZA8KXdllWxHerUhkn6hYspIVy469ERmgTHOR3 DN2C9zRWODdtPLtIjWWy924XzySFJWodRPDhNgSlVW5moLoxRLeYS5JRDot/lyC5SvEG 3vzKSqY7iWPNnF5AJaLQdu7aaoaeL68bhspT32Z0/16z6e9b5rOoNfZu4wa5L7XPOrsl oeu9wQb/yurjTM6Y9jy7b0usQJTB5h7RjLPn/sJgHergvW7mK2YumDNEoO2SrA+pfLza DXJMxybmt/GPbCGnwJ5O2yD4knIBwHp1dHUMQ9ooQ0N/8XCBJC7Y/bDmYwyP864fjDRq yzzQ== ARC-Authentication-Results: i=1; mx.google.com; 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 v16si7063915ejx.96.2019.10.28.14.21.12; Mon, 28 Oct 2019 14:21:36 -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; 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 S2391093AbfJ1Qfl (ORCPT + 99 others); Mon, 28 Oct 2019 12:35:41 -0400 Received: from foss.arm.com ([217.140.110.172]:42724 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729420AbfJ1Qfk (ORCPT ); Mon, 28 Oct 2019 12:35:40 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F03761FB; Mon, 28 Oct 2019 09:35:39 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D03093F6C4; Mon, 28 Oct 2019 09:35:37 -0700 (PDT) Date: Mon, 28 Oct 2019 16:35:33 +0000 From: Mark Rutland To: Sami Tolvanen Cc: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel , Dave Martin , Kees Cook , Laura Abbott , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux , Kernel Hardening , linux-arm-kernel , LKML Subject: Re: [PATCH v2 05/17] add support for Clang's Shadow Call Stack (SCS) Message-ID: <20191028163532.GA52213@lakrids.cambridge.arm.com> References: <20191018161033.261971-1-samitolvanen@google.com> <20191024225132.13410-1-samitolvanen@google.com> <20191024225132.13410-6-samitolvanen@google.com> <20191025105643.GD40270@lakrids.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 25, 2019 at 01:49:21PM -0700, Sami Tolvanen wrote: > On Fri, Oct 25, 2019 at 3:56 AM Mark Rutland wrote: > > > +#define SCS_END_MAGIC 0xaf0194819b1635f6UL > > > > Keyboard smash? ... or is there a prize for whoever figures out the > > secret? ;) > > It's a random number, so if someone figures out a secret in it, > they'll definitely deserve a prize. :) I'll Cc some treasure hunters. :) > > > diff --git a/kernel/fork.c b/kernel/fork.c > > > index bcdf53125210..ae7ebe9f0586 100644 > > > --- a/kernel/fork.c > > > +++ b/kernel/fork.c > > > @@ -94,6 +94,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > Nit: alphabetical order, please (this should come before stackleak.h). > > The includes in kernel/fork.c aren't in alphabetical order, so I just > added this to the end here. Fair enough. It looked otherwise in the context, and we generally aim for that as a soft rule. [...] > > > +static inline void *__scs_base(struct task_struct *tsk) > > > +{ > > > + return (void *)((uintptr_t)task_scs(tsk) & ~(SCS_SIZE - 1)); > > > +} > > > > We only ever assign the base to task_scs(tsk), with the current live > > value being in a register that we don't read. Are we expecting arch code > > to keep this up-to-date with the register value? > > > > I would have expected that we just leave this as the base (as we do for > > the regular stack in the task struct), and it's down to arch code to > > save/restore the current value where necessary. > > > > Am I missing some caveat with that approach? > > To keep the address of the currently active shadow stack out of > memory, the arm64 implementation clears this field when it loads x18 > and saves the current value before a context switch. The generic code > doesn't expect the arch code to necessarily do so, but does allow it. > This requires us to use __scs_base() when accessing the base pointer > and to reset it in idle tasks before they're reused, hence > scs_task_reset(). Ok. That'd be worth a comment somewhere, since it adds a number of things which would otherwise be unnecessary. IIUC this assumes an adversary who knows the address of a task's thread_info, and has an arbitrary-read (to extract the SCS base from thead_info) and an arbitrary-write (to modify the SCS area). Assuming that's the case, I don't think this buys much. If said adversary controls two userspace threads A and B, they only need to wait until A is context-switched out or in userspace, and read A's SCS base using B. Given that, I'd rather always store the SCS base in the thread_info, and simplify the rest of the code manipulating it. Thanks, Mark.