From patchwork Tue Oct 8 17:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13826766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D19EBCEFC38 for ; Tue, 8 Oct 2024 17:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=SiZruZgt97P9WSjD6XDTfyKBVOmz7nTMvKt3PIQ/unA=; b=TRY 4cquF28oozgUp6rgxiQTano33GPGixfFBtptgUpOmd40gdKmlweuVTiY7Ww1YyEObTV5DGs61OZUq RjlffKA26byqF+Q1uzxLXBiUXtoqjID1uVKdyMrrcyaHNzJX8UiykcT1fnLKhKI6w4ABmh4AOfOFt pd6NUI8pgvP5UpIdXUzqLSFuCDwMnO+IJGMqNxBTHeTugjeA2NN/cIYLXemFWsbQQvLwUQ7OjZwru ZGkMc2O5iMAHAxjs4nbanKu71JlH/ANznQbkmPnhf+b4edgGYb7cTz9XRK26kxcGGkbCkebV7e/gt OWHDGW/Xmz9tbzyP97NPQCY/uNx6yfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syEGQ-00000006hA0-0Q27; Tue, 08 Oct 2024 17:44:50 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syE9I-00000006fRO-3c8I for linux-riscv@lists.infradead.org; Tue, 08 Oct 2024 17:37:31 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e258c0e02a9so8081369276.3 for ; Tue, 08 Oct 2024 10:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728409046; x=1729013846; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=14kqYH2Lagbmhr3l3ZBauwCKx1YW0pMdZDc5JLpHFBU=; b=nlGREQjJCFq65+No7yY48jxZDC55slgluff8j/Rq4iAExJKoLtpCpHe8mTfz7KcLr8 dljNq5rTds0v9UOANgtQK7mtuCc4HFxhRRRYMeZ1hW5zRbBnVyCMT0SRgKGYxJd+Nvsf PqtA0q9Ygwt4LhWxMgtB/a4sBrm7MizrUWI5avNg2GmsC5ClPw9vSQLUmUbld87PbDVR uCPZfhhIdDyfIbhk38aT59rYQCIfePyevUjMue7Jd0Ri867f/7himDAhfj9oAnURA/AQ NLpTLMBjfXUB1FeDSnh+Wgmem8RxvCP1wtUQBZr88SWBetwwJnQR+iLHJbsa2U8GLpMH chMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728409046; x=1729013846; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=14kqYH2Lagbmhr3l3ZBauwCKx1YW0pMdZDc5JLpHFBU=; b=C3ArRWdMiu2AW55RNSiQ7rQ5UTqGBzX557Tn/jQ6zo9xF0xk2FIP4EZie3wfPg7aQ2 buSgAlINJH7TFTBXoonhIW3kSBy0s5uEuJvXjB9QSAdVEG3/K8dXgaJCcEliBdCkEFlu y8YBiZ4QGCiHkGyKsiWWZNXSCGSw/8Dtvk4eoZLHz8VNgQdbfyyTBSs4PVPrLsCm5PP5 F76kiOIm7G1tLsmC4Opo4rz0HnfHt+lgKysnOoV08/hKzvmFcIaBUPbvyumJJ0G0cEV8 fuS7CPyGcy+St5c4InHtt/oaO67bLq5NhBMl48UmafSqdqjvA615q2vsQ2rNjcXtuXjE 5vSA== X-Forwarded-Encrypted: i=1; AJvYcCU4plFMq/TlUnOnyd4Pi8gfXDc0tQbqwCHG5TRDRJ9BEFPKJhYRFENkEf9wyCz0Te5cUJu6gn6+stpORw==@lists.infradead.org X-Gm-Message-State: AOJu0YykNfySsa2qKHSW/Jr0D+JH2AtYxIJbQygVjpwHUqsarOqW8jS8 tw2sRcDcUoqoAg95NMxaVS5L+hv1XRtNXj/UFPk1tuPycM3YElpLHS8zJXG5LOcc17vTd34bcJf bHsoTR2bL1l+gOw== X-Google-Smtp-Source: AGHT+IEjlJGoTZEIEFPBQWOYQsgcWBNv7STssnAASdis7+wkamn7O6d4OL1Kl7pDAhoyyf9ZnZoeDVErDdxX93A= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:35bd]) (user=aliceryhl job=sendgmr) by 2002:a5b:c01:0:b0:e1a:9ed2:67f4 with SMTP id 3f1490d57ef6-e28936be3c5mr12885276.2.1728409046382; Tue, 08 Oct 2024 10:37:26 -0700 (PDT) Date: Tue, 08 Oct 2024 17:37:16 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAMxtBWcC/x2MWwqAIBAArxL73YKJPegq0cemay1IiUYE0d2TP odh5oHMSTjDWD2Q+JIsx16gqSuwG+0ro7jCoJU2jVIDWi8Y6SxyCYwUAjrnOt23TN54KF1M7OX +n9P8vh+NFNrcYwAAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=3626; i=aliceryhl@google.com; h=from:subject:message-id; bh=iFRkliMPUiFgYsM5i8rizMPhx7zFXxbEfxZZGLUEsWI=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnBW3TsOD5efmx2WY3KxUXdcrbqgeL+draJdGtZ 55RjhOGUyCJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZwVt0wAKCRAEWL7uWMY5 RkQED/4zTm/du53TqD729hkfSVNMwM33H05QLQMm9IROlmKLIVEZCA8ESyRXRRzq8VwbtUqzvg4 LVFE+cW6I0C1POs/RPTyRsXXHl8gKCPXxvKbHf84pnF3BTUAnv5YsSTEyl8dy7LdtHp+q+0VhaI xNY8QUGLB0eNQSg+Y12hu7agtkK2fduxLOYugeGNvlAAVkILawMnojEd9QC+V8T59K7retm0F4o qO75S0/OSRJBSLxQP+elsafKwxYoFinhixO1x1nvX+HtPcTsjsZ2ZFKD8SpViYHOtxOevQLzuap MXwLZWn5z0ecy15jm8oSNNcF1bPYMYyCGN6QZNgrhEGliPuGjZIr41I3Le2UfzWx3ujeY4GeEMH 3lA1wRQSkGinDGVa6eeSywCG7kcVxFv9wqEdD4DpQI+IKCzFB+fEgsvZef6KhMwKiSIRoVsAnrc 6RY1KI1XIPFvL2N2VicgwwNVeIfctHMekpgLtph/Di1mKHcGJBisNrkA8I2cDEin+gOLCateN3T GKoffCCtKIvnRA2hiY+OcfBzx3tfrLGsGB/KVWJMk2rfrK6qtgoDCaCiYgg3+dpx15xFZsYxbSQ rIiZmpyB25viTLbojc9WIxBsefdxAxvV1RxARqd1bI9vsiTuGO/noq84iBRXKwhvM6SfCla1ln5 ls9oM0phnbhLdFA== X-Mailer: b4 0.13.0 Message-ID: <20241008-cfi-patchable-all-v1-1-512481fd731d@google.com> Subject: [PATCH] cfi: rust: pass -Zpatchable-function-entry on all architectures From: Alice Ryhl To: Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Paul Walmsley , Palmer Dabbelt , Albert Ou , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Trevor Gross , Kees Cook , Matthew Maurer , "Peter Zijlstra (Intel)" , Sami Tolvanen Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, rust-for-linux@vger.kernel.org, Alice Ryhl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241008_103728_932947_01B6637C X-CRM114-Status: GOOD ( 14.24 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The KCFI sanitizer stores the CFI tag of a function just before its machine code. However, the patchable-function-entry flag can be used to introduce additional nop instructions before the machine code, taking up the space that normally holds the CFI tag. In this case, a backwards offset is applied to the CFI tag to move them out of the way of the nop instructions. To ensure that C and Rust agree on the offset used by CFI tags, pass the -Zpatchable-function-entry to rustc whenever it is passed to the C compiler. The required rustc version is bumped to 1.81.0 to ensure that the -Zpatchable-function-entry flag is available when CFI is used. Fixes: ca627e636551 ("rust: cfi: add support for CFI_CLANG with Rust") Signed-off-by: Alice Ryhl Reviewed-By: Matthew Maurer Tested-by: WANG Rui Reviewed-by: Sami Tolvanen --- Note that this fix uses rustc-option which has a pending fix: https://lore.kernel.org/all/20241008-rustc-option-bootstrap-v2-1-e6e155b8f9f3@google.com/ --- arch/arm64/Makefile | 2 ++ arch/loongarch/Makefile | 1 + arch/riscv/Makefile | 2 ++ init/Kconfig | 2 +- 4 files changed, 6 insertions(+), 1 deletion(-) --- base-commit: 4a335f920bc78e51b1d7d216d11f2ecbb6dd949f change-id: 20241008-cfi-patchable-all-ddd6275eaf4f Best regards, diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 9efd3f37c2fd..d7ec0bb09fc4 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -143,9 +143,11 @@ CHECKFLAGS += -D__aarch64__ ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS),y) KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY CC_FLAGS_FTRACE := -fpatchable-function-entry=4,2 + KBUILD_RUSTFLAGS += $(call rustc-option,-Zpatchable-function-entry=4$(comma)2) else ifeq ($(CONFIG_DYNAMIC_FTRACE_WITH_ARGS),y) KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY CC_FLAGS_FTRACE := -fpatchable-function-entry=2 + KBUILD_RUSTFLAGS += $(call rustc-option,-Zpatchable-function-entry=2) endif ifeq ($(CONFIG_KASAN_SW_TAGS), y) diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index ae3f80622f4c..f9cef31d1f0e 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -44,6 +44,7 @@ endif ifdef CONFIG_DYNAMIC_FTRACE KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY CC_FLAGS_FTRACE := -fpatchable-function-entry=2 +KBUILD_RUSTFLAGS += $(call rustc-option,-Zpatchable-function-entry=2) endif ifdef CONFIG_64BIT diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index d469db9f46f4..65d4dcba309a 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -16,8 +16,10 @@ ifeq ($(CONFIG_DYNAMIC_FTRACE),y) KBUILD_CPPFLAGS += -DCC_USING_PATCHABLE_FUNCTION_ENTRY ifeq ($(CONFIG_RISCV_ISA_C),y) CC_FLAGS_FTRACE := -fpatchable-function-entry=4 + KBUILD_RUSTFLAGS += $(call rustc-option,-Zpatchable-function-entry=4) else CC_FLAGS_FTRACE := -fpatchable-function-entry=2 + KBUILD_RUSTFLAGS += $(call rustc-option,-Zpatchable-function-entry=2) endif endif diff --git a/init/Kconfig b/init/Kconfig index 530a382ee0fe..43434b681c3f 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1946,7 +1946,7 @@ config RUST depends on !GCC_PLUGIN_RANDSTRUCT depends on !RANDSTRUCT depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE - depends on !CFI_CLANG || RUSTC_VERSION >= 107900 && HAVE_CFI_ICALL_NORMALIZE_INTEGERS + depends on !CFI_CLANG || RUSTC_VERSION >= 108100 && HAVE_CFI_ICALL_NORMALIZE_INTEGERS select CFI_ICALL_NORMALIZE_INTEGERS if CFI_CLANG depends on !CALL_PADDING || RUSTC_VERSION >= 108100 depends on !KASAN_SW_TAGS