Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1013595iob; Fri, 13 May 2022 19:38:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUwdUFTgOKD3/qsN7eh+t/aOZhdWKhnME/SKbkdO2zLmyWOPxPg/e5DHCBeQfOVBjtCm6x X-Received: by 2002:a05:600c:4ecb:b0:394:5be7:791d with SMTP id g11-20020a05600c4ecb00b003945be7791dmr17099965wmq.151.1652495924762; Fri, 13 May 2022 19:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652495924; cv=none; d=google.com; s=arc-20160816; b=eNRoDCDgxnjwyQ/b0CEWiVVE6cN57R4MFjWKsvt40ohWQr7EOU1xId7MGixvLLj6yx VWR5E8pmaBJs36dDVsswMUMNRlYXPnx7CCVhot+jmJaku9NV9v3r6bhF4/+gT3qOjwz7 JyZvzPIQwBfONtvwX1K57qlTlPFKppIXKK9SNDWqvtCDt1jmO2FpTvVKRN7E3Xy+PXAg 2j5ksbf1b9d30Jr7yyv9zJFCgyabsBRJMmjHJWZqRMDBWJwfs5owCYTY0R9wOPi4aZE1 PLiTvoF23BStxEcDhk48urXu7FFWFxXhl2VX57lnGobehXKViK5VoWnim3vEPVy/uk1h I2tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=6CD2+63H+3oTXjdPkyITKV8H4giwswt8mB7LxNoXRYo=; b=zwesG+xKDC6NEsWPtgCh+zJd7+SvL/phZjdWmW+wyGyMjrJIDK3UdstonDhyRqo3SU k+LQpiZqjFYY2NGPyJyqiwnRX5rrvMnPRBNPjT/83JA5BZQoBD2WOneSWkx31R7A3Ws3 +DmYkBwlQkQt/gcrN4oz1SxmZIIP503Jqqx059aOp9NpIFn++Gr76u3Q1c+FkjhfKmw8 RwEK58dtejFThb1iLrBGpTfAMyhXyML9d+eEstzIBgAWCQFeAo8Af8AxRUxugVVHfDdM hQe6ajbSnq0BQ+KUoiyV8qArdYPDP7I3G6dOXCNiSfzWge0xpasJ4e7sfo+7vcmrxW3e 57Ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=r5EVvXQz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o2-20020a5d6842000000b0020aa9a24b54si3168877wrw.929.2022.05.13.19.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:38:44 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=r5EVvXQz; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4C7944FA941; Fri, 13 May 2022 17:49:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1384106AbiEMUWF (ORCPT + 99 others); Fri, 13 May 2022 16:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384091AbiEMUWE (ORCPT ); Fri, 13 May 2022 16:22:04 -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 E32B21514C9 for ; Fri, 13 May 2022 13:22:02 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id m136-20020a25268e000000b0064b233e03d1so8195588ybm.14 for ; Fri, 13 May 2022 13:22:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=6CD2+63H+3oTXjdPkyITKV8H4giwswt8mB7LxNoXRYo=; b=r5EVvXQzvk5eeQ4XlSJKfwGgANH0BdQwZRjaHHspPEGd/UcpZ1b+p/8Op17mjXBG5B UcgVZwJ5FSAz4mYqsfTlF1djzNN482V8ywnJZCKUyxH5fcayYMuZVx/xzzsow1u428aP rY9zVOEl97Yhu+WgmabAaI95fvlWhW0amOdHtf0P1RgSPXUqo7yujhe5u0jcwXtfAUoN pbARbf7Xgsr9e+APQ8y7txcpe+VK39r8ASkwIWJO4920xmEhxFC4hL1jGf8cUEw0pymm 1Z+FrPtkUzeQHNNBxxbR4A9JRHS4ZuRIlKi1sF+NHM3jSvYeGoE9PrWzK49N5G2jhpQd vRug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=6CD2+63H+3oTXjdPkyITKV8H4giwswt8mB7LxNoXRYo=; b=fJW1oKh6vuU5qbImMgh3eRNoDy+hWzZRyLuLz3tjXV5LWzbJqui//J3Se9QiQCnqUs S0hwSfj5Sou3RVSWCQxdQMq1HWAeYIFNeVW9kLujLkJMUy9c3SNKuvhGpWzB9oiNlrJ6 OZ07d2JpigcS845zDd1EV2PC5XUfsz9MVpxjzT5gADe7BMlCGQsK4kZ8Xf6Gr+b/KzKI /P+ul1VcNuE4rmw6360XfvnZUiEp8tQ9yNTaVrGlgXZChfgLiWM1Lh1GHVXEQFfZi83g vB3B0WfqDs6/qctEhTDNZIQv8RlDZ08pwTx8qm3GSgvZQ8ne625BU27um6FONc7eHbTj ZY5Q== X-Gm-Message-State: AOAM530TorvE5CMKMyEOB6MDc1Y8BvA/mhEEH6UvVD05lHJFtb1nCHzC uKMJUQonogoj+FyuNBhtO0RJ8dWeyVlebj68Ux+th0efUzQnffNq+bEJl4urNyjcCba+PvLBfxT OHV+aWZxzjr+5uJCIBkn2WicgEgUGYVcVOyyHiGylK/Dd0TddeNejNvn5ZK08AiFPHTWTESDwp/ 0NrjRoXYD2vA== X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:e0:c17e:c2dc:13eb]) (user=samitolvanen job=sendgmr) by 2002:a81:7746:0:b0:2fe:b79e:dd21 with SMTP id s67-20020a817746000000b002feb79edd21mr4376368ywc.97.1652473321844; Fri, 13 May 2022 13:22:01 -0700 (PDT) Date: Fri, 13 May 2022 13:21:38 -0700 Message-Id: <20220513202159.1550547-1-samitolvanen@google.com> Mime-Version: 1.0 X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=5033; h=from:subject; bh=QQHZw+nNC3sat5hCbK/dHVOrwEpFv/dcBv8rUGfmodE=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBifr3izuj6onoCVuVAqVb7kGKi7/2NqgwMnFWBknHE pazR+TaJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYn694gAKCRBMtfaEi7xW7nTvC/ 0YeKprfOIH2lFwOEA0eV7IhrhzJnfzOacgxhF8m4gP3pX12d+c0mbY6LaI2TeqHUzmQ/qQVJCbUzed qYGHRtsqq5a1hWR34gMu84GY/VOmXf4HVNCY9Mr0EXKJGFRCORkGxwj5VgShEctPN7xlpzWhj9FSYQ TQpw7TbpV4gvBIzmJ6HlBPMeXAjn8Rw2OsKEmUTiLuTeHD8JNqWopZZiMLs7NptwBdLB5oirOM4hTH fPZ7LcF8aoBKDxQDK583B3fZQ39VGvUEKZSYsiEoGgMQ5ZGbwk84gmyuFzhwCztm16peP2twyeVgD3 WAlgpVrY79VA3j63rGjXh0dj9nAhe6vyQJMm13fOSGcAs1+kYBAxIlFIVhdqoHnLUgXqNMkb7KTzy4 wnCKrZHKvkMRSI4wZR6WdCSPkDWfq5GZMeziUruqhuc5vWqbSN21sjy3udNEPn/iebzu6GOUi6i5cv Vl4j8vDNBqAfPbc0owmH9iQAna1UfIaw1ochzhxveFUDI= X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [RFC PATCH v2 00/21] KCFI support 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KCFI is a proposed forward-edge control-flow integrity scheme for Clang, which is more suitable for kernel use than the existing CFI scheme used by CONFIG_CFI_CLANG. KCFI doesn't require LTO, doesn't alter function references to point to a jump table, and won't break function address equality. The latest LLVM patch is here: https://reviews.llvm.org/D119296 This RFC series replaces the current arm64 CFI implementation with KCFI and adds support for x86_64. KCFI requires assembly functions that are indirectly called from C code to be annotated with type identifiers. As type information is only available in C, the compiler emits expected type identifiers into the symbol table, so they can be referenced from assembly without having to hardcode type hashes. Patch 7 adds helper macros for annotating functions, and patches 9 and 17 add annotations. In case of a type mismatch, KCFI always traps. To support error handling, the compiler generates a .kcfi_traps section for x86_64, which contains the locations of each trap, and for arm64, encodes the necessary register information to the ESR. Patches 10 and 20 add arch-specific error handlers. To test this series, you'll need to compile your own Clang toolchain with the patches linked above. You can also find the complete source tree here: https://github.com/samitolvanen/llvm-project/commits/kcfi-rfc-v2 This series is also available in GitHub: https://github.com/samitolvanen/linux/commits/kcfi-rfc-v2 Sami Tolvanen (21): efi/libstub: Filter out CC_FLAGS_CFI arm64/vdso: Filter out CC_FLAGS_CFI kallsyms: Ignore __kcfi_typeid_ cfi: Remove CONFIG_CFI_CLANG_SHADOW cfi: Drop __CFI_ADDRESSABLE cfi: Switch to -fsanitize=kcfi cfi: Add type helper macros psci: Fix the function type for psci_initcall_t arm64: Add types to indirect called assembly functions arm64: Add CFI error handling arm64: Drop unneeded __nocfi attributes treewide: Drop function_nocfi treewide: Drop WARN_ON_FUNCTION_MISMATCH treewide: Drop __cficanonical objtool: Don't warn about __cfi_ preambles falling through x86/tools/relocs: Ignore __kcfi_typeid_ relocations x86: Add types to indirectly called assembly functions x86/purgatory: Disable CFI x86/vdso: Disable CFI x86: Add support for CONFIG_CFI_CLANG init: Drop __nocfi from __init Makefile | 13 +- arch/Kconfig | 21 +- arch/arm64/crypto/ghash-ce-core.S | 5 +- arch/arm64/crypto/sm3-ce-core.S | 3 +- arch/arm64/include/asm/brk-imm.h | 6 + arch/arm64/include/asm/compiler.h | 16 - arch/arm64/include/asm/ftrace.h | 2 +- arch/arm64/include/asm/mmu_context.h | 4 +- arch/arm64/kernel/acpi_parking_protocol.c | 2 +- arch/arm64/kernel/alternative.c | 2 +- arch/arm64/kernel/cpu-reset.S | 5 +- arch/arm64/kernel/cpufeature.c | 4 +- arch/arm64/kernel/ftrace.c | 2 +- arch/arm64/kernel/machine_kexec.c | 2 +- arch/arm64/kernel/psci.c | 2 +- arch/arm64/kernel/smp_spin_table.c | 2 +- arch/arm64/kernel/traps.c | 46 ++- arch/arm64/kernel/vdso/Makefile | 3 +- arch/arm64/mm/proc.S | 5 +- arch/x86/Kconfig | 2 + arch/x86/crypto/blowfish-x86_64-asm_64.S | 5 +- arch/x86/entry/vdso/Makefile | 3 +- arch/x86/include/asm/linkage.h | 12 + arch/x86/kernel/traps.c | 60 +++- arch/x86/lib/memcpy_64.S | 3 +- arch/x86/purgatory/Makefile | 4 + arch/x86/tools/relocs.c | 1 + drivers/firmware/efi/libstub/Makefile | 2 + drivers/firmware/psci/psci.c | 6 +- drivers/misc/lkdtm/usercopy.c | 2 +- include/asm-generic/bug.h | 16 - include/asm-generic/vmlinux.lds.h | 37 +-- include/linux/cfi.h | 65 ++-- include/linux/cfi_types.h | 57 ++++ include/linux/compiler-clang.h | 6 +- include/linux/compiler.h | 16 +- include/linux/compiler_types.h | 4 - include/linux/init.h | 6 +- include/linux/module.h | 10 +- include/linux/pci.h | 4 +- kernel/cfi.c | 343 ++++------------------ kernel/kthread.c | 3 +- kernel/module.c | 49 +--- kernel/workqueue.c | 2 +- scripts/kallsyms.c | 1 + scripts/module.lds.S | 23 +- tools/objtool/check.c | 4 + 47 files changed, 357 insertions(+), 534 deletions(-) create mode 100644 include/linux/cfi_types.h -- 2.36.0.550.gb090851708-goog