From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-23.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47B03C43470 for ; Tue, 6 Apr 2021 17:03:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2436861040 for ; Tue, 6 Apr 2021 17:03:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244365AbhDFRDS (ORCPT ); Tue, 6 Apr 2021 13:03:18 -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-Google-Smtp-Source: ABdhPJxQSX0S7k4FzbEyhTnhHluxlT34cEUaV5NL9+ccGUPUJJazSLwY0K1+rikJtvM1UuMR3n/GOvlAUPSV1eX6hZs= 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CC6EC433ED for ; Tue, 6 Apr 2021 17:05:18 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5C8961074 for ; Tue, 6 Apr 2021 17:05:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5C8961074 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jrly5q5qhUJzWtY44F6JJ9ecjnP/fwYE55D/kmfmrXs=; b=Tv9iPnThAAg0w8SgrjmFm+gYo tIyxvQmpfQDL95sxCzcM3/G/hXee+Fny+0hwh+GWBERSAFQBt0sjC2WlXLFJtiQrgaHF08mhuhfYs iVQiW54RB8RtNrtSOoK4fDTnduYImQpenM46CgbRXeLWrev/ch9v6I9atx/slrkyz+5fmA4u93wyS fPFPiyI9s780eYs+TW0lPTKA1f9u7Y5ox6ycJHXeQEyBsklJKDYHu8MChl6i7BhmgJmVYrj9OE34K 7csDFiSCQYxOKkmG/ai2bKj1G2n/LwHLImOgjVktEi3Za9mUIdFb4gFbR9RBR7J2Fjpea7JMIpvUC gsQZOvc8A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lTp6p-0034MN-6e; Tue, 06 Apr 2021 17:03:23 +0000 Received: from mail-vs1-xe2e.google.com ([2607:f8b0:4864:20::e2e]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lTp6c-0034KH-A0 for linux-arm-kernel@lists.infradead.org; Tue, 06 Apr 2021 17:03:15 +0000 Received: by mail-vs1-xe2e.google.com with SMTP id u29so8146411vsi.12 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=JRbw7bE4n8sLKakdIn66rkaKLLae5K6Ir/y7Arl87WuXmbJT+i9CSZE53WgWkP8MN3 GCwKfyjSu23t+QKy8OPGRyi/uSxI2XPo6I9TAeU3J9QD+0nhzcm8z5dojHXMcXAyqT0O CLVsepPQm71XUPUy3uMXo9t9SRe9G66EIoh9uKDyMU3EUYK4Mwl06W6OjNWxx9kdjvLD BaPrU/WkzNHhE91G5YoLU/PT2wxPcWlDVQyFYaqq6VW0fVtC2H1NaY6GJmHj9PdTlfpI ElyDtEJ7sbJCw5HiBT47fCwH08wba/qlUbUMrsh6CvdgY2Ksf8YgoYnQJBM6a2P0wkB4 ZJEA== X-Gm-Message-State: AOAM532ty+d9xxd8ly3rqyjEwJnYuV0yWIaLZKZcbh8I9aDOD0AmSSno ZM35xgp4ijUK1G5FX17Ham6wJSQy2v8+Z9Q5FAwCwg== X-Google-Smtp-Source: ABdhPJxQSX0S7k4FzbEyhTnhHluxlT34cEUaV5NL9+ccGUPUJJazSLwY0K1+rikJtvM1UuMR3n/GOvlAUPSV1eX6hZs= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210406_180312_356053_FCABDF2D X-CRM114-Status: GOOD ( 26.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel