Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp439752pxf; Wed, 7 Apr 2021 03:25:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykAB2pr6vXZ1Q5nhKA00bQRs8Kq4ouOg6dqBZJbmTFo5Xgv269SvN++eXjrRXU6K/Wo7z3 X-Received: by 2002:a17:906:6b8c:: with SMTP id l12mr2810497ejr.511.1617791111638; Wed, 07 Apr 2021 03:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617791111; cv=none; d=google.com; s=arc-20160816; b=u7OzGS1UqUigLLYCHoiUKfqJUWLvOG7B4ruUkBI9N66yhHqQBu8KBAFbrQ6sKVBWjL 95y2icRuLwbO8NnjhfYRw4tUs5NdQy60b4ST826Pwap7TlYcD5e/tK8gL5edA9/jFDCh sgnvDkpFqy+EpACHPg0kwMsiB7OOOhtNNZlYBvXXxEHPcmFtz3iO0RLs+AN+a+SbVb6F rdKDJHhNIxdb1gwNHzPSEExYb/oXzIKx0P7IurLSJgwmczovd+O+b+5OOqrke0Hd2ZeL u9/jGhufgYAtwYWrkZoFzU7isLk1JpE25fO5lQ7yr1v4UhlfAEGgdq9E2auPWuG4Iw+C xTtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aSGe0bQ5V3W50ybbudz7bPErfQLcHAnbU3s+nR3236o=; b=ku87+gOgYgzg4D3HORZd5+nIVvaebiOqCVR1CFAzBeXBSY4FtvzJFvwjMWW1+KxAXB x21dKmf1hQbUpumJ4Ezlpk7aj37wIoeqnqFNR68cHEJ5LcmlEHFLwt5/nDJFAdgTvFI1 PqXjJ2eaVK9anOeF13StlzKjhaWsyTf/vyi0x7Gl8NyW70oSCkiU7IrFgoO+UQqB1p0H tjG7CN8/iGCl1ECM5sAdHxL/3AnAB7kry2A3Si+FJxCjNy6AZWosZZxRyVcBP/UwnKbh KvtIRw76Z2Vsk88Dq+JAv4+EF1aNha+h1DFU+VNcOvLSHPxsViM5/5AFA/wg/1hZBtNC rf0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NC4Z5tuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id j7si21206706ejm.492.2021.04.07.03.24.48; Wed, 07 Apr 2021 03:25:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=NC4Z5tuE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S240306AbhDFRDR (ORCPT + 99 others); Tue, 6 Apr 2021 13:03:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233320AbhDFRDQ (ORCPT ); Tue, 6 Apr 2021 13:03:16 -0400 Received: from mail-vs1-xe30.google.com (mail-vs1-xe30.google.com [IPv6:2607:f8b0:4864:20::e30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF1D7C06175F for ; Tue, 6 Apr 2021 10:03:08 -0700 (PDT) Received: by mail-vs1-xe30.google.com with SMTP id 66so3325319vsk.9 for ; Tue, 06 Apr 2021 10:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aSGe0bQ5V3W50ybbudz7bPErfQLcHAnbU3s+nR3236o=; b=NC4Z5tuEQPH56mSVdL6re/GYvhMXmcZBBZJAe0K5oARYXXzfmQy/y1gj01ihWMSmli 1Lb/UGbC8aKZb1zPEG9o6M9ucnwbSG6WIoA+FHAPLLbQ01uPDRIuyTwZIpAHLwOG+yq1 kkZI+8JMwHOnnEn+lyCTAlWm8etMOLtVCp3S1q3K3aO4yA/23/eH2gEXX6vdFz0CJGwN VF7c5vQJUcdiwYPAChJeB0X1E472u2faiMpy7Ui5DpvqvQTq4h26rGokMp0GpoEMI+P1 LV6JUbpNRzT8/BwmE+OHq/ZwSd4sY0JKeDMdURpYfRd1bJM30/6AX5SE7dZl6ySWo0EK KluA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aSGe0bQ5V3W50ybbudz7bPErfQLcHAnbU3s+nR3236o=; b=TJ/+R8zkD3InL+5qoelsX5D0IxiocSVs+0+3fQ5seAnloICSpMOvc3gJMB/EWmGWto voFxpxoPb95rXlgqMhX1e3D58PUhLGLLqCDbmSBkyfZ5q7z237zbn2URXcRsTjn9Wp/Q UkP8WLfKfO8ujJLeIxbziMAOlr9wrN5y4tjvZxPkpwNwihemLxUSgTlsX7HGyUD+DnIS h3oGVYpgtSJYSmyBGHyQzhEyI0tNrIxDs8Y3jV4vbyskjKD2ypOOuKCtQq+dNiSYDSq+ y5HOMJCTU0DRfpFd/Uaz/CIzxEv21B0W8OrG2oQxQbZEfdBvRMrr9OwDS6u75okbxirx 7Qkw== X-Gm-Message-State: AOAM530ysKdB4YAX1N6QtHYGUCZk8ZqgkjdUDWJUyWuLfXJ6+O2PLtLc ilutP0r85Z8lnsTh09ywpt6o9wV7oGnIrh49sxmiCQ== X-Received: by 2002:a05:6102:2423:: with SMTP id l3mr16985008vsi.54.1617728587679; Tue, 06 Apr 2021 10:03:07 -0700 (PDT) MIME-Version: 1.0 References: <20210401233216.2540591-1-samitolvanen@google.com> <20210401233216.2540591-13-samitolvanen@google.com> <20210406113657.GC96480@C02TD0UTHF1T.local> In-Reply-To: <20210406113657.GC96480@C02TD0UTHF1T.local> From: Sami Tolvanen Date: Tue, 6 Apr 2021 10:02:56 -0700 Message-ID: Subject: Re: [PATCH v5 12/18] arm64: implement function_nocfi To: Mark Rutland Cc: Kees Cook , Nathan Chancellor , Nick Desaulniers , Masahiro Yamada , Will Deacon , Jessica Yu , Arnd Bergmann , Tejun Heo , "Paul E. McKenney" , Christoph Hellwig , Peter Zijlstra , Sedat Dilek , Catalin Marinas , bpf , linux-hardening@vger.kernel.org, linux-arch , linux-arm-kernel , linux-kbuild , PCI , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 6, 2021 at 4:37 AM Mark Rutland wrote: > > On Thu, Apr 01, 2021 at 04:32:10PM -0700, Sami Tolvanen wrote: > > With CONFIG_CFI_CLANG, the compiler replaces function addresses in > > instrumented C code with jump table addresses. This change implements > > the function_nocfi() macro, which returns the actual function address > > instead. > > > > Signed-off-by: Sami Tolvanen > > Reviewed-by: Kees Cook > > I think that it's unfortunate that we have to drop to assembly here, but > given this is infrequent I agree it's not the end of the world, so: > > Acked-by: Mark Rutland > > > --- > > arch/arm64/include/asm/memory.h | 15 +++++++++++++++ > > 1 file changed, 15 insertions(+) > > > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > > index 0aabc3be9a75..b55410afd3d1 100644 > > --- a/arch/arm64/include/asm/memory.h > > +++ b/arch/arm64/include/asm/memory.h > > @@ -321,6 +321,21 @@ static inline void *phys_to_virt(phys_addr_t x) > > #define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x))) > > #define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x)) > > > > +#ifdef CONFIG_CFI_CLANG > > +/* > > + * With CONFIG_CFI_CLANG, the compiler replaces function address > > + * references with the address of the function's CFI jump table > > + * entry. The function_nocfi macro always returns the address of the > > + * actual function instead. > > + */ > > +#define function_nocfi(x) ({ \ > > + void *addr; \ > > + asm("adrp %0, " __stringify(x) "\n\t" \ > > + "add %0, %0, :lo12:" __stringify(x) : "=r" (addr)); \ > > If it's not too painful, could we please move the asm constrain onto its > own line? That makes it slightly easier to read, and aligns with what > we've (mostly) done elsewhere in arm64. Sure, I'll change this in the next version. > Not a big deal either way, and the ack stands regardless. > > Thanks, > Mark. Sami