From patchwork Thu Sep 30 18:05:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537983 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13255C433FE for ; Thu, 30 Sep 2021 18:05:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9055619F9 for ; Thu, 30 Sep 2021 18:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353045AbhI3SHW (ORCPT ); Thu, 30 Sep 2021 14:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353040AbhI3SHU (ORCPT ); Thu, 30 Sep 2021 14:07:20 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8563C06176A for ; Thu, 30 Sep 2021 11:05:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id b9-20020a5b07890000b0290558245b7eabso9566873ybq.10 for ; Thu, 30 Sep 2021 11:05:37 -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=2Bgjsb/aFIkQSrBisCHUYv6SIuQmEnOivW87M1Xcmdk=; b=s0beKCqxZCrTzjfSpjjhqmcXy69zfpSvJZh6o5GNgcM7uZ+AeqtB2GWSr7r195f1rK VZ/B+6UwrM+mpMRnK9345tRnKs/YgbEAZ9eOsJNJfk6wUEJ90MUZV+kfc3tj4eTaxLOa kXHyqrh0xzdYEclp3Nm6OAFz0RjI/UPdG/tI8wpaG6YAY0EO/TCH4wUmOFDrXfj7t5Fz lsuvqjkL7pjJ/SIX0nrZVGPhr1o7LWxyJR++PqBbXm1Nz8UhjtglXISZqOi6H+M5mqkg nkK6xeNJ2N4Ikm9NMPJx3jXCpgZd7KGG1eIiwC3+fClS8JUDOLOX1Bo3z7R6uQLhFRFK YrdA== 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=2Bgjsb/aFIkQSrBisCHUYv6SIuQmEnOivW87M1Xcmdk=; b=rg/FeYTTG0ytHYQFTvTBuit02E8OvflCQjIJq48W01D1iNhqMZUNHYEfwltvrAbc/1 mCXF0qxa6Ty/oaV87IyNxa6T4J1zvis4kowsq+g4y/qG+6TxmtAzh/50ue9ghuTPrH7k uxopqDIOWCQI40+cDgt2efE7m3+ev8AyGFpGZTCIUwBd0bbDLVdJOxLBS55ScLlbVy1o yHN8Kqa/aPVnVhGwH2ceigdTLy/YrSmONEMiC04vlRqj7hb+zuagKJ5NCg+Q73Mg+WIj HaRbi0rbBbwy+jm0cK+Qrx9p07IwUx7wt/gwpP0ZnKZnctyhdfbSNCqv2HncQnXS98Ox lF0Q== X-Gm-Message-State: AOAM533ptz6h8XZwSP0dnHYzRTBQu8zwLik3UUXdUyS2fii8O0HaWW2W TcdyFGn4vJscapzQY9hp7qrqOoi4+KLH6wBPy1Y= X-Google-Smtp-Source: ABdhPJwMUV55QPso5VdV9CHYlDd3r2gw61pUnbXkeOQ8hmaSknJheUch0PSQN+nbLOJkSRKUdHc28TAc0FWFceGTOrI= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a5b:1c4:: with SMTP id f4mr677911ybp.47.1633025137173; Thu, 30 Sep 2021 11:05:37 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:17 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-2-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 01/15] objtool: Add CONFIG_CFI_CLANG support From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org With CONFIG_CFI_CLANG, the compiler replaces function references with references to the CFI jump table, which confuses objtool. This change, based on Josh's initial patch [1], goes through the list of relocations and replaces jump table symbols with the actual function symbols. [1] https://lore.kernel.org/r/d743f4b36e120c06506567a9f87a062ae03da47f.1611263462.git.jpoimboe@redhat.com/ Reported-by: Sedat Dilek Suggested-by: Josh Poimboeuf Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers --- tools/objtool/arch/x86/decode.c | 17 ++++++++++ tools/objtool/elf.c | 51 ++++++++++++++++++++++++++++ tools/objtool/include/objtool/arch.h | 3 ++ tools/objtool/include/objtool/elf.h | 2 +- 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decode.c index 3172983bf808..9b043220b0af 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -63,6 +63,23 @@ bool arch_callee_saved_reg(unsigned char reg) } } +unsigned long arch_cfi_section_reloc_offset(struct reloc *reloc) +{ + if (!reloc->addend) + return 0; + + if (reloc->type == R_X86_64_PC32 || reloc->type == R_X86_64_PLT32) + return reloc->addend + 4; + + return reloc->addend; +} + +unsigned long arch_cfi_jump_reloc_offset(unsigned long offset) +{ + /* offset to the relocation in a jmp instruction */ + return offset + 1; +} + unsigned long arch_dest_reloc_offset(int addend) { return addend + 4; diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 8676c7598728..05a5f51aad2c 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -291,6 +292,10 @@ static int read_sections(struct elf *elf) if (sec->sh.sh_flags & SHF_EXECINSTR) elf->text_size += sec->len; + /* Detect -fsanitize=cfi jump table sections */ + if (!strncmp(sec->name, ".text..L.cfi.jumptable", 22)) + sec->cfi_jt = true; + list_add_tail(&sec->list, &elf->sections); elf_hash_add(section, &sec->hash, sec->idx); elf_hash_add(section_name, &sec->name_hash, str_hash(sec->name)); @@ -576,6 +581,49 @@ static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc, unsi return 0; } +/* + * CONFIG_CFI_CLANG replaces function relocations to refer to an intermediate + * jump table. Undo the conversion so objtool can make sense of things. + */ +static int fix_cfi_relocs(const struct elf *elf) +{ + struct section *sec; + struct reloc *reloc; + + list_for_each_entry(sec, &elf->sections, list) { + list_for_each_entry(reloc, &sec->reloc_list, list) { + struct reloc *cfi_reloc; + unsigned long offset; + + if (!reloc->sym->sec->cfi_jt) + continue; + + if (reloc->sym->type == STT_SECTION) + offset = arch_cfi_section_reloc_offset(reloc); + else + offset = reloc->sym->offset; + + /* + * The jump table immediately jumps to the actual function, + * so look up the relocation there. + */ + offset = arch_cfi_jump_reloc_offset(offset); + cfi_reloc = find_reloc_by_dest(elf, reloc->sym->sec, offset); + + if (!cfi_reloc || !cfi_reloc->sym) { + WARN("can't find a CFI jump table relocation at %s+0x%lx", + reloc->sym->sec->name, offset); + return -1; + } + + reloc->sym = cfi_reloc->sym; + reloc->addend = 0; + } + } + + return 0; +} + static int read_relocs(struct elf *elf) { struct section *sec; @@ -639,6 +687,9 @@ static int read_relocs(struct elf *elf) tot_reloc += nr_reloc; } + if (fix_cfi_relocs(elf)) + return -1; + if (stats) { printf("max_reloc: %lu\n", max_reloc); printf("tot_reloc: %lu\n", tot_reloc); diff --git a/tools/objtool/include/objtool/arch.h b/tools/objtool/include/objtool/arch.h index 589ff58426ab..93bde8aaf2e3 100644 --- a/tools/objtool/include/objtool/arch.h +++ b/tools/objtool/include/objtool/arch.h @@ -81,6 +81,9 @@ unsigned long arch_jump_destination(struct instruction *insn); unsigned long arch_dest_reloc_offset(int addend); +unsigned long arch_cfi_section_reloc_offset(struct reloc *reloc); +unsigned long arch_cfi_jump_reloc_offset(unsigned long offset); + const char *arch_nop_insn(int len); const char *arch_ret_insn(int len); diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index c3857fadee7a..e8d838217c77 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -39,7 +39,7 @@ struct section { char *name; int idx; unsigned int len; - bool changed, text, rodata, noinstr; + bool changed, text, rodata, noinstr, cfi_jt; }; struct symbol { From patchwork Thu Sep 30 18:05:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537985 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADFE0C433FE for ; Thu, 30 Sep 2021 18:05:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9415D61A05 for ; Thu, 30 Sep 2021 18:05:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353048AbhI3SHY (ORCPT ); Thu, 30 Sep 2021 14:07:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353054AbhI3SHX (ORCPT ); Thu, 30 Sep 2021 14:07:23 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B285C06176A for ; Thu, 30 Sep 2021 11:05:40 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id m1-20020a05620a290100b0045e5e0b11e6so14220049qkp.23 for ; Thu, 30 Sep 2021 11:05:40 -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=yAjbLnc/4a+xG0iJA7167YzRctoMe7iQs3Th7exl8y0=; b=SvlcxRI3GX2nd8j9Q0bgxfBDF3ydh6ydlHg7K7EZljsvTET8asCVHOloFKQ7TRijza vN0HjN5JaVANlUkWbGRwoLqyCgaugjgFLtXJHICFTckU6s8u5Nw3D5IRqZLMoisvtJT2 lwK7V/I2GkKyyR8M8zIipdubdj0hm5i89gRWQrdBh2hPr2MdTtfMRvAeGSHtTIvOdIhf ZgQHGgegg2kyvZYqJy9o/zJ24gjETr43HBOkQdJxZ72YKuNL5hp0p+5Nx8/E20tIzHQZ 64R8fZAjx4IFoTPSPIENZysfkgVYoNGXhh3++DuTcKc8F+NymV7l7WKLPlMjk4zfml8u QopA== 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=yAjbLnc/4a+xG0iJA7167YzRctoMe7iQs3Th7exl8y0=; b=dFHGot7eoqQ9y9nXpoPDmQrLEG+XayvL81ieiZIUCRVjqZW310NHwqPuGqkVlcQaxu iCdI8NEjag7vxMkl/mBr5lVNmTK6NwyXTYJLo/AptKGTocZBzFRhZznW6I/thF4+M4/L I++GBi1JSLGldLX3L3vsu6eoOq0qKbwC4IPMvOO+buRXgdhuSB8shn4J32Z0rRMVmgJ4 ctb94B1k+ZuczzFJQRtfkKf4Nq5g3r7l05zts2HeXO1KK1TS9WjYxGBKP4hAiY5v6IHs /ro0DzQNh5MnXOFZamMe1M0Lbp/DBB8onHFHs9O06lrlgNf2YI0DGn01PNuA/og6MPZ+ aV8A== X-Gm-Message-State: AOAM533MTN2hCeYo86qNKxFIbdIHSisVbnTzAkd7VDsrIRBFNBhmzXHs RrMJwv0aO1ePBzAiJ3Zc3XuZz89bdtiZIde0Jww= X-Google-Smtp-Source: ABdhPJzSSSnwMdWUnZcSCWxApNcxtPczjvh4ogkn8fqf5fL6TvlzIOJjfdSg+b9xxcs7cfAmBGB0tTMcLHwNPjr9GOk= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a0c:9d05:: with SMTP id m5mr5140529qvf.30.1633025139519; Thu, 30 Sep 2021 11:05:39 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:18 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-3-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 02/15] objtool: Add ASM_STACK_FRAME_NON_STANDARD From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org To use the STACK_FRAME_NON_STANDARD macro for a static symbol defined in inline assembly, we need a C declaration that implies global visibility. This type mismatch confuses the compiler with CONFIG_CFI_CLANG. This change adds an inline assembly version of the macro to avoid the issue. Signed-off-by: Sami Tolvanen Acked-by: Josh Poimboeuf --- include/linux/objtool.h | 6 ++++++ tools/include/linux/objtool.h | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/objtool.h b/include/linux/objtool.h index 7e72d975cb76..080e95174536 100644 --- a/include/linux/objtool.h +++ b/include/linux/objtool.h @@ -66,6 +66,11 @@ struct unwind_hint { static void __used __section(".discard.func_stack_frame_non_standard") \ *__func_stack_frame_non_standard_##func = func +#define ASM_STACK_FRAME_NON_STANDARD(func) \ + ".pushsection .discard.func_stack_frame_non_standard, \"aw\"\n" \ + ".long " __stringify(func) " - .\n" \ + ".popsection\n" + #else /* __ASSEMBLY__ */ /* @@ -127,6 +132,7 @@ struct unwind_hint { #define UNWIND_HINT(sp_reg, sp_offset, type, end) \ "\n\t" #define STACK_FRAME_NON_STANDARD(func) +#define ASM_STACK_FRAME_NON_STANDARD(func) #else #define ANNOTATE_INTRA_FUNCTION_CALL .macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 diff --git a/tools/include/linux/objtool.h b/tools/include/linux/objtool.h index 7e72d975cb76..080e95174536 100644 --- a/tools/include/linux/objtool.h +++ b/tools/include/linux/objtool.h @@ -66,6 +66,11 @@ struct unwind_hint { static void __used __section(".discard.func_stack_frame_non_standard") \ *__func_stack_frame_non_standard_##func = func +#define ASM_STACK_FRAME_NON_STANDARD(func) \ + ".pushsection .discard.func_stack_frame_non_standard, \"aw\"\n" \ + ".long " __stringify(func) " - .\n" \ + ".popsection\n" + #else /* __ASSEMBLY__ */ /* @@ -127,6 +132,7 @@ struct unwind_hint { #define UNWIND_HINT(sp_reg, sp_offset, type, end) \ "\n\t" #define STACK_FRAME_NON_STANDARD(func) +#define ASM_STACK_FRAME_NON_STANDARD(func) #else #define ANNOTATE_INTRA_FUNCTION_CALL .macro UNWIND_HINT sp_reg:req sp_offset=0 type:req end=0 From patchwork Thu Sep 30 18:05:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537987 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8D5FC433FE for ; Thu, 30 Sep 2021 18:05:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FC2361A02 for ; Thu, 30 Sep 2021 18:05:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353066AbhI3SH0 (ORCPT ); Thu, 30 Sep 2021 14:07:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353062AbhI3SHZ (ORCPT ); Thu, 30 Sep 2021 14:07:25 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE76C06176F for ; Thu, 30 Sep 2021 11:05:42 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id q9-20020ad45749000000b00382b7c83aa1so31659qvx.11 for ; Thu, 30 Sep 2021 11:05:42 -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=7QsELX2b4zYjlGgyKK6SovhZ4mE+qI9YjYk7qrPU0wo=; b=U3ToAP/4F0z7c/GCezlIqVZAyjDQl9Undff00n8rJGZDjq+07eqdViNINuCfWY1gAV unl0hcnz0BXbOBcy4UqMjtpy6qawy4EcwcORy+8OW1ACvyXXa6zNSchJ1AgtSuMiyhci A2Rb3gS4n1GsjAdz8QP0qRZXZlN7W5YcVoEHpCHtWmD7vAunZfgv5OLov4Y4ncEh1Feb 8FI5yhThK1PcJDaedcnZ0vKjLy0BIpS4W/lszSEK1gEaPNiwNcDLMreQ6kvO28TkAnOW hUXG+aiWaZ407Veb2EEYZn3WXY1mJv3sZVnKlxe3E/7bfH5npygUexLcxyON5o7gD53g m+Kw== 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=7QsELX2b4zYjlGgyKK6SovhZ4mE+qI9YjYk7qrPU0wo=; b=L+XCIREFPg+CM4eK67X3Ls9AEW1pXaEsmVaKa44rHiPMg9VydzZ8VFV3ZuACIUkXoW VFM56E40CXF4cHu+ZG7JJ5WsU6r1cLgfPcJo62gcXAUpVJMox/wMV0hR2idaXrBW3xla aj7OaBvaM+hYluSmgulhSWgWtZsuk0n+gDqjVR8SS1Sn/CpyrTGZHF7GOarF3+3zIR7A Kj5BThNFN9aUe1O4Bj8I9c1dPmhqcS4yiXqFd8gcsolakltOX5Oh5jc1gk8GIU4TPTGY XuJQ97CXmjVmlqiqrrU4FVSUcDj4M0H9rimrYVMe5Vjib1rhGu+HD4o3uZHwb3Fh87tB Mjlg== X-Gm-Message-State: AOAM533gVigMvsHa3cavQuVI0K0BZ1TXpCrRmVHFkZ5rTn3/vAHkws39 kc134zuPotiogt6pWIw+4xaFulH+U7nTAFwk4gY= X-Google-Smtp-Source: ABdhPJx2qfURfbEwyFW4qktv+A5fIlkTLMCqBZahUPc77DrDAO6ToNYtooGeOAIl80LkI4WjSBoXazOHhIJ3TSe3qUs= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a05:6214:1c8d:: with SMTP id ib13mr81485qvb.10.1633025141843; Thu, 30 Sep 2021 11:05:41 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:19 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 03/15] linkage: Add DECLARE_ASM_FUNC_SYMBOL From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org The kernel has several assembly functions, which are not directly callable from C but need to be referred to from C code. This change adds the DECLARE_ASM_FUNC_SYMBOL macro, which allows us to declare these symbols using an opaque type, which makes misuse harder, and avoids the need to annotate references to the functions for Clang's Control-Flow Integrity (CFI). Suggested-by: Andy Lutomirski Signed-off-by: Sami Tolvanen --- include/linux/linkage.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/linkage.h b/include/linux/linkage.h index dbf8506decca..f1eac26b2dd6 100644 --- a/include/linux/linkage.h +++ b/include/linux/linkage.h @@ -48,6 +48,19 @@ #define __PAGE_ALIGNED_DATA .section ".data..page_aligned", "aw" #define __PAGE_ALIGNED_BSS .section ".bss..page_aligned", "aw" +/* + * Declares a function not callable from C using an opaque type. Defined as + * an array to allow the address of the symbol to be taken without '&'. + */ +#ifndef DECLARE_ASM_FUNC_SYMBOL +#define DECLARE_ASM_FUNC_SYMBOL(sym) \ + extern const u8 sym[] +#endif + +#ifndef __ASSEMBLY__ +typedef const u8 *asm_func_ptr; +#endif + /* * This is used by architectures to keep arguments on the stack * untouched by the compiler by keeping them live until the end. From patchwork Thu Sep 30 18:05:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537989 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7977C433FE for ; Thu, 30 Sep 2021 18:05:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B07AB61A08 for ; Thu, 30 Sep 2021 18:05:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353056AbhI3SH2 (ORCPT ); Thu, 30 Sep 2021 14:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353061AbhI3SH1 (ORCPT ); Thu, 30 Sep 2021 14:07:27 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E86C06176C for ; Thu, 30 Sep 2021 11:05:44 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id bi20-20020a05620a319400b0045df2735d63so14321445qkb.2 for ; Thu, 30 Sep 2021 11:05:44 -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=UPn3WtDbLCsbJwfnPoAfGXnHgXkJDxwgkdwnBZu0rd0=; b=LRSomAQTsHguWWIKiMw9RL00G2RwUJwWty90kpxqVCwzfIlu+csku0f3xJTJ72BD6F yXJ22lD7BN8EYgnROAkXZRaywcWzJXpqzXsLDih1PLHbwhivOr2f+PMAriDNh+MUeZOP BCfzOtSkQg4k+23cBSVoFXCUxo1PKOZKKI6nLGtBCUmQM28BvI5ySpHt3V+xhHmaoVke y/8c5MuDXtIcVFOK0LYzBdy2v3gW9BnfQ+0YsarknLZGD87mbIzFlQUBx3V2C7uN5GWz aRkaAtBBlCAJ2TXIaBGq/HcSEJ6D+ZmZyUgAgCRMXr9MaU+Dhc5FMWM922utY0OBExHd LqCg== 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=UPn3WtDbLCsbJwfnPoAfGXnHgXkJDxwgkdwnBZu0rd0=; b=e7lYcSNvZbkMIyKCAijcmwtJi027ftc0DgHmMzdjqogqZtspv/8/KUuUvRIFjG165M dS1kBnKLhAfmKElFahYk4388G2L88LXP3XzKq06UJejPJaaLJSXTJBMuk0rSodgWoIjU PbfwINKauGSzHJJV4DGpUn3vP1MDIH2VhATFlt0D9ZHwx0DWlMgdAu0K4fufkNkDsfKU CgObHxetP6dijsVmhQi43PPzPSxrBkMw7cJCjIJJpaRWcpPcpgiTQBJtwxn9npUFjuUu sjDLjeiBqBhUaXYPa5ZTu8Lu93L53HhGEr9B0Ycyue/eNFFaurLXAlRT5hF3fWPEgfgG 893g== X-Gm-Message-State: AOAM532Z3qcMQohmGh4RBYqOPPl371+dDkVZ+WRZXi4GbGq5Wuxav4mI wSN6pQI8ELuBUMQcfRm9rn1mJiiQBf9WWbZcKQc= X-Google-Smtp-Source: ABdhPJyt+DoXC8M8wV+eSBDlDe6RpKid8twadzBUYb7JQ4nxap7WFvIXyFpTNj3EkS84jhtbCdxnm7bYEDsu1PiKEJk= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a0c:c189:: with SMTP id n9mr6585773qvh.5.1633025144137; Thu, 30 Sep 2021 11:05:44 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:20 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 04/15] cfi: Add DEFINE_CFI_IMMEDIATE_RETURN_STUB From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org This change introduces the DEFINE_CFI_IMMEDIATE_RETURN_STUB macro, which defines a stub function that immediately returns and when defined in the core kernel, always passes indirect call checking with CONFIG_CFI_CLANG. Note that this macro should only be used when a stub cannot be called using the correct function type. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers --- include/asm-generic/vmlinux.lds.h | 11 +++++++++++ include/linux/cfi.h | 13 +++++++++++++ kernel/cfi.c | 24 +++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index f2984af2b85b..5b77284f7221 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -407,6 +407,16 @@ KEEP(*(.static_call_tramp_key)) \ __stop_static_call_tramp_key = .; +#ifdef CONFIG_CFI_CLANG +#define CFI_EXCLUDED_DATA \ + . = ALIGN(8); \ + __start_cfi_excluded = .; \ + KEEP(*(.cfi_excluded_stubs)) \ + __stop_cfi_excluded = .; +#else +#define CFI_EXCLUDED_DATA +#endif + /* * Allow architectures to handle ro_after_init data on their * own by defining an empty RO_AFTER_INIT_DATA. @@ -430,6 +440,7 @@ __start_rodata = .; \ *(.rodata) *(.rodata.*) \ SCHED_DATA \ + CFI_EXCLUDED_DATA \ RO_AFTER_INIT_DATA /* Read only after init */ \ . = ALIGN(8); \ __start___tracepoints_ptrs = .; \ diff --git a/include/linux/cfi.h b/include/linux/cfi.h index 879744aaa6e0..19f74af8eac2 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -20,6 +20,17 @@ extern void __cfi_check(uint64_t id, void *ptr, void *diag); #define __CFI_ADDRESSABLE(fn, __attr) \ const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn +/* + * Defines a stub function that returns immediately, and when defined and + * referenced in the core kernel, always passes CFI checking. This should + * be used only for stubs that cannot be called using the correct function + * pointer type, which should be rare. + */ +#define DEFINE_CFI_IMMEDIATE_RETURN_STUB(fn) \ + void fn(void) { return; } \ + const void *__cfi_excl_ ## fn __visible \ + __section(".cfi_excluded_stubs") = (void *)&fn + #ifdef CONFIG_CFI_CLANG_SHADOW extern void cfi_module_add(struct module *mod, unsigned long base_addr); @@ -35,6 +46,8 @@ static inline void cfi_module_remove(struct module *mod, unsigned long base_addr #else /* !CONFIG_CFI_CLANG */ #define __CFI_ADDRESSABLE(fn, __attr) +#define DEFINE_CFI_IMMEDIATE_RETURN_STUB(fn) \ + void fn(void) { return; } #endif /* CONFIG_CFI_CLANG */ diff --git a/kernel/cfi.c b/kernel/cfi.c index 9594cfd1cf2c..8d931089141b 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -278,12 +278,34 @@ static inline cfi_check_fn find_module_check_fn(unsigned long ptr) return fn; } +extern unsigned long __start_cfi_excluded[]; +extern unsigned long __stop_cfi_excluded[]; + +static inline bool is_cfi_excluded(unsigned long ptr) +{ + unsigned long *p = __start_cfi_excluded; + + for ( ; p < __stop_cfi_excluded; ++p) + if (*p == ptr) + return true; + + return false; +} + +static void __cfi_pass(uint64_t id, void *ptr, void *diag) +{ +} + static inline cfi_check_fn find_check_fn(unsigned long ptr) { cfi_check_fn fn = NULL; - if (is_kernel_text(ptr)) + if (is_kernel_text(ptr)) { + if (unlikely(is_cfi_excluded(ptr))) + return __cfi_pass; + return __cfi_check; + } /* * Indirect call checks can happen when RCU is not watching. Both From patchwork Thu Sep 30 18:05:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537991 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7057C433EF for ; Thu, 30 Sep 2021 18:05:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AED73619F6 for ; Thu, 30 Sep 2021 18:05:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353105AbhI3SHf (ORCPT ); Thu, 30 Sep 2021 14:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353083AbhI3SHa (ORCPT ); Thu, 30 Sep 2021 14:07:30 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4A4DC061771 for ; Thu, 30 Sep 2021 11:05:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id f8-20020a2585480000b02905937897e3daso9678195ybn.2 for ; Thu, 30 Sep 2021 11:05:47 -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=+kIR6qTjG/q5eMITJU4my49cgyuaT1AvUzOJ+gtDnlg=; b=gkCn4CDHLNSjsTR7OqrAxG6q83amYoBjzRr52f4LFVrdFSlQ8WBZn3Kp+3hZbL0upx 4QgBEhfGWRMKKAB/Rg5nkWRPHjKEkG/A1Q1qhUvrWVXvLGMuMuBA65OpsS/tfbRK1pcp eZTHr+xF/PKqk0va5Z1T6QCYSxxDDVLojGTe6x4KArjInUM6eej4hO0563SYOBLYvQxu yxWiLR/GGIF9MjLLQ4I9iznSEWKsa3Wm0AcgJ7EcWRtashf7JTUQz/Fz45R7wS4Xruin N84Os+Y9Bz4ZPFcIAj4+J/A0L0R7xfD7qZl7197i2pE3AEJLLWz5uVkY+0dbWWm5rWpY CXAg== 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=+kIR6qTjG/q5eMITJU4my49cgyuaT1AvUzOJ+gtDnlg=; b=S5jggfYtxRtMKsU0MrszN6raS4ENext3hScQiBxiI54HESG0r7JA1/MTOXyok6AfQA 0cHH4la2AhKMU4ZfNVp465feTUf4wxvZ32JjPHkfQ0AMM9WQdyJb+/wS2JgdKfL7/Mek Rz9BwasD8osK8LbcJy5BURqCXK/6IaF7ZzEDhY2SBDQ4gvQn0AdGGfFUa9J3kCSCy38h vIJaAOjaqhoxtD+NRxHEgo4Ts3pA51NKXCWUOuwCXfB1q+8WcDn6U7rNpdMSaa2l0avX FpuXCoTS3V5AbiPDaSIH8KJ25li2aX25cVoF0imI3ier9zVPJ67fCQ/ruGjNzJPyawU7 Alcw== X-Gm-Message-State: AOAM5316VqzQGrI8lf11BqYIh3L+17Vb6a1S4lhetMgEBZTeGROHfxwJ 1zopkUBBW0L9m26rSGHOmNG0JX8Qq2Z08EpUzlo= X-Google-Smtp-Source: ABdhPJzeouRFzQrqqzPBJAENZtj4Ib+N4rD5s05tDGC56V66KMQtSgvl9JGoFrlez4rsmfK0wargeV1Nvuyh26mOOio= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a25:45c6:: with SMTP id s189mr689329yba.290.1633025146834; Thu, 30 Sep 2021 11:05:46 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:21 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-6-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 05/15] tracepoint: Exclude tp_stub_func from CFI checking From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org If allocate_probes fails, func_remove replaces the old function with a pointer to tp_stub_func, which is called using a mismatching function pointer that will always trip indirect call checks with CONFIG_CFI_CLANG. Use DEFINE_CFI_IMMEDATE_RETURN_STUB to define tp_stub_func to allow it to pass CFI checking. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers --- kernel/tracepoint.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index 64ea283f2f86..58acc7d86c3f 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -99,10 +99,7 @@ struct tp_probes { }; /* Called in removal of a func but failed to allocate a new tp_funcs */ -static void tp_stub_func(void) -{ - return; -} +static DEFINE_CFI_IMMEDIATE_RETURN_STUB(tp_stub_func); static inline void *allocate_probes(int count) { From patchwork Thu Sep 30 18:05:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537993 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E96F2C433F5 for ; Thu, 30 Sep 2021 18:05:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5A27615A2 for ; Thu, 30 Sep 2021 18:05:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353078AbhI3SHh (ORCPT ); Thu, 30 Sep 2021 14:07:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353072AbhI3SHe (ORCPT ); Thu, 30 Sep 2021 14:07:34 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35146C061775 for ; Thu, 30 Sep 2021 11:05:50 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id cr8-20020ad456e8000000b0038251b6e5c4so11493095qvb.1 for ; Thu, 30 Sep 2021 11:05:50 -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=nyhBoKfxi6FxDeRTTSmIOiquDaJDbE0FRQCKwRagYzQ=; b=T2lq5gRHvw6HVmjDdKTKIU1Ifpl7jyOJEawY1hRX4vNGm2m2nzy1S8ESeA2a4KNaxe xhrDFVZgVoHH7n5+D6FzMG+ADaHIqQfT5a3maFMxqN1us5n6zUhDM/4ui2AjQ/KXJaQC fQPzA4TJyo2y4De2ZswfldLfkLbVcxP3yYMEWGBpEZwvQO9/SJLW1/LkkgeDWdzCVDpw nyKxKIEzcgDsh/sRCZh3QnyKYWkZOA6Wpc6V+uhnQTPw7D9cJoRvBYcUYu4QH/bAcm6z e7AswDeOL40y/jPDduTFcfYjw7Y59rNsNbWUUVP7n2+DL39rBCbsI1hqyvNLKT6ngpT7 bsOw== 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=nyhBoKfxi6FxDeRTTSmIOiquDaJDbE0FRQCKwRagYzQ=; b=6YgHrFl1BjVmiPYcDwaFJlpdV9k/niyz6nxm3MjCbtFqzWPq72DoCmTL3siPs/rOXl BkqosK9N5PmmUB6nusFS46d6PLJf3y7XOGYrPRnB3fgcBaMRSO6aRMJlTCgL23xKNP07 bE9HSeoLHIzKaMe7VwFPoCg+d+1tU8pSb2heRfoz1vUpx/HmkyAi5G6GQSBonnB3dO0l QOayU0oKqqm/11I+ObkUxxkFNh1j0B5Ercl23whjcQCPszbbpiTcF5DZ6fZnlEJgIMDE X6FMjHOspO8HpR5Kh3YxYqIG80GVYL/9pJ8eUc+596JJAgVV+YJVVgY3RV4IqV2gS9c+ MbFQ== X-Gm-Message-State: AOAM531r31WrX0fj4FVz3VWcYbsrFklLCeoZTFAS+P4+ULbedGqYXR6A cVVt89NBehPBgGsOV0BAFlWcP6gq9pcVk6QgKAM= X-Google-Smtp-Source: ABdhPJww8bG0Sv/OFRh6ZYC4dDKnX2iWbaFo6aoQfxHbUGCC9B7YtHlIYDywb7k5TQZjobzIRlqWU7FhDhse/4Y7wIg= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a05:6214:5cf:: with SMTP id t15mr5253298qvz.25.1633025149389; Thu, 30 Sep 2021 11:05:49 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:22 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-7-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 06/15] ftrace: Use an opaque type for functions not callable from C From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org With CONFIG_CFI_CLANG, the compiler changes function references to point to the CFI jump table. As ftrace_call, ftrace_regs_call, and mcount_call are not called from C, use DECLARE_ASM_FUNC_SYMBOL to declare them. Signed-off-by: Sami Tolvanen --- include/linux/ftrace.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 832e65f06754..67de28464aeb 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -578,9 +578,10 @@ extern void ftrace_replace_code(int enable); extern int ftrace_update_ftrace_func(ftrace_func_t func); extern void ftrace_caller(void); extern void ftrace_regs_caller(void); -extern void ftrace_call(void); -extern void ftrace_regs_call(void); -extern void mcount_call(void); + +DECLARE_ASM_FUNC_SYMBOL(ftrace_call); +DECLARE_ASM_FUNC_SYMBOL(ftrace_regs_call); +DECLARE_ASM_FUNC_SYMBOL(mcount_call); void ftrace_modify_all_code(int command); From patchwork Thu Sep 30 18:05:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537997 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58F29C433F5 for ; Thu, 30 Sep 2021 18:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4330D61A02 for ; Thu, 30 Sep 2021 18:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353099AbhI3SHk (ORCPT ); Thu, 30 Sep 2021 14:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353106AbhI3SHf (ORCPT ); Thu, 30 Sep 2021 14:07:35 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBCD9C06176A for ; Thu, 30 Sep 2021 11:05:52 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 207-20020a2503d8000000b005b6fc088578so4434789ybd.0 for ; Thu, 30 Sep 2021 11:05:52 -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=tPhQgqpAKPBQUxwOrEtJBlsTaM2q8Clcy13gCpSQvzI=; b=DArh49XlDsWw110GeI4zxBAHoJ8q7ew7MQMlgVAwRtWh7bUKmPZfZ7aXH7ujHia2uw HEnHzF6kVSmrR7TmAje3meeaPs7TWUj5rVnFZwTdr25/8j+pGDf59ZYj+3roFewtIGs/ cB5pd1eXeFShrPHnoMPzs7oGq46vacp6Lw7jmxzPenkQ3SB55sqHk5fgT1qFUDzsDYio XUK86TrTKe8WETWjwDLexToijeo42Ji0hwIOCJ00XTXo43J4d2Pzfw/nC/bPLCih+7td Zh9jihr7INO9ZOmeUJsTe4QKzPECqLF9Tyi0ml0jLQFMF2QaRwgvYHM+V5QM1iKFjZP6 A3CA== 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=tPhQgqpAKPBQUxwOrEtJBlsTaM2q8Clcy13gCpSQvzI=; b=f+6pFMzNJ5Sno3tHQooBvFPoKzhYDIGvNpw68sDTvr4chiLmWZgIRHrAqWxN2eoU/A Xtro717BzK+z3oGhGACGGSPQYuruvFaqxXCLTZ9RsNA9qFevvfrKEb4iAcJduZLXnFnA 5M3NPV7FLShmslfpX8ZEqzA+OuEF+pj+NIv+UieQbZmZm/VCuXBROYx2XXZoPYUQLH+2 It2mARzTwuZyGFU7HkNx4rXqhSTFY+YhO/BVcUNaUbUaDQkeFoeRGtLSqjjOeYMiPp04 SvWfbGWFEA1EttUMeT7Bktjlki0tmgNaO2zjcw0G4RkCkVFIHvoAJ3S50NzCJfOMptQw rjOA== X-Gm-Message-State: AOAM530sD2jH/A++m4wuOZNmpL8abiGzkaTGwfFXtpi+np3GG4CwYgfV f6dBafKMv9gl+sr4MjSQjcBrkP+vB+XokhreXts= X-Google-Smtp-Source: ABdhPJzd8xBuekl5w0YEWpM/wXNrKDJYF8cvGNaiEGRWRb966n+l0RkGQPKD+VnEBRebQwkRbBbjmfvH313kcdqx/Zw= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a25:5093:: with SMTP id e141mr690151ybb.171.1633025152132; Thu, 30 Sep 2021 11:05:52 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:23 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 07/15] lkdtm: Disable UNSET_SMEP with CFI From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Disable the UNSET_SMEP test when CONFIG_CFI_CLANG is enabled as jumping to a call gadget would always trip CFI instead. Signed-off-by: Sami Tolvanen Acked-by: Kees Cook --- drivers/misc/lkdtm/bugs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index 4282b625200f..6e8677852262 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -367,7 +367,7 @@ void lkdtm_STACK_GUARD_PAGE_TRAILING(void) void lkdtm_UNSET_SMEP(void) { -#if IS_ENABLED(CONFIG_X86_64) && !IS_ENABLED(CONFIG_UML) +#if IS_ENABLED(CONFIG_X86_64) && !IS_ENABLED(CONFIG_UML) && !IS_ENABLED(CONFIG_CFI_CLANG) #define MOV_CR4_DEPTH 64 void (*direct_write_cr4)(unsigned long val); unsigned char *insn; From patchwork Thu Sep 30 18:05:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537995 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8828DC43219 for ; Thu, 30 Sep 2021 18:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 707AC619F9 for ; Thu, 30 Sep 2021 18:05:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353101AbhI3SHl (ORCPT ); Thu, 30 Sep 2021 14:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353073AbhI3SHh (ORCPT ); Thu, 30 Sep 2021 14:07:37 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F275AC061772 for ; Thu, 30 Sep 2021 11:05:54 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 207-20020a2503d8000000b005b6fc088578so4434943ybd.0 for ; Thu, 30 Sep 2021 11:05:54 -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=fPre9riEtsWDn3nT/Sr4LcMmmeeCRXoVSu1AIB6M7IQ=; b=WOqKG4pCG4OG7NbKOjdPUlyrET1QwyjhNoXM+aIOZw4h0mqTSFrygPNgZWNl3rJbMt ML1pg1BjoWcbeGwL9iWhIBhRu94ny8XE0YqMSBcYge2bqQCuYxe6MX874k7SY90mzw3Y jII4mgP4SW+9kJcE8r5WwgwTH67+Na/lflvYaG9d2yMhYIbQaWYy6157X3WkK+fwEAeZ TFeIKl7Bl19j1EM4wzKjC/hLn/0dDGGmOKStF0nzGx5lrmYtksNqbTpx4hRMh8ikb6g3 3QNQuzIAKHhNiAI9PEpmiGHCmsLVSSCwkoYoAnvMyKiyBHS8WVu1OkICCZv4IWS8SnCI rNhQ== 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=fPre9riEtsWDn3nT/Sr4LcMmmeeCRXoVSu1AIB6M7IQ=; b=q3bKU6R+Lvj0YdeGqbAAZHCTbou8zrUca7DCpHHhIE2o/BHXyOByBVW0FF1EL/oA5x PZW8+RjDmPyrIESMQ+HGesGxXZLYzuMGpWzDd55Ejt9WZaPgESmK3ZU5upAaEKMorDSc V3G4Fssa430+/3i3X7o7HegmZJtuaVFYkfZVjxAefG4OTsXqJ45xZhZZLpxpnno3xNL8 7RFFN9Y34aqP1Kstvuy5KTasq/lAnhQWBdRSikev7CGLkhIzz2X14HGnPPq2jvdtyAFI ylaG1CE8L+FvXblHYJ4MmNLbGJr0Vo7sMD1k2aALWf+Kr9PbatYkh9JxpNBLSsetmsC6 hUjg== X-Gm-Message-State: AOAM533DC/xDUyAFLrgEvnx/a1wKyl6B1P+7Tlg2M7rCd4ZT97M/Oakr tkj3ZCm+sp06g9huaM9QxzpStfUWZmDT6ISWU24= X-Google-Smtp-Source: ABdhPJxSAVWIMsARi3nfwWxlFk7SoNUuPOxAnFKLyn/tb5cb4kWVXe1gudHXrJc1oNAyYUvYK7dAfI4tbix6w58R9is= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a25:d48f:: with SMTP id m137mr655048ybf.109.1633025154238; Thu, 30 Sep 2021 11:05:54 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:24 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-9-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 08/15] lkdtm: Use an opaque type for lkdtm_rodata_do_nothing From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Use an opaque type for lkdtm_rodata_do_nothing to stop the compiler from generating a CFI jump table entry that jumps to .rodata. Signed-off-by: Sami Tolvanen Acked-by: Kees Cook --- drivers/misc/lkdtm/lkdtm.h | 2 +- drivers/misc/lkdtm/perms.c | 2 +- drivers/misc/lkdtm/rodata.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index c212a253edde..2da74236c005 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -137,7 +137,7 @@ void lkdtm_REFCOUNT_TIMING(void); void lkdtm_ATOMIC_TIMING(void); /* rodata.c */ -void lkdtm_rodata_do_nothing(void); +DECLARE_ASM_FUNC_SYMBOL(lkdtm_rodata_do_nothing); /* usercopy.c */ void __init lkdtm_usercopy_init(void); diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index 2dede2ef658f..fa2bd90bd8ee 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -151,7 +151,7 @@ void lkdtm_EXEC_VMALLOC(void) void lkdtm_EXEC_RODATA(void) { - execute_location(lkdtm_rodata_do_nothing, CODE_AS_IS); + execute_location((void *)lkdtm_rodata_do_nothing, CODE_AS_IS); } void lkdtm_EXEC_USERSPACE(void) diff --git a/drivers/misc/lkdtm/rodata.c b/drivers/misc/lkdtm/rodata.c index baacb876d1d9..17ed0ad4e6ae 100644 --- a/drivers/misc/lkdtm/rodata.c +++ b/drivers/misc/lkdtm/rodata.c @@ -3,7 +3,7 @@ * This includes functions that are meant to live entirely in .rodata * (via objcopy tricks), to validate the non-executability of .rodata. */ -#include "lkdtm.h" +void lkdtm_rodata_do_nothing(void); void noinstr lkdtm_rodata_do_nothing(void) { From patchwork Thu Sep 30 18:05:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538001 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01878C4332F for ; Thu, 30 Sep 2021 18:06:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3CAC61A02 for ; Thu, 30 Sep 2021 18:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353125AbhI3SHp (ORCPT ); Thu, 30 Sep 2021 14:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353098AbhI3SHk (ORCPT ); Thu, 30 Sep 2021 14:07:40 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AAA4C06176D for ; Thu, 30 Sep 2021 11:05:57 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 81-20020a251254000000b005b6220d81efso9545156ybs.12 for ; Thu, 30 Sep 2021 11:05:57 -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=yQU12La/KcSmVBf8yylpekUFgOmt+PXL3oVr9qE0LoI=; b=pnTMN3fz++vB2Sf9sZZOcWzPPVW20xTtE3g0a3MCpfyP3dl4edEhM5M39xvNnN+KBo TB11zIdLXzr37SI94slGbWoDmz924atm9XmR9llxKsUYosrkJFca2AePhVEJ2KDrVV5w ZVK6bJw5MkirHnCrnUIrk/+3EtR1Vg3yjbCQjq71ZZbKtr+mHHB93rdjHoeaupu51wJx Hm/oiLabeYfCrQkI77o/vlLvl1ph5LHHZraQbPnZZQsHhfa7RzBJ2HhTFJYO2GfPVb3J kW3LIUHEV5ayen+WkY6BPJZT+ddZ5P3Md0XtJkc6cN0ZEsCieJ1nuAqT+22CrDtBhd7S QdPg== 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=yQU12La/KcSmVBf8yylpekUFgOmt+PXL3oVr9qE0LoI=; b=fSVc8X7bKuN7hZ/Pk/QuLyVxK4ITI9GNNzDi5DvMoa+fYrjIdu8++2wIiMYGdMPKQj YQgDQCrblLoJXXXD5mHC5rZBCMDTObTtTbd8ctX65FaVhaVrrE8DKkxXA9eiEnIwxCpf v16pK2wYpq7+kQkQjVT0XKPsinIbMtIdJtmQTDSBQg2ygMixyBcExkvKGM29R8GGESIS 7cXlzPa7UU9A3jx8LSThHQmgA0htW1uLFWoqtNhvxzs6ljD+kgY+7Cbx7R2aW44kx1vA Osk5IShu2cEmyWEO8Do70yTLGbuzzWu3hzglVJN9woHdYS8jcHsP/HQZWJdAGLLx8cb0 PrIA== X-Gm-Message-State: AOAM532fniG93mqmRE2cNa4vOcHBYgYm5rIzAA2tFSEnERiSMQWHyuzb oXY3fyUuewtWa6a4ytpIK3QEbCxns/j76Ak5+yc= X-Google-Smtp-Source: ABdhPJznfmrqE91cvelw1V7oFVJ8N8612t77FEmRP1grMD+n+ILKJlOvgn1gcdjF4WvXOl343eChfkNX6jk2zU7uUtE= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a25:bb8b:: with SMTP id y11mr700022ybg.384.1633025156793; Thu, 30 Sep 2021 11:05:56 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:25 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-10-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 09/15] x86: Use an opaque type for functions not callable from C From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org The kernel has several assembly functions that are not directly callable from C. Use an opaque type for these function prototypes to make misuse harder, and to avoid the need to annotate references to these functions for Clang's Control-Flow Integrity (CFI). Suggested-by: Andy Lutomirski Suggested-by: Alexander Lobakin Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- arch/x86/include/asm/ftrace.h | 2 +- arch/x86/include/asm/idtentry.h | 10 +++++----- arch/x86/include/asm/page_64.h | 7 ++++--- arch/x86/include/asm/paravirt_types.h | 3 ++- arch/x86/include/asm/processor.h | 2 +- arch/x86/include/asm/proto.h | 25 +++++++++++++------------ arch/x86/include/asm/uaccess_64.h | 9 +++------ arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ftrace.c | 2 +- arch/x86/kernel/paravirt.c | 4 ++-- arch/x86/kvm/emulate.c | 4 ++-- arch/x86/kvm/kvm_emulate.h | 9 ++------- arch/x86/xen/enlighten_pv.c | 6 +++--- arch/x86/xen/xen-ops.h | 10 +++++----- 14 files changed, 45 insertions(+), 50 deletions(-) diff --git a/arch/x86/include/asm/ftrace.h b/arch/x86/include/asm/ftrace.h index 9f3130f40807..54d23f421c16 100644 --- a/arch/x86/include/asm/ftrace.h +++ b/arch/x86/include/asm/ftrace.h @@ -17,7 +17,7 @@ #ifndef __ASSEMBLY__ extern atomic_t modifying_ftrace_code; -extern void __fentry__(void); +DECLARE_ASM_FUNC_SYMBOL(__fentry__); static inline unsigned long ftrace_call_adjust(unsigned long addr) { diff --git a/arch/x86/include/asm/idtentry.h b/arch/x86/include/asm/idtentry.h index 1345088e9902..2f6d0528bdd2 100644 --- a/arch/x86/include/asm/idtentry.h +++ b/arch/x86/include/asm/idtentry.h @@ -27,8 +27,8 @@ * as well which is used to emit the entry stubs in entry_32/64.S. */ #define DECLARE_IDTENTRY(vector, func) \ - asmlinkage void asm_##func(void); \ - asmlinkage void xen_asm_##func(void); \ + DECLARE_ASM_FUNC_SYMBOL(asm_##func); \ + DECLARE_ASM_FUNC_SYMBOL(xen_asm_##func); \ __visible void func(struct pt_regs *regs) /** @@ -78,8 +78,8 @@ static __always_inline void __##func(struct pt_regs *regs) * C-handler. */ #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ - asmlinkage void asm_##func(void); \ - asmlinkage void xen_asm_##func(void); \ + DECLARE_ASM_FUNC_SYMBOL(asm_##func); \ + DECLARE_ASM_FUNC_SYMBOL(xen_asm_##func); \ __visible void func(struct pt_regs *regs, unsigned long error_code) /** @@ -386,7 +386,7 @@ static __always_inline void __##func(struct pt_regs *regs) * - The C handler called from the C shim */ #define DECLARE_IDTENTRY_DF(vector, func) \ - asmlinkage void asm_##func(void); \ + DECLARE_ASM_FUNC_SYMBOL(asm_##func); \ __visible void func(struct pt_regs *regs, \ unsigned long error_code, \ unsigned long address) diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h index 4bde0dc66100..d6760b6773de 100644 --- a/arch/x86/include/asm/page_64.h +++ b/arch/x86/include/asm/page_64.h @@ -5,6 +5,7 @@ #include #ifndef __ASSEMBLY__ +#include #include /* duplicated to the one in bootmem.h */ @@ -40,9 +41,9 @@ extern unsigned long __phys_addr_symbol(unsigned long); #define pfn_valid(pfn) ((pfn) < max_pfn) #endif -void clear_page_orig(void *page); -void clear_page_rep(void *page); -void clear_page_erms(void *page); +DECLARE_ASM_FUNC_SYMBOL(clear_page_orig); +DECLARE_ASM_FUNC_SYMBOL(clear_page_rep); +DECLARE_ASM_FUNC_SYMBOL(clear_page_erms); static inline void clear_page(void *page) { diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index d9d6b0203ec4..dfaa50d20d6a 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -38,6 +38,7 @@ #include #include #include +#include struct page; struct thread_struct; @@ -271,7 +272,7 @@ struct paravirt_patch_template { extern struct pv_info pv_info; extern struct paravirt_patch_template pv_ops; -extern void (*paravirt_iret)(void); +extern asm_func_ptr paravirt_iret; #define PARAVIRT_PATCH(x) \ (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 577f342dbfb2..02743d701fa8 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -449,7 +449,7 @@ static inline unsigned long cpu_kernelmode_gs_base(int cpu) DECLARE_PER_CPU(void *, hardirq_stack_ptr); DECLARE_PER_CPU(bool, hardirq_stack_inuse); -extern asmlinkage void ignore_sysret(void); +DECLARE_ASM_FUNC_SYMBOL(ignore_sysret); /* Save actual FS/GS selectors and bases to current->thread */ void current_save_fsgs(void); diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h index 8c5d1910a848..a6aa64eb3657 100644 --- a/arch/x86/include/asm/proto.h +++ b/arch/x86/include/asm/proto.h @@ -2,6 +2,7 @@ #ifndef _ASM_X86_PROTO_H #define _ASM_X86_PROTO_H +#include #include struct task_struct; @@ -11,26 +12,26 @@ struct task_struct; void syscall_init(void); #ifdef CONFIG_X86_64 -void entry_SYSCALL_64(void); -void entry_SYSCALL_64_safe_stack(void); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSCALL_64); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSCALL_64_safe_stack); long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2); #endif #ifdef CONFIG_X86_32 -void entry_INT80_32(void); -void entry_SYSENTER_32(void); -void __begin_SYSENTER_singlestep_region(void); -void __end_SYSENTER_singlestep_region(void); +DECLARE_ASM_FUNC_SYMBOL(entry_INT80_32); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSENTER_32); +DECLARE_ASM_FUNC_SYMBOL(__begin_SYSENTER_singlestep_region); +DECLARE_ASM_FUNC_SYMBOL(__end_SYSENTER_singlestep_region); #endif #ifdef CONFIG_IA32_EMULATION -void entry_SYSENTER_compat(void); -void __end_entry_SYSENTER_compat(void); -void entry_SYSCALL_compat(void); -void entry_SYSCALL_compat_safe_stack(void); -void entry_INT80_compat(void); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSENTER_compat); +DECLARE_ASM_FUNC_SYMBOL(__end_entry_SYSENTER_compat); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSCALL_compat); +DECLARE_ASM_FUNC_SYMBOL(entry_SYSCALL_compat_safe_stack); +DECLARE_ASM_FUNC_SYMBOL(entry_INT80_compat); #ifdef CONFIG_XEN_PV -void xen_entry_INT80_compat(void); +DECLARE_ASM_FUNC_SYMBOL(xen_entry_INT80_compat); #endif #endif diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h index 45697e04d771..df2be1efa35e 100644 --- a/arch/x86/include/asm/uaccess_64.h +++ b/arch/x86/include/asm/uaccess_64.h @@ -17,12 +17,9 @@ */ /* Handles exceptions in both to and from, but doesn't do access_ok */ -__must_check unsigned long -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len); -__must_check unsigned long -copy_user_generic_string(void *to, const void *from, unsigned len); -__must_check unsigned long -copy_user_generic_unrolled(void *to, const void *from, unsigned len); +DECLARE_ASM_FUNC_SYMBOL(copy_user_enhanced_fast_string); +DECLARE_ASM_FUNC_SYMBOL(copy_user_generic_string); +DECLARE_ASM_FUNC_SYMBOL(copy_user_generic_unrolled); static __always_inline __must_check unsigned long copy_user_generic(void *to, const void *from, unsigned len) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e9da3dc71254..0c60a7fa6fa5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -530,7 +530,7 @@ extern struct paravirt_patch_site __start_parainstructions[], * convention such that we can 'call' it from assembly. */ -extern void int3_magic(unsigned int *ptr); /* defined in asm */ +DECLARE_ASM_FUNC_SYMBOL(int3_magic); asm ( " .pushsection .init.text, \"ax\", @progbits\n" diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 1b3ce3b4a2a2..9e0c07a82b44 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -589,7 +589,7 @@ void arch_ftrace_trampoline_free(struct ftrace_ops *ops) #ifdef CONFIG_FUNCTION_GRAPH_TRACER #ifdef CONFIG_DYNAMIC_FTRACE -extern void ftrace_graph_call(void); +DECLARE_ASM_FUNC_SYMBOL(ftrace_graph_call); static const char *ftrace_jmp_replace(unsigned long ip, unsigned long addr) { diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c index ebc45360ffd4..737437043e40 100644 --- a/arch/x86/kernel/paravirt.c +++ b/arch/x86/kernel/paravirt.c @@ -138,7 +138,7 @@ void paravirt_set_sched_clock(u64 (*func)(void)) } /* These are in entry.S */ -extern void native_iret(void); +DECLARE_ASM_FUNC_SYMBOL(native_iret); static struct resource reserve_ioports = { .start = 0, @@ -403,7 +403,7 @@ struct paravirt_patch_template pv_ops = { #ifdef CONFIG_PARAVIRT_XXL NOKPROBE_SYMBOL(native_load_idt); -void (*paravirt_iret)(void) = native_iret; +asm_func_ptr paravirt_iret = native_iret; #endif EXPORT_SYMBOL(pv_ops); diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2837110e66ed..1f81f939d982 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -201,7 +201,7 @@ struct opcode { const struct escape *esc; const struct instr_dual *idual; const struct mode_dual *mdual; - void (*fastop)(struct fastop *fake); + fastop_t fastop; } u; int (*check_perm)(struct x86_emulate_ctxt *ctxt); }; @@ -322,7 +322,7 @@ static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); __FOP_RET(#name) #define FOP_START(op) \ - extern void em_##op(struct fastop *fake); \ + DECLARE_ASM_FUNC_SYMBOL(em_##op); \ asm(".pushsection .text, \"ax\" \n\t" \ ".global em_" #op " \n\t" \ ".align " __stringify(FASTOP_SIZE) " \n\t" \ diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 68b420289d7e..44c1a9324e1c 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -290,13 +290,8 @@ enum x86emul_mode { #define X86EMUL_SMM_MASK (1 << 6) #define X86EMUL_SMM_INSIDE_NMI_MASK (1 << 7) -/* - * fastop functions are declared as taking a never-defined fastop parameter, - * so they can't be called from C directly. - */ -struct fastop; - -typedef void (*fastop_t)(struct fastop *); +/* fastop functions cannot be called from C directly. */ +typedef asm_func_ptr fastop_t; struct x86_emulate_ctxt { void *vcpu; diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 6cf3c379bbaa..62dd7ae00e3f 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -612,8 +612,8 @@ DEFINE_IDTENTRY_RAW(xenpv_exc_machine_check) #endif struct trap_array_entry { - void (*orig)(void); - void (*xen)(void); + asm_func_ptr orig; + asm_func_ptr xen; bool ist_okay; }; @@ -672,7 +672,7 @@ static bool __ref get_trap_addr(void **addr, unsigned int ist) struct trap_array_entry *entry = trap_array + nr; if (*addr == entry->orig) { - *addr = entry->xen; + *addr = (void *)entry->xen; ist_okay = entry->ist_okay; found = true; break; diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 8d7ec49a35fb..b5ceb3007cfe 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -8,12 +8,12 @@ #include /* These are code, but not functions. Defined in entry.S */ -extern const char xen_failsafe_callback[]; +DECLARE_ASM_FUNC_SYMBOL(xen_failsafe_callback); -void xen_sysenter_target(void); +DECLARE_ASM_FUNC_SYMBOL(xen_sysenter_target); #ifdef CONFIG_X86_64 -void xen_syscall_target(void); -void xen_syscall32_target(void); +DECLARE_ASM_FUNC_SYMBOL(xen_syscall_target); +DECLARE_ASM_FUNC_SYMBOL(xen_syscall32_target); #endif extern void *xen_initial_gdt; @@ -136,7 +136,7 @@ __visible unsigned long xen_read_cr2(void); __visible unsigned long xen_read_cr2_direct(void); /* These are not functions, and cannot be called normally */ -__visible void xen_iret(void); +DECLARE_ASM_FUNC_SYMBOL(xen_iret); extern int xen_panic_handler_init(void); From patchwork Thu Sep 30 18:05:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12537999 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E167EC433F5 for ; Thu, 30 Sep 2021 18:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C296361A02 for ; Thu, 30 Sep 2021 18:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353120AbhI3SHo (ORCPT ); Thu, 30 Sep 2021 14:07:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353083AbhI3SHn (ORCPT ); Thu, 30 Sep 2021 14:07:43 -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 031EEC06176C for ; Thu, 30 Sep 2021 11:06:00 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id i83-20020a256d56000000b005b706d1417bso3305997ybc.6 for ; Thu, 30 Sep 2021 11:05:59 -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=ED+/GzZlK6Ch13ba2R4bfh465Q8WBKVR8XLcZW0S8Fc=; b=a4wIEk16Yi3WBVYxNj/u51ELotSd+Td/UHu5Z2iCoJjh7G9jRGSdAmVPqtg7kE8Moe I4F+ko0NAisazC4HsQaML3NwV2zmrg9GU8RMTzl4nNV0YQZGmSlwHt67AOxxn0feNH3F nQZUM2xnZ/CZVNrQn9LgEvChc7hWBZ0Bu8GusDtqOg/P6nNDmjVzBfhQiA41rlfFFdt1 uio94UCFZ4s7qAecfPVlGTyQcFmmy2BmWsE8b+uKB7X+mRvERwX512m9RWqmmcbA7p7m BtC11Cog4hGglHVBuwF6TI8qFMjDv0NG8yTE62Oqgj9Ec0mcPRwdgMiO3dqPzNKINnMk bwYA== 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=ED+/GzZlK6Ch13ba2R4bfh465Q8WBKVR8XLcZW0S8Fc=; b=i/VjsvR64qBdhs+0yRKo6TYN6Xx+85jLFPVePmmvEOIEXxKypQG/tkxPsQtT/Nxce4 qJ2PTqYEV7EqFXcXc2SxV1xaZH5uLtTmQIRbdkIW2j6zDSe7n5ptHDBfQcdglVfbwPIs QqesUlJivCKTnSNbjAy50oWxcCgyoHPIV60FtcvX4nwAo/SOoP1snRXRRds1oJztYmsf NmYPZEswsvB65bgFGT6sFPhB981YE0WpVwj3lPXWkV7ErsWZbWDVROvs8e5jNX6emuMC swrhgXaupyt6JYCzF6NvP9tVF6jlzv/gSKEDAJ+0dCmqrZGEyscS5dCOK6sCwyzXJlAM NEvg== X-Gm-Message-State: AOAM532CQcJ1o+DgYEBe0uckiYkcCj21fTHyaUiqCh3p6ScuF11BHEvh 5drm56XQRCS0JtC1y4+kSmHqt2AVi1W2u3K3CfY= X-Google-Smtp-Source: ABdhPJyvNbwNfpOpt6OxAXYurh0/xz6gRjcukdf9v0nRCwRueYu27FjQKWVhrCW4pcvTUYbPjtDzmue7U+ITV+Khz+c= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:1106:: with SMTP id o6mr823986ybu.201.1633025159268; Thu, 30 Sep 2021 11:05:59 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:26 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 10/15] x86/purgatory: Disable CFI From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Disable CONFIG_CFI_CLANG for the stand-alone purgatory.ro. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers --- arch/x86/purgatory/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 95ea17a9d20c..911954fec31c 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -55,6 +55,10 @@ ifdef CONFIG_RETPOLINE PURGATORY_CFLAGS_REMOVE += $(RETPOLINE_CFLAGS) endif +ifdef CONFIG_CFI_CLANG +PURGATORY_CFLAGS_REMOVE += $(CC_FLAGS_CFI) +endif + CFLAGS_REMOVE_purgatory.o += $(PURGATORY_CFLAGS_REMOVE) CFLAGS_purgatory.o += $(PURGATORY_CFLAGS) From patchwork Thu Sep 30 18:05:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538003 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FFB6C433EF for ; Thu, 30 Sep 2021 18:06:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E870E619F6 for ; Thu, 30 Sep 2021 18:06:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353175AbhI3SHz (ORCPT ); Thu, 30 Sep 2021 14:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353108AbhI3SHp (ORCPT ); Thu, 30 Sep 2021 14:07:45 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53DC4C06176D for ; Thu, 30 Sep 2021 11:06:02 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id o6-20020a05622a008600b002a6c2fbc853so12479176qtw.16 for ; Thu, 30 Sep 2021 11:06:02 -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=36JGoOQwhp84OMbqBWPfqbJksyq4Ee1GRSA1czJSFhs=; b=cB77Vb/CwICfRwD2mkh0raoM//6noNAFP5BtwePcoVGM1nyAlCfVJtKF35wL1pMwev D2GqltNZ1bhq+hRH8UnFSweflcXsS95Ir8dZ3rY6OVAjnMt/R0W1UR6ctQPtg/gcIBa9 y8KQaYC2G05aBR5jrnIWIZ3huUYLx77QQT5hlGs/UVeG0GqNpK2l8DTtd4cNHYI81Vw3 zwyXCy6a/HqwSqBa9p+Vi89JXE5Vy18KuamIGkTDlZ/7kQWptK+0iRY5d9Fkqgkci/3a srPd+GRRzz57/fZCNOzWknSmGYqJ1fzF0HmWIqUaS3MZQa3RmMT3xGN54NzMRyKTJiRj eUqw== 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=36JGoOQwhp84OMbqBWPfqbJksyq4Ee1GRSA1czJSFhs=; b=GOCsMw2jH16aDxeVG8ex8VdyG9Tp21oHB1sknTAirgFekUDn4N87NdTavdm7fx3dQO P5uoDpOONtf6TGxrslz99jA9qiMjtuStwnzZwMvTurlUZ+su6771tHtt5gVlco9XCcri B4sfxJZJPkCXVyJYN9cJKNtuRLh42XGsGEEU+bZUmgVs+XJ/pwDUnRbjvw8Zeiir1g/J Tr+Q70Broo6mGvRlIZcaST5NI+ji6wMXNxekCyfLyH3d+18YzBUH8x1EnbW/0Cpm99i7 ts1Swkf/LXNSQhQ21P7fBcgKHZEywSxzdiaG0edkGXklUP5/RuO9j1wNHIHSb5tYRyMc NeVA== X-Gm-Message-State: AOAM531N7BLlAMlMk9ci8J6k6NFZn5PKgm8NcN+Fe53SfeZ24g/Ss3fM RoNBveabaZAoKvt7mA4lcPTVrGvHQoT3JzMEBG4= X-Google-Smtp-Source: ABdhPJzH+nWTE6A+qxvqzNs/xyKJE6Qfj8m4/ETPnnzMgQrPSxiF3nkVfaZaM0P8d+oy0XInEzgoA4qs0F4Eos30P9A= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a05:6214:1022:: with SMTP id k2mr5344731qvr.53.1633025161554; Thu, 30 Sep 2021 11:06:01 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:27 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-12-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 11/15] x86, relocs: Ignore __typeid__ relocations From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org From: Kees Cook The __typeid__* symbols aren't actually relocations, so they can be ignored during relocation generation. Signed-off-by: Kees Cook Signed-off-by: Sami Tolvanen --- arch/x86/tools/relocs.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index 27c82207d387..5304a6037924 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -51,6 +51,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = { "^(xen_irq_disable_direct_reloc$|" "xen_save_fl_direct_reloc$|" "VDSO|" + "__typeid__|" "__crc_)", /* @@ -811,6 +812,12 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym, symname); break; + case R_X86_64_8: + if (!shn_abs || !is_reloc(S_ABS, symname)) + die("Non-whitelisted %s relocation: %s\n", + rel_type(r_type), symname); + break; + case R_X86_64_32: case R_X86_64_32S: case R_X86_64_64: From patchwork Thu Sep 30 18:05:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538007 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D63CC433FE for ; Thu, 30 Sep 2021 18:06:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55BA3619F6 for ; Thu, 30 Sep 2021 18:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353229AbhI3SIF (ORCPT ); Thu, 30 Sep 2021 14:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353145AbhI3SHs (ORCPT ); Thu, 30 Sep 2021 14:07:48 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D99CC061770 for ; Thu, 30 Sep 2021 11:06:04 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id q24-20020ac84118000000b002a6d14f21e9so12472703qtl.9 for ; Thu, 30 Sep 2021 11:06:04 -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=6Sx35dcc+ZTMADfJZWhUXml0PH3ooMBccB8Q+X9WArY=; b=pk5WOqOatQc/RJ42WoGinJC4/twjfgeWj1OXnhRiKHOSyA+pezAiWCoNBnz9Fj+AjS aOIDIpm1iy+TcjZpq5DTIf5dzaYDjtKWxePGXlKJa1s8UPeIkYjw0jRVH3Fo7J0/v0qa Y2+1NlkQ7MA9G1a8IAApp1+pO7VRGdMokUvCl+6ZqMyyCl/dV0LjnCsymGj+FNDQdi2n 3daBKXh9Aoyuacg/VlU0MSjADI1JKmnKQdrM641Bl1X+yQD52QCGprXK4zzCdYcdsyEE oGzZH6nn/kGwgiv5PC/yBBtgiJkSbK5MH/dRMdPRgoeoO/0StI8Cr8IDhLNSg1Y1Z3L3 Bzjw== 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=6Sx35dcc+ZTMADfJZWhUXml0PH3ooMBccB8Q+X9WArY=; b=JdbUlaTaQY9SoltUJukDAKNdHYlCpAQESgqH1Yxry3hCZ9FXX8vZp8rvsJGFssjEJl 48luFQ3NlLT/1rVhrBHXOZKnVRG/5iILogWllZu1NnzDkX9UdVi/JHc/0UHXDAPotNuB W48W4+2G0a6irqC1jtOYN9SBi3hAC9GuzIERrq4T9WkiIxGW03bKTsItl7j91if6gxfu 0lqnPptW+4WFSlGCO9TfUJ+qNFWmEnhBer4Xyma9SnjCRSuhB5gvA0PbwIHhPiq3jvK0 oYXHAY6B/3agYRGxIJba5h+KJ9AA5A2ZM6R6fW9d9Oub9AST8sHLab8Zn3krx/7tMxiM hq9w== X-Gm-Message-State: AOAM530kI/fuA5PuVdsozI8ylHmV0Y0H5rcDA6vw9nmD/pJaZjjcAo3+ +MqPfhul1kS5uQS9rzYz/8fJG36Yl/gGqqw4Pbo= X-Google-Smtp-Source: ABdhPJw0mNH+hlrHNL741Ke8vSbHmQVJvJ7uLoZQ3qKxdZHJuHeykLu/G/qfGGTqGEDZGgeR0jdbNGhA10M2iltx9l4= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:ad4:408f:: with SMTP id l15mr4167941qvp.60.1633025163728; Thu, 30 Sep 2021 11:06:03 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:28 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-13-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 12/15] x86, module: Ignore __typeid__ relocations From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Ignore the __typeid__ relocations generated with CONFIG_CFI_CLANG when loading modules. Signed-off-by: Sami Tolvanen --- arch/x86/kernel/module.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 5e9a34b5bd74..c4aeba237eef 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -197,6 +197,10 @@ static int __apply_relocate_add(Elf64_Shdr *sechdrs, val -= (u64)loc; write(loc, &val, 8); break; + case R_X86_64_8: + if (!strncmp(strtab + sym->st_name, "__typeid__", 10)) + break; + fallthrough; default: pr_err("%s: Unknown rela relocation: %llu\n", me->name, ELF64_R_TYPE(rel[i].r_info)); From patchwork Thu Sep 30 18:05:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538005 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 418A8C433EF for ; Thu, 30 Sep 2021 18:06:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D41F619F6 for ; Thu, 30 Sep 2021 18:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353222AbhI3SIE (ORCPT ); Thu, 30 Sep 2021 14:08:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353166AbhI3SHx (ORCPT ); Thu, 30 Sep 2021 14:07:53 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A46F9C061774 for ; Thu, 30 Sep 2021 11:06:06 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id m26-20020ac87b5a000000b002a6b3744ae6so12433979qtu.22 for ; Thu, 30 Sep 2021 11:06:06 -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=QXcVEtkl1ttQdqJQ36Mmw2BuBwRi/4y7WfQWoHeDQYQ=; b=YIvuqa4diHL/KOdonWT+XrXNn6ejbmYGrxpcq6tHonqWDd9wLeV2kwwd7/MnZkZe+o s2KOkSSO2fNwJF71waRq3eGAH4t/zuBbUl+XNk9E9a6TngigsVIeZe5yIU42XiSqwlo8 HQ9xPg9wLyxcZETOfRH6ThiR7EGl9OmCGOW0Fy7NxiJTbRGoINKW6TqXqmjsD6Gjlfn/ 1A8wRMJIuH+s8jB6UrBBIYr1tJxFMfIp51clrm1Ltlh5lxhL31MVFlV8m5jJB1qsC5Bz y30kNX8VS2C21viJCJ3iLc/AywLzChE7HO7BQ8g0EW657HJlc44Icfo9Td2j2D5Ps4vu t4eg== 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=QXcVEtkl1ttQdqJQ36Mmw2BuBwRi/4y7WfQWoHeDQYQ=; b=CZdBgGMIJrr0Q2Z1640NR9srq/4ekyLQj5Sr62aGm9QhZwak60whQu+I4YweadCMwN /3ACq/nuzMTXBBuVpfGBw6Cez9zplpm//IfGr98zmgKn2jtgu3QC8O+sOPVsWcebf4Do Dx7y1Fc+53L8/utrAwYGylssOe2BPm4z0UaeyoWDxkFJlN4wJPkD7nRgfKtc6e4wXXi7 /tpA44sFvVz6mp81/bik93ZFLDdvw5Yxx+IOPCbSGBJAnDsGIUWiKOOrKZ/UNP2+KpBd 4R5TCZomnXXEPfERWxcMFrUHSrGQEfP5sE7hzm1B4hyx7dOyOkc6g2MiPKUp7Pi5qIVY Fzkg== X-Gm-Message-State: AOAM531KqMZ7Me5AJ2VUvzono2EsrC1TCCSIVw1m+N/qq0GzPsdL8VMd Msh3sktCnJWXX1OedJC4af5QiWCKE+YRu92+6RA= X-Google-Smtp-Source: ABdhPJwOEaXh89+R/H7MBRz5M9c3ZhPc6Z/jeTX/U7qPBoq+FlxU6J4n+Dxg9mzNIkwXfswiN5kgdhWujNpQQLRVsnA= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a05:6214:122e:: with SMTP id p14mr6685928qvv.37.1633025165880; Thu, 30 Sep 2021 11:06:05 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:29 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-14-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 13/15] x86, cpu: Use LTO for cpu.c with CFI From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Allow LTO to be used for cpu.c when CONFIG_CFI_CLANG is enabled to avoid indirect call failures. CFI requires Clang >= 13, which doesn't have the stack protector inlining bug. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Reviewed-by: Nick Desaulniers --- arch/x86/power/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/power/Makefile b/arch/x86/power/Makefile index 379777572bc9..a0532851fed7 100644 --- a/arch/x86/power/Makefile +++ b/arch/x86/power/Makefile @@ -4,9 +4,11 @@ # itself be stack-protected CFLAGS_cpu.o := -fno-stack-protector +ifndef CONFIG_CFI_CLANG # Clang may incorrectly inline functions with stack protector enabled into # __restore_processor_state(): https://bugs.llvm.org/show_bug.cgi?id=47479 CFLAGS_REMOVE_cpu.o := $(CC_FLAGS_LTO) +endif obj-$(CONFIG_PM_SLEEP) += cpu.o obj-$(CONFIG_HIBERNATION) += hibernate_$(BITS).o hibernate_asm_$(BITS).o hibernate.o From patchwork Thu Sep 30 18:05:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538009 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11F80C433EF for ; Thu, 30 Sep 2021 18:07:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFC3C61164 for ; Thu, 30 Sep 2021 18:07:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353022AbhI3SJI (ORCPT ); Thu, 30 Sep 2021 14:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353127AbhI3SID (ORCPT ); Thu, 30 Sep 2021 14:08:03 -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 079A8C06176C for ; Thu, 30 Sep 2021 11:06:09 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id x16-20020a25b910000000b005b6b7f2f91cso9722527ybj.1 for ; Thu, 30 Sep 2021 11:06:08 -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=JQBSJ8qj9mW2upriZ1hUokdADKSbuyuOL0tMdMaGIyA=; b=s0zb3TFc82fA3XBAkcMpi6oec+ReyD7OcULFaBcO4uVLgtojliDt/V9XqnukzyaPol A1j7FIPBDGl1ZjSc0ZQu19AnLj9TllbqEcwRN+TRer3xWWvadPs/ORvRkVe6dvTICt1G ZJSeRN291POY2ZwlPuLkPJfEigA5ifAD8VVI7lIAbUsEkdzuPSZyBYmZlQ0B4+zCW2rr qqRiFZDvF5dgJaJMlYRAszaI2SitdqSUKgdJ5pFoL9uuyAVwfeRdYywQggtwFRNBko2I 8/rrf+ej0B9GZ/BRIEXG3mVOFCf/XjamfkW4tLCotoa9+itW1Ey93cSEGhIpV3FRDA+r bR9g== 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=JQBSJ8qj9mW2upriZ1hUokdADKSbuyuOL0tMdMaGIyA=; b=xIBCOlK8X4u04l6kAYCVrfcXoQlQRlffY15blhawSzdQVkBQVBuQNJh/42Jtl8Oo+V fG9JyubqHbOFZ1Uhoe2fbg21wSsUSQ7XfqMEqM6PLmW/+5hQOeYZwnnmxzR2ixYZ9Wlv CATAW34WdlsmsAi9KBK6QdJ2RoSyI8i9HVUWsiVxoVsjZj9/t44L5yyXBeLDpbGHTTou vTMI3tYZ5OR5I8FasK2jlA3HctRkSSE/ZF0c7DWsMFJ837YNH02qPaAP4SBNvQvi4RYf 4HgD3Hpr+tkBGqJEtiMqGJ40AsGNuQhxD51TY87y9yckOfd1eFPRkWAzdOrumLTbJz1a qRZA== X-Gm-Message-State: AOAM5319GwS4BFrmUVTAotaOUChuiuSJXza9VzxdRdsESlKQVxzEmyHw 9cBGKxzH+og3PC5l1cisSpoBQU5ghAcrm2GJLdg= X-Google-Smtp-Source: ABdhPJygJzfXzJubcmYgFAfGrc+L5exrHwzMqpfVKfj5yjqfYD02sPYHI+OV9HqYRb8L1IT/rL2I3DNS49v9knmwmuI= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a25:21c2:: with SMTP id h185mr689359ybh.495.1633025168233; Thu, 30 Sep 2021 11:06:08 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:30 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-15-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 14/15] x86, kprobes: Fix optprobe_template_func type mismatch From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org The optprobe_template_func symbol is defined in inline assembly, but it's not marked global, which conflicts with the C declaration needed for STACK_FRAME_NON_STANDARD and confuses the compiler when CONFIG_CFI_CLANG is enabled. Marking the symbol global would make the compiler happy, but as the compiler also generates a CFI jump table entry for all address-taken functions, the jump table ends up containing a jump to the .rodata section where optprobe_template_func resides, which results in an objtool warning. Use ASM_STACK_FRAME_NON_STANDARD instead to avoid both issues. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- arch/x86/kernel/kprobes/opt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 71425ebba98a..95375ef5deee 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -103,6 +103,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val) asm ( ".pushsection .rodata\n" "optprobe_template_func:\n" + ASM_STACK_FRAME_NON_STANDARD(optprobe_template_func) ".global optprobe_template_entry\n" "optprobe_template_entry:\n" #ifdef CONFIG_X86_64 @@ -154,9 +155,6 @@ asm ( "optprobe_template_end:\n" ".popsection\n"); -void optprobe_template_func(void); -STACK_FRAME_NON_STANDARD(optprobe_template_func); - #define TMPL_CLAC_IDX \ ((long)optprobe_template_clac - (long)optprobe_template_entry) #define TMPL_MOVE_IDX \ From patchwork Thu Sep 30 18:05:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12538011 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56BEAC433F5 for ; Thu, 30 Sep 2021 18:07:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39C2D61164 for ; Thu, 30 Sep 2021 18:07:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353160AbhI3SJK (ORCPT ); Thu, 30 Sep 2021 14:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353163AbhI3SID (ORCPT ); Thu, 30 Sep 2021 14:08:03 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58A2BC06176F for ; Thu, 30 Sep 2021 11:06:11 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id bi20-20020a05620a319400b0045df2735d63so14322994qkb.2 for ; Thu, 30 Sep 2021 11:06:11 -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=YTs3o+Lcv5DCr2QuauAOS05kw4e75hGm1Ap6LaNmDuQ=; b=X2H89x2ZY/Vpdf/BQvunK6wfPqMyb4DEDk9pbiFs6nK3/2FbhHHbrE6V4xLhMLMO72 drYHTD2/KCJ6G99TSY9C0aO1sKa6Of2qEhogYWv2HQTGYu0JWgUpAaLMIJzwMu+or7pa iHk0oBTabObWMRZMT4JZN8w06cBqyUEON9DOp1KFYQGQ3SL+tbs7p/0CMzwj/JX+J6Bv wWym0ky/0NAtPtaaqTZBHkMxxafKQWsjUiZH+m2pu8IQRQNs99qH5Pfj/TWo3mDJ7327 NFrnHKXLRwYMI9ciPDGRpaNES499YGFq66cYMWgu6ugJqzdhsfWL/THEpUxc1niccano aXmw== 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=YTs3o+Lcv5DCr2QuauAOS05kw4e75hGm1Ap6LaNmDuQ=; b=wgfv/lwz84oLqw8Dd9iuz4Ktv9h0BraWn8MJTKdz5VKIU8NpnWJ4WMa7UsKB1hjsbC cIsGjG7yJaxH6Y+rzRp1wojjs6X1naMG0uNqrQYOyKrboid2GEeKxY4KBRluTp1d/w43 uK7xB+KUsLG+lwaFXT0nsErig26Cq3xQv7yHPODtz9mz/a70WDyKk6vJ4tMoEDbsUpyT m2b75rL7z4CPEqOD8+YSWROAEYxwkcrEi0eF4+a366+WEWtx1Hq4We7JCTSvcfXT0tMQ mtR/wwmEb3mSkoBNNtq1TewZVVqiTRqARpumnIr+PqkmZOPWzC21dILVsgCYXzOk1efQ 8SnQ== X-Gm-Message-State: AOAM532o2i0F305HNPMlxnRhRD1PQ5VYaSe//IwRXjMKi112M455DNfq FzZWVSlbc8d5aLLmzwCoJQj0GUcqnuLYS/M9wFA= X-Google-Smtp-Source: ABdhPJxQHjdB5w0u1pGsQKGQzmTIef8NLz4brDiegqDKDUQgvgv1vEwzWyrPFnKCP//0W8Pt+jlJdM7oOGX+dho9Rwo= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:ce43:4366:95ca:d6e9]) (user=samitolvanen job=sendgmr) by 2002:a0c:8e8e:: with SMTP id x14mr5086772qvb.67.1633025170495; Thu, 30 Sep 2021 11:06:10 -0700 (PDT) Date: Thu, 30 Sep 2021 11:05:31 -0700 In-Reply-To: <20210930180531.1190642-1-samitolvanen@google.com> Message-Id: <20210930180531.1190642-16-samitolvanen@google.com> Mime-Version: 1.0 References: <20210930180531.1190642-1-samitolvanen@google.com> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH v4 15/15] x86, build: Allow CONFIG_CFI_CLANG to be selected From: Sami Tolvanen To: x86@kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, Sami Tolvanen Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Select ARCH_SUPPORTS_CFI_CLANG to allow CFI to be enabled with Clang >= 13. Link: https://bugs.llvm.org/show_bug.cgi?id=51588 Signed-off-by: Sami Tolvanen --- arch/x86/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 16e216b57863..ea6d255a125f 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -107,6 +107,7 @@ config X86 select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP if NR_CPUS <= 4096 select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN + select ARCH_SUPPORTS_CFI_CLANG if X86_64 && CLANG_VERSION >= 130000 select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS