Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp312059ybf; Wed, 26 Feb 2020 13:41:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyCUUPjVg+rnvO7qHUw4ZPVIPlY2iWLibBQzLg22OqimCDaUTSndW1Tcub5NRH7aTavwxj0 X-Received: by 2002:a9d:34c:: with SMTP id 70mr676183otv.174.1582753272108; Wed, 26 Feb 2020 13:41:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582753272; cv=none; d=google.com; s=arc-20160816; b=xMhhEovuxCWe8CCMk8G8++JcM8NoImW8GMJoX/8Py32JKtc/7fx/BBGeY6GgrZBtN3 CqCRFBDVx21SvKfrXcGAeDPdhksjvxAiImHi5u6oPepRg9w4c8LB28PAoBSItQQ0jduU 4d9iC8n8sIs3I+IuK+8ogISo4A41SMRmJ0KmVZIaIGgHpg+rLf7SlCODpxB5dDRNide8 gkGao5xsqmdOIQrQzgsuxlGLyaWvzSn8M/HLteIyv5aPdQp0zKZTwmmui6sCBXVKrpS9 imSnTN5YMzu+nO8CwidXlMvRsLZ3d4l5lTRZjh7aWQ5pMHH2I3p5n2LugEAPg3uW4gB3 R8ZQ== 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=SuRPBFQdcJTBQXLfW7zhTZM3AVXzTzaLq0hZO+OJ8t8=; b=KfzJH+DVPFvvNVkMEWXOLYuXV6REsoZPC43aktPUgF6qFdqFGME5aKT5CEWjEZxCCy Wj2iHTKoN+G+A/3PMySejKFDL5xsn3aL4O/i02QpP4Zo18sCKyYhINGP4+HM1fKJDd5g b3XySQBbjZ3yic+1a22XUswNMXsYuTgE7GMMNfMG+aaRLAeMxUrWh9+ZqJVWQRnxjjSu wnX8CmDqmpicFuVDKNPk2owyFqTSiA/5hFHLzRtlF8YbCbAM+Z4CDfMombGAfht3GnmF 3q/zWZ7LK6+ohbnxlCMUkZzySTdrZ7sSIbcDYbDld/hKJacTYt4SPWLiDsfsYtFOxzZs jDYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="McMrWJB/"; 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 y8si229979oih.141.2020.02.26.13.40.59; Wed, 26 Feb 2020 13:41:12 -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="McMrWJB/"; 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 S1727740AbgBZVjy (ORCPT + 99 others); Wed, 26 Feb 2020 16:39:54 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:34012 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727637AbgBZVjx (ORCPT ); Wed, 26 Feb 2020 16:39:53 -0500 Received: by mail-pf1-f193.google.com with SMTP id i6so453741pfc.1 for ; Wed, 26 Feb 2020 13:39:51 -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=SuRPBFQdcJTBQXLfW7zhTZM3AVXzTzaLq0hZO+OJ8t8=; b=McMrWJB/rzDG1kYNRHCmu6YGhWogESTULXa4e+VE70LyFgccjXgbd+15VJ3LqXUUU8 jJaLOjX8fotobjx6twtTRj4EZmpxPNIw/R2SlyBMIKuyHb/AIRdVMvgSR5jzwqx1whrJ Fa20+GL6IL88TZFTbMeFNrQ8Xj9oz3fbcCWZ0= 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=SuRPBFQdcJTBQXLfW7zhTZM3AVXzTzaLq0hZO+OJ8t8=; b=Ixkj2NQUhwCDB0ouStXTFoxZwnmfQ5XcY2JlYPH0PWY5U9cNAuPPyaXO3S/AMNU3cZ 0/LgdXJGd1e+LpiXwBwvanuTqCpAwaR/Bqxgwdj5jZrP4IziHQg+H/3O5Ygz+PNVUgG4 uGIJ3l43v+kXjEulJIzRC5hnwCSYN+UKj7WiTJ2iER1/aNog7UhJzyxG3z0vgIXVgwVL ZBSHWI4YBa8/BJMDQaGm/7S+QwkPWVJS8uxHBi3drBZSxFNzg5b5UuD83MuQlV/2hDQS x7DUuL6vDqC4Ub1+wrL87b3ZXPgYTsVAD4gjdK5Nra3yHTSbuLFL8sAEYWFS2PArjgpC ebMA== X-Gm-Message-State: APjAAAX12KL/n3eNBrXWeyEV5sXlfB/4sytK8LOKAvxeBuaoujnI9Gpp 12aeW0BL5QyT6FZIBSXVretTQA== X-Received: by 2002:a63:1a5b:: with SMTP id a27mr769948pgm.249.1582753191171; Wed, 26 Feb 2020 13:39:51 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i2sm3730242pjs.21.2020.02.26.13.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 13:39:50 -0800 (PST) Date: Wed, 26 Feb 2020 13:39:49 -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 08/11] arm64: traps: Shuffle code to eliminate forward declarations Message-ID: <202002261339.53539BA19@keescook> References: <20200226155714.43937-1-broonie@kernel.org> <20200226155714.43937-9-broonie@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226155714.43937-9-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:11PM +0000, Mark Brown wrote: > From: Dave Martin > > Hoist the IT state handling code earlier in traps.c, to avoid > accumulating forward declarations. > > No functional change. > > Signed-off-by: Dave Martin Reviewed-by: Kees Cook -Kees > Signed-off-by: Mark Brown > --- > arch/arm64/kernel/traps.c | 103 ++++++++++++++++++-------------------- > 1 file changed, 50 insertions(+), 53 deletions(-) > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index bc9f4292bfc3..3c07a7074145 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -272,7 +272,55 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, > } > } > > -static void advance_itstate(struct pt_regs *regs); > +#ifdef CONFIG_COMPAT > +#define PSTATE_IT_1_0_SHIFT 25 > +#define PSTATE_IT_1_0_MASK (0x3 << PSTATE_IT_1_0_SHIFT) > +#define PSTATE_IT_7_2_SHIFT 10 > +#define PSTATE_IT_7_2_MASK (0x3f << PSTATE_IT_7_2_SHIFT) > + > +static u32 compat_get_it_state(struct pt_regs *regs) > +{ > + u32 it, pstate = regs->pstate; > + > + it = (pstate & PSTATE_IT_1_0_MASK) >> PSTATE_IT_1_0_SHIFT; > + it |= ((pstate & PSTATE_IT_7_2_MASK) >> PSTATE_IT_7_2_SHIFT) << 2; > + > + return it; > +} > + > +static void compat_set_it_state(struct pt_regs *regs, u32 it) > +{ > + u32 pstate_it; > + > + pstate_it = (it << PSTATE_IT_1_0_SHIFT) & PSTATE_IT_1_0_MASK; > + pstate_it |= ((it >> 2) << PSTATE_IT_7_2_SHIFT) & PSTATE_IT_7_2_MASK; > + > + regs->pstate &= ~PSR_AA32_IT_MASK; > + regs->pstate |= pstate_it; > +} > + > +static void advance_itstate(struct pt_regs *regs) > +{ > + u32 it; > + > + /* ARM mode */ > + if (!(regs->pstate & PSR_AA32_T_BIT) || > + !(regs->pstate & PSR_AA32_IT_MASK)) > + return; > + > + it = compat_get_it_state(regs); > + > + /* > + * If this is the last instruction of the block, wipe the IT > + * state. Otherwise advance it. > + */ > + if (!(it & 7)) > + it = 0; > + else > + it = (it & 0xe0) | ((it << 1) & 0x1f); > + > + compat_set_it_state(regs, it); > +} > > void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) > { > @@ -285,7 +333,7 @@ void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) > if (user_mode(regs)) > user_fastforward_single_step(current); > > - if (regs->pstate & PSR_MODE32_BIT) > + if (compat_user_mode(regs)) > advance_itstate(regs); > } > > @@ -578,34 +626,6 @@ static const struct sys64_hook sys64_hooks[] = { > {}, > }; > > - > -#ifdef CONFIG_COMPAT > -#define PSTATE_IT_1_0_SHIFT 25 > -#define PSTATE_IT_1_0_MASK (0x3 << PSTATE_IT_1_0_SHIFT) > -#define PSTATE_IT_7_2_SHIFT 10 > -#define PSTATE_IT_7_2_MASK (0x3f << PSTATE_IT_7_2_SHIFT) > - > -static u32 compat_get_it_state(struct pt_regs *regs) > -{ > - u32 it, pstate = regs->pstate; > - > - it = (pstate & PSTATE_IT_1_0_MASK) >> PSTATE_IT_1_0_SHIFT; > - it |= ((pstate & PSTATE_IT_7_2_MASK) >> PSTATE_IT_7_2_SHIFT) << 2; > - > - return it; > -} > - > -static void compat_set_it_state(struct pt_regs *regs, u32 it) > -{ > - u32 pstate_it; > - > - pstate_it = (it << PSTATE_IT_1_0_SHIFT) & PSTATE_IT_1_0_MASK; > - pstate_it |= ((it >> 2) << PSTATE_IT_7_2_SHIFT) & PSTATE_IT_7_2_MASK; > - > - regs->pstate &= ~PSR_AA32_IT_MASK; > - regs->pstate |= pstate_it; > -} > - > static bool cp15_cond_valid(unsigned int esr, struct pt_regs *regs) > { > int cond; > @@ -626,29 +646,6 @@ static bool cp15_cond_valid(unsigned int esr, struct pt_regs *regs) > return aarch32_opcode_cond_checks[cond](regs->pstate); > } > > -static void advance_itstate(struct pt_regs *regs) > -{ > - u32 it; > - > - /* ARM mode */ > - if (!(regs->pstate & PSR_AA32_T_BIT) || > - !(regs->pstate & PSR_AA32_IT_MASK)) > - return; > - > - it = compat_get_it_state(regs); > - > - /* > - * If this is the last instruction of the block, wipe the IT > - * state. Otherwise advance it. > - */ > - if (!(it & 7)) > - it = 0; > - else > - it = (it & 0xe0) | ((it << 1) & 0x1f); > - > - compat_set_it_state(regs, it); > -} > - > static void compat_cntfrq_read_handler(unsigned int esr, struct pt_regs *regs) > { > int reg = (esr & ESR_ELx_CP15_32_ISS_RT_MASK) >> ESR_ELx_CP15_32_ISS_RT_SHIFT; > -- > 2.20.1 > -- Kees Cook