Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp6396846ybv; Tue, 18 Feb 2020 16:11:24 -0800 (PST) X-Google-Smtp-Source: APXvYqzKduPxNqKTuSDoIEOb3xvw5pqpMZ5Sw8/2JtymvunsBONO55W3VGrp1ZFVTmmC1cS1KqzZ X-Received: by 2002:aca:ab51:: with SMTP id u78mr2979662oie.21.1582071084220; Tue, 18 Feb 2020 16:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582071084; cv=none; d=google.com; s=arc-20160816; b=ji390yZv+sREKmwZocd7eJPqCxWUpCNmCbjZVw6Y9msKskYY/vpqX9kQW/Dz098hTr zlPxeumGJlOlhjA9HFJ9EEDlc/ddRfBxRunNNnheiGRM/iRkFZPMB9VAeT8jOs5QKwvP 19LcnLAbI3Rz6F9kogdlqjyrylOB4mCxf/IHa4L49SYZFElIyoszgMFpBX6dOvylwGYN JpfbkP/WP6CaSgT3yixFxTJnm5TV9HSYgFj5SPEIYBxNqkRSiYUTCPkOLuUWq2Zc8eYj a2wUvuxhZ/nrNVCqpGJSTml+kwaUwVbJxOV0g92Ks4lEXgFD/+z3nCsKVnY9OmBvzLol AEZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=QniVckAJWtqLmmFgAWqtQvDUqGmhiEDDkK5Atd0uI+w=; b=Gv4+plvRb9hg+8rSIGyB3l6/GuXdKURUmJj08TKMSGK+T7lMMLLmska5I9qohTlbAn z0sskJDzeRfwu05gcozOAmvISjieS02sMSfWPP0FwJmYFgt9JmnMhxZmTqGGH4RMQIMe bEpyO/PMp0DaEUBrEkfnWpDAOonvduk/4/uRtYTPpDgP+P7jVCeBKFbUWU8xVWK98P5M tnneYhB89uiLCX51DgyFMjNq4gRLwvraLtYlZcZE/ZrR8To5SaoghDMYQHy5rq4G3dm9 wgj+ZqImXNhbVjYq8TmqSNcpDPw0ZtcWosTW/wk9QZNcRGcLWkVfSlxTi3W3ya+2l2GW fWYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qufzpGjE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z10si8262995oic.77.2020.02.18.16.11.12; Tue, 18 Feb 2020 16:11:24 -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=@google.com header.s=20161025 header.b=qufzpGjE; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728023AbgBSAIx (ORCPT + 99 others); Tue, 18 Feb 2020 19:08:53 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:44434 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728008AbgBSAIw (ORCPT ); Tue, 18 Feb 2020 19:08:52 -0500 Received: by mail-pg1-f202.google.com with SMTP id o2so14859358pgj.11 for ; Tue, 18 Feb 2020 16:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QniVckAJWtqLmmFgAWqtQvDUqGmhiEDDkK5Atd0uI+w=; b=qufzpGjEppDMWPImhTuGEdGT5fSrkUOCFRhcyjZobkamDvVW8lKE7S9n8IfeI9kMjN GjSsbQERqiJCrQWg5+yur9ZmpwI3842rBfYePp5EboZsGV0A9NX4KJSaHBYX9WS8TV/B YxOPfKJb3HR14olUqNzIghumWLSF9JfupKrwhtKGLhHcH+iy/cZLakuxTBBKr3BSQC+Q l/d2gtUBVVI2+sDEnrXi83zlWZ5bO/OYVixaPN92nFcUWQ3ZPH+WoaCJq/ch+3VstHjI DDMR+HT+E10IhOJZsyS+YJ4gi2CPv7gIBX5icVylNk3GYCOKGpIchxJrvY+jCKqp3YLe pYjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QniVckAJWtqLmmFgAWqtQvDUqGmhiEDDkK5Atd0uI+w=; b=gD1EbNdmSN3xdDALYMYu0SkdBUjchQH+FAHRIofJxFzLYHGNI0fus/t1RtKDi1uiRV QVbAuTkPf7tRtjzmnT1TybQWcHesuYeeXxs3mbl6c2XHX/n0De8TPGGTgG9ua7XzGrwR Gollb8GZ2Fhv/h9mfwZmqBF9hd5Pcoi2oEZvb7AuY9/mbu+JbqjHELCAh3azwIs4a3P1 3zRdfm2VBVti2SCSzwiASHIrjeQFCZaXrP907ZmKnZZNnax1Ct/g1+e/NCOszAlLM6is uxmLCloIn+/rgWMUv+rjLB5NYevAal/Y/QH8pHXoCRbboKdcHd6RDRHiM8KGkTg/jNEW humw== X-Gm-Message-State: APjAAAWGELITEMPyrLwKzbTMPwtZWRWtBomQZQhWVbCvENa05j1A4DH+ froERjo6Rg7oUsI9cdpy/c9Yan5sZMIc9BGnBUM= X-Received: by 2002:a63:bc02:: with SMTP id q2mr24517139pge.174.1582070930907; Tue, 18 Feb 2020 16:08:50 -0800 (PST) Date: Tue, 18 Feb 2020 16:08:12 -0800 In-Reply-To: <20200219000817.195049-1-samitolvanen@google.com> Message-Id: <20200219000817.195049-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20191018161033.261971-1-samitolvanen@google.com> <20200219000817.195049-1-samitolvanen@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v8 07/12] arm64: efi: restore x18 if it was corrupted From: Sami Tolvanen To: Will Deacon , Catalin Marinas , Steven Rostedt , Masami Hiramatsu , Ard Biesheuvel , Mark Rutland , james.morse@arm.com Cc: Dave Martin , Kees Cook , Laura Abbott , Marc Zyngier , Nick Desaulniers , Jann Horn , Miguel Ojeda , Masahiro Yamada , clang-built-linux@googlegroups.com, kernel-hardening@lists.openwall.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If we detect a corrupted x18, restore the register before jumping back to potentially SCS instrumented code. This is safe, because the wrapper is called with preemption disabled and a separate shadow stack is used for interrupt handling. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Acked-by: Will Deacon --- arch/arm64/kernel/efi-rt-wrapper.S | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/efi-rt-wrapper.S b/arch/arm64/kernel/efi-rt-wrapper.S index 3fc71106cb2b..6ca6c0dc11a1 100644 --- a/arch/arm64/kernel/efi-rt-wrapper.S +++ b/arch/arm64/kernel/efi-rt-wrapper.S @@ -34,5 +34,14 @@ ENTRY(__efi_rt_asm_wrapper) ldp x29, x30, [sp], #32 b.ne 0f ret -0: b efi_handle_corrupted_x18 // tail call +0: + /* + * With CONFIG_SHADOW_CALL_STACK, the kernel uses x18 to store a + * shadow stack pointer, which we need to restore before returning to + * potentially instrumented code. This is safe because the wrapper is + * called with preemption disabled and a separate shadow stack is used + * for interrupts. + */ + mov x18, x2 + b efi_handle_corrupted_x18 // tail call ENDPROC(__efi_rt_asm_wrapper) -- 2.25.0.265.gbab2e86ba0-goog