Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4558398pxf; Tue, 23 Mar 2021 13:42:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBq+hFPnga44W3PSTSpOqrVbpuba9kw/lmMc5rUBmyfKjkNudcWVpawn4zBFJ7UZbvJSMz X-Received: by 2002:a17:907:3e9e:: with SMTP id hs30mr77915ejc.66.1616532122969; Tue, 23 Mar 2021 13:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616532122; cv=none; d=google.com; s=arc-20160816; b=Rj7qxCGit80AqogvM76CCPAyvLv+wkX5T1FRg3ReZNneryyvFvirvoM5ZdbFvZqJyM YQdvbfUlsOADn0h4ZlF0ZWSnTXDiAyvIuG5eGfYjvylpsDVBVDCAsxaLl0hONmf5uOY+ gq+qGz9Lq/Driioz9cVHMYbfE1CgDFsE36nKgtyzZrEz0/upIdGiyADep0NRZpXH41Rp aRb6RHjXLYqIAdE/svQMaTXERTqnAWU1LfbgoYp0TPQlntvf99U0b0K5cxW8F+A+YPf8 tVEQI1jQ8aABtbvM61Q7e09XusbZLvlMuSjx8CRyPCQLfn2aO1o8cBUw7WMZ2bqwsOtL cMag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=pXHCPErazdX/nDg2/nb6QksjLfEFTtrkU2uTHlahGRs=; b=YxwnG1QvPqe3wUcioQ3F8rOMewyfwfiCsaO3nST/zAEJNdA4Ji039ZLSJYWx2/jW7m OilN10Wr2tqm1klz/uSJA84FV9k0FtORBVDQCwUN6zfSBwHHkf6l8ubgJs2jvUr3hdpO RNPmlDe4qIh7bGF5QVPQlSxF8fUEKLf/gW9bmJMuuMEK4GABewnDG9tBatSJZM6QEmu6 RtSNxw4zGrFFaO/gOoabJXDwKvJbNxUMkO5rDkrZTGFu+kZOeY+mNOmfDzUc02F31Jf1 QxvZqxUN33AlOcY1P41e9ZTIkVrFZ+zU0wI00dnV8Cfxwqym33l7t1AzHrZx15QjXQTG tI5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jFt+TBSD; 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 f7si68593edu.503.2021.03.23.13.41.39; Tue, 23 Mar 2021 13:42:02 -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=jFt+TBSD; 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 S233698AbhCWUk6 (ORCPT + 99 others); Tue, 23 Mar 2021 16:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233528AbhCWUkM (ORCPT ); Tue, 23 Mar 2021 16:40:12 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B534FC0613DD for ; Tue, 23 Mar 2021 13:40:11 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i2so636859ybl.21 for ; Tue, 23 Mar 2021 13:40:11 -0700 (PDT) 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=pXHCPErazdX/nDg2/nb6QksjLfEFTtrkU2uTHlahGRs=; b=jFt+TBSDKrmbmcTGUS3Zh3LQfQ9h6g78j1z40AyKg7NaLPpZHn37Ldl7vtccRAf8UV GppokLpY6wTAB+Sle9DrxlzNvmD7RLVB1LrLtLP+DoPSdOHThcUhWPgZsZMHr1AypqJp 2ausF2iw7I06q65bPHkkK5uKHVdZZ+ckMEmm7IBf/pcXpGFOQXgKf2NyXu+UF4y2zTd2 ycqljJ06Wbbus0bG5F1C0bgOjXenQJWv7VPFmvmSNViXRdLRYpO43wanLsM7EnyPPUa4 y3y0OHiuMRejUijcBoHlT618Iy/tBMRleGTHHjCIOalK/zQVBqz//LPDgG2CS2s+wtjo u2Nw== 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=pXHCPErazdX/nDg2/nb6QksjLfEFTtrkU2uTHlahGRs=; b=V/Ln0UOW6fIonCu7M/wEQWyDcUWNZcIW2mwtwE5YCKWacK9Mx6wKtUqckAI7WDUHpo v4BIk6YpDm/QWq90JPXDuyn7MOqJr/0dg1H4rAzHFbwOLsD8XFYEx79KBhd4zNzfCBBY vEc7PzhEOHOsjlH2aw/9Ya3LXdTMFk8A5O3IUeeC54dekgPHGDOXm9m0BPEKJCDbQoXc tmeNu5hIIPaSlr66bpR+dn+o7vkPjXDB/nEA51Gi7NJnforDiFZP1HPTcP6YnuKQZT9u stNm8a6Pxr7AcgiehdGkS0o0zpZN1A72r620fOd61hLdRu2qdxQPiWIb6D+RbWTNUDgx MfiQ== X-Gm-Message-State: AOAM530cRIrrCLKq7Eb4iP5FNv1k44AUEO9CLGqmYFuW4pE3S05Mzdfl RHm60/DHuxAyQR9Pl/MC/0xeU1LpRwGw4WRWcTw= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:e9a3:260d:763b:67dc]) (user=samitolvanen job=sendgmr) by 2002:a25:d3d3:: with SMTP id e202mr58822ybf.283.1616532011040; Tue, 23 Mar 2021 13:40:11 -0700 (PDT) Date: Tue, 23 Mar 2021 13:39:41 -0700 In-Reply-To: <20210323203946.2159693-1-samitolvanen@google.com> Message-Id: <20210323203946.2159693-13-samitolvanen@google.com> Mime-Version: 1.0 References: <20210323203946.2159693-1-samitolvanen@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH v3 12/17] arm64: implement __va_function From: Sami Tolvanen To: Kees Cook Cc: Nathan Chancellor , Nick Desaulniers , Masahiro Yamada , Will Deacon , Jessica Yu , Arnd Bergmann , Tejun Heo , "Paul E. McKenney" , Christoph Hellwig , Peter Zijlstra , bpf@vger.kernel.org, linux-hardening@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kbuild@vger.kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Sami Tolvanen Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With CONFIG_CFI_CLANG, the compiler replaces function addresses in instrumented C code with jump table addresses. This change implements the __va_function() macro, which returns the actual function address instead. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- 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..9a4887808681 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 __va_function macro always returns the address of the + * actual function instead. + */ +#define __va_function(x) ({ \ + void *addr; \ + asm("adrp %0, " __stringify(x) "\n\t" \ + "add %0, %0, :lo12:" __stringify(x) : "=r" (addr)); \ + addr; \ +}) +#endif + /* * virt_to_page(x) convert a _valid_ virtual address to struct page * * virt_addr_valid(x) indicates whether a virtual address is valid -- 2.31.0.291.g576ba9dcdaf-goog