From patchwork Fri Jun 10 23:34:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12878198 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3CAFAC43334 for ; Fri, 10 Jun 2022 23:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=FRKyFrcqZpQ4pm7lo/90QqpGR9EFQ6qyAzXXp/zW36M=; b=ih4cpJB+1KDfwz+l2vu5x4IWCX k267Ws56UHnRzqA1gu71KQa8sFMfJVjASt6Xw3Svap3Ot8nmNEgkkqJspcSngR6ROiKsFQFPUvGFy Ywt2HBvY45OYW6+HYo8E7nN9i0JcUeqg43Tx6qDOfRN/UBjYN1XRjgDXFnHSbcCvjA0uHTaeOkELo G0k0eiCxGnpk6A7UVswSXkEQg9Coc8dfM76tyCr+02Oz/XI0S7qcNVxFIkU1qYLp9OFUSm3DFKYgJ eLc2Mcrx1KjS1GffETccsxo326xNBQCMHBE1N7mLEbKW5cQuX7pfc/9PctwCMjoqjtBhYQPUyDBct EmZ21PMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzoAm-00ARDI-FE; Fri, 10 Jun 2022 23:36:13 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzoA2-00AQpB-9b for linux-arm-kernel@lists.infradead.org; Fri, 10 Jun 2022 23:35:28 +0000 Received: by mail-pf1-x44a.google.com with SMTP id d15-20020aa7868f000000b0051c24cfebc0so283565pfo.13 for ; Fri, 10 Jun 2022 16:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=McmKeDfQU54OT2ddjesNbtVSHYxn5HOZJ/k/YIxSA2Q=; b=pKSmswC9i7CgIKNd8Ueb3Mz+6W8hfA6K3s8z6NmKiL9LavoDEDZ6LuI6xYKZyL/Qkr 160+qtQ1m3Pr4c4JAr7nYajwE1TSz/y2E1Rrx9U++y9J2+JSWlXRC5Nl3ytA7Ul5xzdO LISOUP2H04z2pfT/iuQxpK756TTuJdOX8Llgnt3mEUhHJ4JH2+YFORRQmfjqRsJn4Bha d2lJj5ycPYMuGuK+7809rBwk55D2MIZfdYbMtD+yfSi3pj5+WYVoynmFYFomThVrwt7o j7kMxaeyxnvLaVO3AbnVftP4ICSRzwZIOsIGKZKiAR/cybwHZ+1F8gwFFjHtiLh7Ahn2 MnjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=McmKeDfQU54OT2ddjesNbtVSHYxn5HOZJ/k/YIxSA2Q=; b=cA+T3u4sV9SHIJo82vlkCXUIRbMM1wNx5u2aziFi2vj+O+TFkh2tEI4AG8Yzydi7WE ZvZ93WFYMq0Z4g56wuelQCNiG2Az4utZBsV9yuddF2Yw2bZw7Wd0I1TLzZLQQ/rKOmJU +9WB/UenG68HEORDiz8YuwJAVBuSHJLMLJOlMgExYHV1DhSzbaDrW2C3WmGqXNS/1+W/ JHYy93V/RJoemY5MRksyAB8HhhFUz/ngURmQWTCWt0aUFGrQ+56vqkE7nsYkQeFndJmz OiWbdDt11aPhkWdB/CaRM5LDc6P5BgtCvIMZPb4wnD0o2VUFGfIkhUGIJyIOkTa5EjU2 CTDw== X-Gm-Message-State: AOAM530oBup26vvfetkBCprJk926WgsV4H2d9sIfhyFI7oWfpaS7LhRo chMguncT6Wjd7QkyG2ei5rlW9seyUsG0ceQwt7w= X-Google-Smtp-Source: ABdhPJwgQhAUrkZ2E3ncordFI1QLNbwk0KpIEhulvG6cFyGBziAQCqlrz6Jc+ed47AfAPj4RJHLMezGZqpWcUfbVd+4= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:f464:6db6:3d47:ed14]) (user=samitolvanen job=sendgmr) by 2002:a65:4149:0:b0:3fb:1476:d0dc with SMTP id x9-20020a654149000000b003fb1476d0dcmr41179133pgp.373.1654904124994; Fri, 10 Jun 2022 16:35:24 -0700 (PDT) Date: Fri, 10 Jun 2022 16:34:57 -0700 In-Reply-To: <20220610233513.1798771-1-samitolvanen@google.com> Message-Id: <20220610233513.1798771-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20220610233513.1798771-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3262; h=from:subject; bh=hbOGCW0Qi8kWOELjdrp8JGjjRWA8+I9n0fNulcEZcDg=; b=owEB7AET/pANAwAKAUy19oSLvFbuAcsmYgBio9UtgU/4jH18jloCAgXuwbucQRi4omU8/F8NLShQ oWKWan2JAbIEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYqPVLQAKCRBMtfaEi7xW7sBKC/ iex5GdKDqwH+DynVX5SiIJ/O/kBiCxebuuv+PRNnuuu5NP3jE7hyT+5F6E93ER1zUiBBK717u3FgLM L/KlhU6pU7G104AQ8tdX1EU7D34Q2YLaJaHJT0vOywEEKfCCVNO+h3Nx/jZ+PHXxg1QbXtXlSWqwD4 +/kvY1WrcT2i0BoLP1VvzxkSbZ3OIWtWezPEJtmHsP0Zy1M3HZLifJAwutTnmdIsdpv9vZQ68g8N1R S/V+L3L0LNtSorcPqo4u5nmqsCPPmIuNp+YSGzEHyyTivV/J+hlSsjueuuG+FneyECj2fZXlEwrptx UaYbxCmG+FVcXob7aFxve9hYP4mWfcFcfo7ktgXDRFpRdlXdFOIESUIV0VgVIUuD5GwLoCwcU7BXjp LBOlYl7jufqbE7cbRH0s3GrWLWgb9tXfwvkRiQYvNAsCxgZdDhOJu/Agg+kRH9qOBXZVA7xHUVh+3c PHYJe+YwgEv/MPvMx4VnjwfiMUUrjuw0CqB1kic5eKMA== X-Mailer: git-send-email 2.36.1.476.g0c4daa206d-goog Subject: [RFC PATCH v3 04/20] cfi: Drop __CFI_ADDRESSABLE From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_163526_375044_6973818C X-CRM114-Status: GOOD ( 15.02 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The __CFI_ADDRESSABLE macro is used for init_module and cleanup_module to ensure we have the address of the CFI jump table, and with CONFIG_X86_KERNEL_IBT to ensure LTO won't optimize away the symbols. As __CFI_ADDRESSABLE is no longer necessary with -fsanitize=kcfi, add a more flexible version of the __ADDRESSABLE macro and always ensure these symbols won't be dropped. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- include/linux/cfi.h | 20 -------------------- include/linux/compiler.h | 6 ++++-- include/linux/module.h | 4 ++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/include/linux/cfi.h b/include/linux/cfi.h index 4ab51c067007..2cdbc0fbd0ab 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -13,26 +13,6 @@ typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); /* Compiler-generated function in each module, and the kernel */ extern void __cfi_check(uint64_t id, void *ptr, void *diag); -/* - * Force the compiler to generate a CFI jump table entry for a function - * and store the jump table address to __cfi_jt_. - */ -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#else /* !CONFIG_CFI_CLANG */ - -#ifdef CONFIG_X86_KERNEL_IBT - -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#endif /* CONFIG_X86_KERNEL_IBT */ - #endif /* CONFIG_CFI_CLANG */ -#ifndef __CFI_ADDRESSABLE -#define __CFI_ADDRESSABLE(fn, __attr) -#endif - #endif /* _LINUX_CFI_H */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 01ce94b58b42..63be1c23d676 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -221,9 +221,11 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, * otherwise, or eliminated entirely due to lack of references that are * visible to the compiler. */ -#define __ADDRESSABLE(sym) \ - static void * __section(".discard.addressable") __used \ +#define ___ADDRESSABLE(sym, __attrs) \ + static void * __used __attrs \ __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym; +#define __ADDRESSABLE(sym) \ + ___ADDRESSABLE(sym, __section(".discard.addressable")) /** * offset_to_ptr - convert a relative memory offset to an absolute pointer diff --git a/include/linux/module.h b/include/linux/module.h index abd9fa916b7d..efecd65a976d 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -132,7 +132,7 @@ extern void cleanup_module(void); { return initfn; } \ int init_module(void) __copy(initfn) \ __attribute__((alias(#initfn))); \ - __CFI_ADDRESSABLE(init_module, __initdata); + ___ADDRESSABLE(init_module, __initdata); /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ @@ -140,7 +140,7 @@ extern void cleanup_module(void); { return exitfn; } \ void cleanup_module(void) __copy(exitfn) \ __attribute__((alias(#exitfn))); \ - __CFI_ADDRESSABLE(cleanup_module, __exitdata); + ___ADDRESSABLE(cleanup_module, __exitdata); #endif