From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75373C28CC0 for ; Thu, 30 May 2019 03:36:34 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 49E4224B71 for ; Thu, 30 May 2019 03:36:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LDAl+RLi"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ivmtiP+b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 49E4224B71 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QjU/A6O42PZdshLI7PAp3rM4m134FrxHUvGZIfXGvhk=; b=LDAl+RLiiiCQul z9EI+CUipH43P7LapeNubO5rEC/a5RsE64mUWeYwpo+K0bfiVcN9abKw8YAmsjkN70XBC9fPUlrr5 2FygCwX0oeoW5GzsrFDtEwkwK74Bz8t5fT0atkAvgwMcF1lvz3Muis4JofBrvUPBsR7okFPkxT+SA yx7wVBF/iVMFz+J6+wFlbpod8thcZ6thkhk7a+dBgapEdyq4zm0EQbDn+umfkGgTdFbHL2D5jKAt8 NkTFoj6mEnSXCXxeKXp5brD6p7uqE8Fmx5a7ym4Mgtd6lJcndeYfp/Zbi6SrX59QMgViLyZ8yc4qo L6zfnGsPfBs/4pWmO4AA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWBrj-0003Yh-3V; Thu, 30 May 2019 03:36:31 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hWBrg-0003YN-Cg for linux-arm-kernel@lists.infradead.org; Thu, 30 May 2019 03:36:29 +0000 Received: by mail-pg1-x542.google.com with SMTP id n2so1116068pgp.11 for ; Wed, 29 May 2019 20:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=sQQIrKCZw7QJSvWRojgxcrgfDweSyJMGbr73dM9YOfA=; b=ivmtiP+bmqM37BCsnV51RB1vs3qGfkQMINQAzja+MAJLcXy9vwQdCa67MZR+CxyW3b SXruT+dUQfOfhiDAcm0kGPTFpu+BxKpbbIwS35QkW3S0/hvgT5f3+gDbYzgAzTFV0Z/c noiuoTkVq44HFKRcDYZEaAO1fPdDV9ey92H0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=sQQIrKCZw7QJSvWRojgxcrgfDweSyJMGbr73dM9YOfA=; b=aJgLjd9iX+hNxhKc22swLJUVdancW0O+QoMDEPjo8wOcIqIOa6lMvKjaCZYwhOfp/H 65SGMIfv1NNPz575gYH+Q+vogtS+kEBjFUUzZrd7C80iQP6+rOsM1E0zDdKs+rhAd1B9 yHW43OZT8p+34bQPMGZktTz5YVkpwkEnm61XgWluA/RWHxlGqGW55cEZ8Hoj65ZMFNd5 RsuMEWYBqlDPMhjDvAIFmZGemnOggHGuFtfnmyTPVy0lEA9g9uLmbWs8rAKzZL6ZUqCI q2/nL6TSgeokGe4JzTFTcFkwlGPfU0b2XlQ/bJCvo/SfkzYv8qeGdg63zULdQQSnd+C9 m3tA== X-Gm-Message-State: APjAAAUMVer6STz8q2eUJyUQl/ZzyL5oSHM9Hwr7dYvoZkQlzlc7KQa1 0jbT4KEup1h0bAM+jq4fhuJKQQ== X-Google-Smtp-Source: APXvYqz5mhzD4gugDelwxgPmCknBvQYV+YduG9U90ygKMUM5cxPglagBlx+ToZPvyJ2TPhrpMkt8kw== X-Received: by 2002:a17:90a:cb82:: with SMTP id a2mr1657996pju.80.1559187387253; Wed, 29 May 2019 20:36:27 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k36sm971779pjb.14.2019.05.29.20.36.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 May 2019 20:36:26 -0700 (PDT) Date: Wed, 29 May 2019 20:36:25 -0700 From: Kees Cook To: Kristina Martsenko Subject: Re: [RFC v2 6/7] arm64: unwind: strip PAC from kernel addresses Message-ID: <201905292035.A4D0E73@keescook> References: <20190529190332.29753-1-kristina.martsenko@arm.com> <20190529190332.29753-7-kristina.martsenko@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20190529190332.29753-7-kristina.martsenko@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190529_203628_433813_B39D6721 X-CRM114-Status: GOOD ( 19.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ard Biesheuvel , Catalin Marinas , Suzuki K Poulose , Will Deacon , Ramana Radhakrishnan , Amit Kachhap , Dave Martin , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, May 29, 2019 at 08:03:31PM +0100, Kristina Martsenko wrote: > From: Mark Rutland > > When we enable pointer authentication in the kernel, LR values saved to > the stack will have a PAC which we must strip in order to retrieve the > real return address. > > Strip PACs when unwinding the stack in order to account for this. > > Reviewed-by: Amit Daniel Kachhap > Signed-off-by: Mark Rutland > Signed-off-by: Kristina Martsenko Reviewed-by: Kees Cook -Kees > --- > > Changes since RFC v1: > - Moved the patch later in the series > > arch/arm64/include/asm/pointer_auth.h | 10 +++++++--- > arch/arm64/kernel/stacktrace.c | 3 +++ > 2 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/include/asm/pointer_auth.h b/arch/arm64/include/asm/pointer_auth.h > index 79f35f5ecff5..5491c34b4dc3 100644 > --- a/arch/arm64/include/asm/pointer_auth.h > +++ b/arch/arm64/include/asm/pointer_auth.h > @@ -80,12 +80,16 @@ extern int ptrauth_prctl_reset_keys(struct task_struct *tsk, unsigned long arg); > * The EL0 pointer bits used by a pointer authentication code. > * This is dependent on TBI0 being enabled, or bits 63:56 would also apply. > */ > -#define ptrauth_user_pac_mask() GENMASK(54, vabits_user) > +#define ptrauth_user_pac_mask() GENMASK(54, vabits_user) > + > +#define ptrauth_kernel_pac_mask() (GENMASK(63, 56) | GENMASK(54, VA_BITS)) > > -/* Only valid for EL0 TTBR0 instruction pointers */ > static inline unsigned long ptrauth_strip_insn_pac(unsigned long ptr) > { > - return ptr & ~ptrauth_user_pac_mask(); > + if (ptr & BIT_ULL(55)) > + return ptr | ptrauth_kernel_pac_mask(); > + else > + return ptr & ~ptrauth_user_pac_mask(); > } > > #define ptrauth_thread_init_user(tsk) \ > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index d908b5e9e949..df07c27a9673 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -24,6 +24,7 @@ > #include > > #include > +#include > #include > #include > > @@ -56,6 +57,8 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) > frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); > frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); > > + frame->pc = ptrauth_strip_insn_pac(frame->pc); > + > #ifdef CONFIG_FUNCTION_GRAPH_TRACER > if (tsk->ret_stack && > (frame->pc == (unsigned long)return_to_handler)) { > -- > 2.11.0 > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel