Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp313294ybf; Wed, 26 Feb 2020 13:42:48 -0800 (PST) X-Google-Smtp-Source: APXvYqz/tCEEKRfSURon9GdeFMvAnRyInmeJRtI2LeewgWIbNJ52uXcqbJZOxEJfdcfrQkQdFoQe X-Received: by 2002:aca:90f:: with SMTP id 15mr912565oij.18.1582753368447; Wed, 26 Feb 2020 13:42:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582753368; cv=none; d=google.com; s=arc-20160816; b=eKwwaFt9/zDvX3t3wGZ0kKN6Agfxur62Ca3e3cx6M0AhJpMQvRhd1/P731w3ENqHaT rJO92SvbeZsWU1NP/8QoO/Z1Msl19sICDJPKm03XEFp688W05Njc0jqCiE+hEDWHNeH+ yyOqhLOQolsbLaNWP70EawJCFSqfG1Bs+gdrWpLsiULaAwnj6bduce6Y38jI/NaPHp34 TQU0dTbKtpQu3+kA++qcFrD7I8jt4RGxadZGIrI+lXhUFxPubat86L+oWEIDZCVhHrCD O6QD1GM79fDKcU6XnHSE+Y4RAcwkTZ6lQdXibV4bgiO1i45BBPqz8sySkjNWg/trV9qC 5MTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=CMs6CM+hK6aKdC1S/oL5Dxo9YOdRorQKtX4mbGWHNSk=; b=RyPNCzWmeFPZ7BozLC3u+c40anj0JINS94ovFucUvmbsnxVmMIfTImAs88Kh3QEmuJ B0ge4jqFIf43JBo95YHsi1ouau/rnBE4TxjTEB5H8zT4C193gklFxXNpjf4pXPO7DsLe 6yFKo9zVCZMEfVe3WgLfl72+pxPn54PAKiEhs/nd06eX3BWH4SZxoCrZ1UlugiVsDtoE HgZoy2TgtQgO8ngA97E0Duf0tcLmQCqCSUU0Mw7VEG89P3YcRgoX2SLHoUY3OIx1QO19 JY8/9HbldHckw6s7pn1nBPyjK6yV1EUN9qHdmPLstBbiv+AFq0DgLI3QfKpNFhgsCqEG Rrfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CU1gKkU3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b191si242851oii.266.2020.02.26.13.42.36; Wed, 26 Feb 2020 13:42:48 -0800 (PST) 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=@chromium.org header.s=google header.b=CU1gKkU3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727755AbgBZVmF (ORCPT + 99 others); Wed, 26 Feb 2020 16:42:05 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41082 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727695AbgBZVmE (ORCPT ); Wed, 26 Feb 2020 16:42:04 -0500 Received: by mail-pg1-f194.google.com with SMTP id b1so295551pgm.8 for ; Wed, 26 Feb 2020 13:42:04 -0800 (PST) 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=CMs6CM+hK6aKdC1S/oL5Dxo9YOdRorQKtX4mbGWHNSk=; b=CU1gKkU3xVHYfQWJJENAudAyAiPTUD9x0S1kT0iOTLbD28SlxzNGyC/Pjw96hdP+Ic KYiXd/ZyZjzG/MAgYZfYLykdQEZCv52NwiDmvuSsSwe5Lz0GvhE9KWl1U6RevuNcNG/3 Yu6+M1GqnsTAvu1IQig3Cvlyxb/ZJgDUzh5tc= 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=CMs6CM+hK6aKdC1S/oL5Dxo9YOdRorQKtX4mbGWHNSk=; b=eqfKhnmKb9iWaK0e5QyDBqNMfLZVqg4wPWS2INEyYApjOPTGCDH4xyhOZCrg/Qezn/ nkWKWLxYUwWnhKZGlwSok8WlpzRauSYAX0B01ltl0Vc+qW2X605KxL3YDb0F4DHsyzpl H/x/8HYfns5NcSAN+lLuT18PhZ650J6ZDu0Ab3Xfjc6yJMPdpvKA/wLSC2AIrab4Kuhe Od8jM+hXoUp4I6oxcgq9+cq/cse8WRO0ofEoPyzXInC1iqqJrZOLxps7ow4zH/ziNXwm Nq0pdovBcfNEgulq/KJlrw7AQ9MWh8p7hIrgkU+5Xag8cEmsVEYAAmw1TiA8AAbKcoeI OEAQ== X-Gm-Message-State: APjAAAWUE/vTbgq7IK85B2VKmDJxJjafAJVBe58KhEEtdLuzWavuQ06w +db014rfHn4sbUyQBSk5t8xJJg== X-Received: by 2002:a62:f842:: with SMTP id c2mr746353pfm.104.1582753323721; Wed, 26 Feb 2020 13:42:03 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u11sm3814980pjn.2.2020.02.26.13.42.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 13:42:02 -0800 (PST) Date: Wed, 26 Feb 2020 13:42:01 -0800 From: Kees Cook To: Mark Brown Cc: Catalin Marinas , Will Deacon , Alexander Viro , Paul Elliott , Peter Zijlstra , Yu-cheng Yu , Amit Kachhap , Vincenzo Frascino , Marc Zyngier , Eugene Syromiatnikov , Szabolcs Nagy , "H . J . Lu " , Andrew Jones , Arnd Bergmann , Jann Horn , Richard Henderson , Kristina =?utf-8?Q?Mart=C5=A1enko?= , Thomas Gleixner , Florian Weimer , Sudakshina Das , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, Dave Martin Subject: Re: [PATCH v7 06/11] arm64: BTI: Decode BYTPE bits when printing PSTATE Message-ID: <202002261341.D2BB57A@keescook> References: <20200226155714.43937-1-broonie@kernel.org> <20200226155714.43937-7-broonie@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226155714.43937-7-broonie@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 03:57:09PM +0000, Mark Brown wrote: > From: Dave Martin > > The current code to print PSTATE symbolically when generating > backtraces etc., does not include the BYTPE field used by Branch > Target Identification. > > So, decode BYTPE and print it too. > > In the interests of human-readability, print the classes of BTI > matched. The symbolic notation, BYTPE (PSTATE[11:10]) and > permitted classes of subsequent instruction are: > > -- (BTYPE=0b00): any insn > jc (BTYPE=0b01): BTI jc, BTI j, BTI c, PACIxSP > -c (BYTPE=0b10): BTI jc, BTI c, PACIxSP > j- (BTYPE=0b11): BTI jc, BTI j > > Signed-off-by: Dave Martin Reviewed-by: Kees Cook -Kees > Signed-off-by: Mark Brown > --- > arch/arm64/kernel/process.c | 17 +++++++++++++++-- > 1 file changed, 15 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c > index b8e3faa8d406..24af13d7bde6 100644 > --- a/arch/arm64/kernel/process.c > +++ b/arch/arm64/kernel/process.c > @@ -211,6 +211,15 @@ void machine_restart(char *cmd) > while (1); > } > > +#define bstr(suffix, str) [PSR_BTYPE_ ## suffix >> PSR_BTYPE_SHIFT] = str > +static const char *const btypes[] = { > + bstr(NONE, "--"), > + bstr( JC, "jc"), > + bstr( C, "-c"), > + bstr( J , "j-") > +}; > +#undef bstr > + > static void print_pstate(struct pt_regs *regs) > { > u64 pstate = regs->pstate; > @@ -229,7 +238,10 @@ static void print_pstate(struct pt_regs *regs) > pstate & PSR_AA32_I_BIT ? 'I' : 'i', > pstate & PSR_AA32_F_BIT ? 'F' : 'f'); > } else { > - printk("pstate: %08llx (%c%c%c%c %c%c%c%c %cPAN %cUAO)\n", > + const char *btype_str = btypes[(pstate & PSR_BTYPE_MASK) >> > + PSR_BTYPE_SHIFT]; > + > + printk("pstate: %08llx (%c%c%c%c %c%c%c%c %cPAN %cUAO BTYPE=%s)\n", > pstate, > pstate & PSR_N_BIT ? 'N' : 'n', > pstate & PSR_Z_BIT ? 'Z' : 'z', > @@ -240,7 +252,8 @@ static void print_pstate(struct pt_regs *regs) > pstate & PSR_I_BIT ? 'I' : 'i', > pstate & PSR_F_BIT ? 'F' : 'f', > pstate & PSR_PAN_BIT ? '+' : '-', > - pstate & PSR_UAO_BIT ? '+' : '-'); > + pstate & PSR_UAO_BIT ? '+' : '-', > + btype_str); > } > } > > -- > 2.20.1 > -- Kees Cook