Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp312598ybf; Wed, 26 Feb 2020 13:41:51 -0800 (PST) X-Google-Smtp-Source: APXvYqwbqdtVYR7vpO/4QIjU7vG0TVLXVcz3T1ipMRcJl5tgpUUYwJzj9SrAC6tXPltBewT0pxIn X-Received: by 2002:a9d:7e99:: with SMTP id m25mr690129otp.212.1582753311159; Wed, 26 Feb 2020 13:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582753311; cv=none; d=google.com; s=arc-20160816; b=P6eJxE5l03jE9L74k1OiVaUjMJeNEScAW4lUwy52TMZVjPBxj4oo8avpg+fGVOgQLj mqbOHWR6X1kH8jEWn0EYsCILokbRGQZR1Z7i2TxOdY9VREdRzYsRybdG8dSxGVEUKAxk 9AWfJbGNM9JGC7a/P3k6AUm+OJZiUfz+bZbFpI9NxkdpQVe0is2GdxmVkCeCvNL3UnlQ HdLFV3TS0LbKxtgtqRVI9wx2YwbKlflqx9AIi0GUOkF0IMvTGON2DmF+FIA5Qlj1t1Pd m+Gm5XUjPVFwswH4N38LH+BYNF6MGF9mCuBEy/Ix9T4lw0Iu+aaRGrwX2k3Mu2agdtuF lgmA== 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=wf+hQg66hhCzpMAXWHM+HuBnD6U1j60tq45EYdsucCI=; b=OQHI/yiSN01Z5/ULzWwoyGek6G9Kkw0HdCvbBAQIOlMFmKSuG6vMA0d3t4mA7iWV7j DkRPPYD5UFmi3jy+oMh6UZ8dxmoHaswxj9NG7wNn+Eh0+Lmr1aMjFIi0wXFOkvGwe2Z5 bzGO5I5MBI/vLd6e4B/2VTJaTK8rOQTB2D6qywosEv9SXiJG+IJBW0Q/BRVgYl2zEimi 4/n4YYmJTA2JCVtc9xfPCodxEIEvP4m7C9YOOFXVl2QQzKt9okryF0+ossX/VTWhxonF 4NL4ynTK/b8f1MDQCjcP4fo1Hsr+GdpqjfQ8yCyWY7/+S7rGIihjQ/ghwJWLSNtpxau/ 7LrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mKb208fd; 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 z2si253925oix.100.2020.02.26.13.41.39; Wed, 26 Feb 2020 13:41:51 -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=mKb208fd; 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 S1727803AbgBZVlV (ORCPT + 99 others); Wed, 26 Feb 2020 16:41:21 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:41103 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727581AbgBZVlV (ORCPT ); Wed, 26 Feb 2020 16:41:21 -0500 Received: by mail-pl1-f193.google.com with SMTP id t14so218775plr.8 for ; Wed, 26 Feb 2020 13:41:20 -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=wf+hQg66hhCzpMAXWHM+HuBnD6U1j60tq45EYdsucCI=; b=mKb208fdH4VjrwAPiQEKqixvPOAB9C95cgTfKiEVpaRU9pMoAh2U424X2d1KOS351h v3QCIIUBYYnbICJoZx66ooI34HW+uVxKVR5ZWT6qVHHx9+aGuRZ8VDIMeA/2CqbHpdlI OGf1aiGEA7cFYbwiUUymDfbs0m5xFpVfrYVAc= 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=wf+hQg66hhCzpMAXWHM+HuBnD6U1j60tq45EYdsucCI=; b=WO72VcxvYpJkZ6C5rgBcrgqjtJKQqMmLQtgRIj71c6ZTb7aj5iL2KMIYpCv90EqtuF E6yS1bzu3PtYg/CCfcdMSb8yKVdRyAFMXB7fNtUIAujobEjMAhIgJumQTmzGy7Y903bc UW1DusxVCYvGrwwJyXboQbWhCYJvPGsMTpbzOSk1aREubqM22bgieEGycikLCxfmjIZr bE7b1qinPE+6OMzGKGTSJMnmbAWM4/q9z8maGz738d7U3RuDCkJvYb4vMG/WJT9KpNda MojUMkPkaFLX/8kNv2neXbX3unT6HnVkbV5G3RCvZhKBOUz4MJbfiWHLSnJ8gBsP9VKJ rsRA== X-Gm-Message-State: APjAAAWH8OehRE+jWzlZsIZ/B8MLSRFABks+KqblOoTfnDDeyQIfqSGS Wv/l4hZy9vW7Fx65nQ0GPZvHjA== X-Received: by 2002:a17:90a:fa8d:: with SMTP id cu13mr1177001pjb.68.1582753280049; Wed, 26 Feb 2020 13:41:20 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id g7sm4283587pfq.33.2020.02.26.13.41.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 13:41:19 -0800 (PST) Date: Wed, 26 Feb 2020 13:41:18 -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 , Mark Rutland Subject: Re: [PATCH v7 07/11] arm64: unify native/compat instruction skipping Message-ID: <202002261341.17C9BC2222@keescook> References: <20200226155714.43937-1-broonie@kernel.org> <20200226155714.43937-8-broonie@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226155714.43937-8-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:10PM +0000, Mark Brown wrote: > From: Dave Martin > > Skipping of an instruction on AArch32 works a bit differently from > AArch64, mainly due to the different CPSR/PSTATE semantics. > > Currently arm64_skip_faulting_instruction() is only suitable for > AArch64, and arm64_compat_skip_faulting_instruction() handles the IT > state machine but is local to traps.c. > > Since manual instruction skipping implies a trap, it's a relatively > slow path. > > So, make arm64_skip_faulting_instruction() handle both compat and > native, and get rid of the arm64_compat_skip_faulting_instruction() > special case. > > Signed-off-by: Dave Martin Reviewed-by: Kees Cook -Kees > Reviewed-by: Mark Rutland > Signed-off-by: Mark Brown > --- > arch/arm64/kernel/traps.c | 18 ++++++++---------- > 1 file changed, 8 insertions(+), 10 deletions(-) > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index b8c714dda851..bc9f4292bfc3 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -272,6 +272,8 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, > } > } > > +static void advance_itstate(struct pt_regs *regs); > + > void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) > { > regs->pc += size; > @@ -282,6 +284,9 @@ 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) > + advance_itstate(regs); > } > > static LIST_HEAD(undef_hook); > @@ -644,19 +649,12 @@ static void advance_itstate(struct pt_regs *regs) > compat_set_it_state(regs, it); > } > > -static void arm64_compat_skip_faulting_instruction(struct pt_regs *regs, > - unsigned int sz) > -{ > - advance_itstate(regs); > - arm64_skip_faulting_instruction(regs, sz); > -} > - > 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; > > pt_regs_write_reg(regs, reg, arch_timer_get_rate()); > - arm64_compat_skip_faulting_instruction(regs, 4); > + arm64_skip_faulting_instruction(regs, 4); > } > > static const struct sys64_hook cp15_32_hooks[] = { > @@ -676,7 +674,7 @@ static void compat_cntvct_read_handler(unsigned int esr, struct pt_regs *regs) > > pt_regs_write_reg(regs, rt, lower_32_bits(val)); > pt_regs_write_reg(regs, rt2, upper_32_bits(val)); > - arm64_compat_skip_faulting_instruction(regs, 4); > + arm64_skip_faulting_instruction(regs, 4); > } > > static const struct sys64_hook cp15_64_hooks[] = { > @@ -697,7 +695,7 @@ void do_cp15instr(unsigned int esr, struct pt_regs *regs) > * There is no T16 variant of a CP access, so we > * always advance PC by 4 bytes. > */ > - arm64_compat_skip_faulting_instruction(regs, 4); > + arm64_skip_faulting_instruction(regs, 4); > return; > } > > -- > 2.20.1 > -- Kees Cook