From patchwork Thu Sep 8 21:54:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970694 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 7A2E6C38145 for ; Thu, 8 Sep 2022 21:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MzkkupVLKI8S1fn95XLT6XD1zJ4O9K47zGKWMaSnHeY=; b=S0GxgH1PaDFH/t8EP6oMILXIHn 8zIJM5uQ86aXktE0HR28YfjTAzkxjFojHtk8vCyzH5G+e7l3kWNuU1Ex1jaH6r7r4CY8+QZtEpZTs y6/Si/Vb81fgdhOCKrR7dj05O+XcHBuGz5o59BFkiAU4XtfHl4Y41LSiHHo4qSMxwUQ4XBhcnER38 cCnPRl0jDn8b95plmJb0HKkePpgH2H6X1poUd2m2Z7IqH5S5RX/oWeeySBExm//RL8MsqYvs9Ku6W YhZnEf6Tjr+6YtfuRnO+O7mgeaXknEHnNA6hPJqKj5pv2p1MJ58H9eGhjFvWWoGY/kBjuGPLOjbHL bkqJcLfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUZ-00950T-Nh; Thu, 08 Sep 2022 21:55:23 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUN-0094uY-Hd for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:12 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j11-20020a05690212cb00b006454988d225so9024ybu.10 for ; Thu, 08 Sep 2022 14:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=++1/qtdOmwUSaxqgiZQTBSEYvAxbI4XHV6GATm9VhUE=; b=DAxdaA/TeHYFNkGxc72IwSwNKQuOykXTJDQORvATjh5oTgcXipGkVmqfycb+PUS8Wp SXGLVEnuzt4Ps6Cp3jiSeQ9/bxkrOwHccGPNwXMZ4cOSpTui8APRzBdyggwyYN3bpUBU csqHhnCeJ1j65G97AeYq/khlWiDGhXIxKGbBc5NpejjSwqU8L1EmcqUWr8+5Rvz54bQa 6fjvp8eKwXpdwITxvySX9EurH7B9DSaYc1UZa4+fZqlKfV788bJDzyLxtjPFogWibp84 y3PzkRHda3kd1F0KGkBO4FaaSRROQQWwIa2Op7LMzexNluxxyA67slpTBOHo/cuaH5Xk CKkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=++1/qtdOmwUSaxqgiZQTBSEYvAxbI4XHV6GATm9VhUE=; b=NxgFs50e1z+kQDGfAhB9ctfsEo6Qk3mY2XLtKVo93QN50e5SYU1iuyj/JPc6xdiwQi amYfgbfvhH/xc5QxaXLxhOF7Q1RUUcmsN99IXGTdDhJrRwozXEEfXTjWA1fG/uQ/RRH9 Q/Ef5vv4znNiYuhDlaJcS1X68NGMpIIZQXeU5KtoF569jaIeFEJkuULkV4XgIFJIb5Hr 1Og4mZNNSFSnjr+Xitf6pzGMSfqdcsRFtPgJvmXoHVtleDFiRzQ+YwJWTk+rmrHBS47y MrUTxvjDzy6C0lQQLqmt4J4T4ewg5jg4bGqiJpZP6AfoA3/MzpvfEH/26Zw3ERTpakwq adxg== X-Gm-Message-State: ACgBeo0uum6mdcDHzZFYvKaLo9zkq9PZLRnBIa1dvD6dWihvqTCzLZfd xeZT3Z3m9Jex5Wt3euhvs85XBzZlS7keYkZ/rgg= X-Google-Smtp-Source: AA6agR7Urz8mEtWhFvoUwvvdWySJPZQ7jqpog2D5kyDc+2eNo1L58ipOybnpuwS7VRcYjJKRoWU3GYlVidDt0EeoNs0= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a0d:f904:0:b0:345:4639:8253 with SMTP id j4-20020a0df904000000b0034546398253mr9771674ywf.438.1662674109557; Thu, 08 Sep 2022 14:55:09 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:43 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-2-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3048; i=samitolvanen@google.com; h=from:subject; bh=NqOg6IoR6gX09sXAr0B0cPUiAt3ZJYmbQkr2LJPJNus=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSyAhdY+c0yuGLwUcRxL94Fo3kpoLG9gssQn6xK 0NRN0dKJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpksgAKCRBMtfaEi7xW7snLC/ 4kqxfaphRvYnLEvON3wLCWq1o1yoypBX3QcocACz45p22AS2T5hfosvQm9Qoq55kO7fEf6uzqBQuMQ kGIPv/gs/+9O5Id/51exiQCxLR2ReTQngCFQ10xRIwfcsM/z45xAQ4nusTdRGj0bHv2gAdmNAXFZ+R oJkA10VfP80fqUgAUn0+WpEv6rnxzPuorF9bqiXWBrChAAtoLY5p41e3AExfZGMMh7qKArwCJMFqFB y/qs9kY9bk7UdIiNxvzvQmkkzRuNJHtI+Sea40LsKjqkiJ7eQQfMAeEbh2ArJDRu/sBdGkzhU2zhS1 Y5SHy5RY9gHiNRwadqeXZhe5TTujjTecKJG/HZPk8XNU1EizECc1s+y10rNiGBUlVhI0MRI1NL24fK qE0JNaiWlsv2WhYZN6SZ32uY130fpB+FjtHg+/0bVXbfmrvraFK+7dE4e8P3E6F3RvBWXa0RdHztpF 730W9Oi74vsIeysCfW1gRdtm+goTa2x0/ontLouoIJkP4= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 01/22] treewide: Filter out CC_FLAGS_CFI From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145511_605300_FE62831D X-CRM114-Status: GOOD ( 11.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation for removing CC_FLAGS_CFI from CC_FLAGS_LTO, explicitly filter out CC_FLAGS_CFI in all the makefiles where we currently filter out CC_FLAGS_LTO. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/arm64/kernel/vdso/Makefile | 3 ++- arch/x86/entry/vdso/Makefile | 3 ++- drivers/firmware/efi/libstub/Makefile | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile index bafbf78fab77..619e2dc7ee14 100644 --- a/arch/arm64/kernel/vdso/Makefile +++ b/arch/arm64/kernel/vdso/Makefile @@ -40,7 +40,8 @@ ccflags-y += -DDISABLE_BRANCH_PROFILING -DBUILD_VDSO # kernel with CONFIG_WERROR enabled. CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) -Os $(CC_FLAGS_SCS) \ $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) \ - $(CC_FLAGS_LTO) -Wmissing-prototypes -Wmissing-declarations + $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) \ + -Wmissing-prototypes -Wmissing-declarations KASAN_SANITIZE := n KCSAN_SANITIZE := n UBSAN_SANITIZE := n diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index 12f6c4d714cd..381d3333b996 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -91,7 +91,7 @@ ifneq ($(RETPOLINE_VDSO_CFLAGS),) endif endif -$(vobjs): KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO) $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) +$(vobjs): KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO) $(CC_FLAGS_CFI) $(RANDSTRUCT_CFLAGS) $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) $(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO # @@ -153,6 +153,7 @@ KBUILD_CFLAGS_32 := $(filter-out $(RANDSTRUCT_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS_32)) +KBUILD_CFLAGS_32 := $(filter-out $(CC_FLAGS_CFI),$(KBUILD_CFLAGS_32)) KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic KBUILD_CFLAGS_32 += -fno-stack-protector KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls) diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile index 2c67f71f2375..b43fdb319fd4 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -46,6 +46,8 @@ KBUILD_CFLAGS := $(filter-out $(RANDSTRUCT_CFLAGS), $(KBUILD_CFLAGS)) # remove SCS flags from all objects in this directory KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_SCS), $(KBUILD_CFLAGS)) +# disable CFI +KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_CFI), $(KBUILD_CFLAGS)) # disable LTO KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO), $(KBUILD_CFLAGS)) From patchwork Thu Sep 8 21:54:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970696 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 4BD85C54EE9 for ; Thu, 8 Sep 2022 21:56:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZUqsanQQqGpgZzq7ytBB02jnVayHAjSA+oaphY3EN1s=; b=I3iGK0eFnUmd/SP6MJDEaBhDsd nzibhLU14ocXMQmszFOb4ZIQw++PZKF+HyGjFa2LpSOmiJQYWeCCUtXDo1AdROqp4aUDZ+9BnTP99 +wHqCtNgsv5jS7h/ty6J3W6S7OG2JoPclCcxynS8tzrFZjHCnfxhk+2/9kmriiPuikRkaM6xnEhc3 YXL5t6QySn+aoKwRfZ0pOZjkChRavtjUNJ2ATHaDBysT/emoVwDb4FGW0hTP+52Kbt5Jp4CpejHkK TQt+nHJ4AInJ3TdJk1oiVxJWphHc5UqbLyH6iW0JfQQwRYCpYPKA8w897AjmHRWssdVa+0iPgSLD0 v1xzcuug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUl-00958P-Mn; Thu, 08 Sep 2022 21:55:35 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUP-0094vM-Fo for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-344f79c2dc9so143117667b3.15 for ; Thu, 08 Sep 2022 14:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=E5MP4taEQT0v3MmrVmyzRF+/DATosXuoXnrYsLQHUt8=; b=L0Iv4WoX7t7oX0WurXOJImKj4FKAQ7re2UnLEhWMqBVV2Fb5NfTnuW2Td8go+/9K6n SkH9GL97wuofrg9xGkIn5kyIhAmBJAxgkLl96Z8R1Hjdeepd7iLXs16r2vNEOmNfB6NN pYrZR4o/znOy912UFas2yKeS6IxtwYS6F8YZh49Y9glgRCjElvb2XKYZ6p18HeHKrID7 gF5K1Aj4DpSyZHEytLRiRo0RwLicqziomG+WI7ZrmK+m7giLGz5jMh+TDkwJpV28iRCk HI/6sbkn6jWBGV6ukL1Xo4ySP8vpvjZEZELv9aNq/CpXKxA+cVnME5odPvthvt74Vh8t PlSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=E5MP4taEQT0v3MmrVmyzRF+/DATosXuoXnrYsLQHUt8=; b=w/lyESLm+wdKdZug42KUYcEVx1ytYc+DN9FHIuDcGjxEH5N2Wp1P4vKP712CuZTX7O ZESABjX2leu7YuDrgpV+TWglC8HnDKpFK9tZDKBEFSGwEeZTXCLPv+CbA98oKNfi3AIH skQuIdRD0/rTvkMXp2l3mIXgvnGpoTnfgJxFWoSVgXc/155TUfC3MvDxePbczuOYI4f1 jrR1uqAioDCV5xb6F5GStP4n2ns4HSGtLngpYyyGAsNzV08ZBM9F9JpzA/HI5TTZLmK7 4bTDcYQ++0ni6lcq6uxk4cQ6JMf7fR0cFXNZMkUb010sAnAc6mIQ/Qf3OYf+bJUjAIto Vm6A== X-Gm-Message-State: ACgBeo1BrrpsJZBbofujvMV0cQf3dyQC7N5VLmBzrRmd6U5IxOZiVBnS JEIUNXJuEFes5A6HP+tsKtSpu7p7OY3Hfw5MgBQ= X-Google-Smtp-Source: AA6agR405k5ikQwnvuDn5SVwnN6wLe5SN+NO6wYS+1bv3HntlAG2SOkyPiCtLnlkgBLkiab70NT9z3nfmFmzqG8/h4w= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a25:e401:0:b0:66e:280a:98cd with SMTP id b1-20020a25e401000000b0066e280a98cdmr9395449ybh.540.1662674112156; Thu, 08 Sep 2022 14:55:12 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:44 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-3-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=911; i=samitolvanen@google.com; h=from:subject; bh=Lh36Gb4BQjSISqwOnlA1V8paDgitJ+WqG6DvavOOD2s=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSzrVY+vd10oEbk9xRXIoCFu1ml2ON/ucyrRCLU kFTNLaaJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpkswAKCRBMtfaEi7xW7vDdC/ 0T+hmkD8EM0RGtayG8NWtUqkvZSj8cNhp4JVPo0ZmXjPbKX0vB4cnrvRNfMCAxxWkXMiyIOjn7rlCU ZT0vqj0O4durfcDKdeoLvdOpmgmdpHgeuGIjsJ6Bqg/jOiZ9BRWRbkeblhhIkdJYQ3zI7S20k1kjFd juV/s45NYG82Qds/KpEHXqoyNySmSHrowOYqaUonQv0u+PklBZpEIup6A5zb3x/lMx79rtigk0VOIY eSXbPLsufZXtaU7R+VIcyMoovGSY+rkYZx87gGozk1NcVMZONyXqiKnH0giKpRZYXyl8w2cnxubMVF SP2csMdnJJfFebE62u8kNREg86O2VLozoKYT9wYD3c0u9hCqJ7R/xjsqrA2wmQ955d27tD0zmjg0Db N+VwhZoKY+QMxOSysQScJ8GNMEv26OEHYdgsVW3ptZoDLv9draG1Lpyu1Hmgscmc0wyrHsn7UMpIDy 18ZZT/0e58vrIeERnxIJd+NH1H+wNp9jN1zHiWOlpKV0s= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 02/22] scripts/kallsyms: Ignore __kcfi_typeid_ From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145513_558033_6046C1B0 X-CRM114-Status: GOOD ( 10.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The compiler generates __kcfi_typeid_ symbols for annotating assembly functions with type information. These are constants that can be referenced in assembly code and are resolved by the linker. Ignore them in kallsyms. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- scripts/kallsyms.c | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index f18e6dfc68c5..ccdf0c897f31 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -119,6 +119,7 @@ static bool is_ignored_symbol(const char *name, char type) "__ThumbV7PILongThunk_", "__LA25Thunk_", /* mips lld */ "__microLA25Thunk_", + "__kcfi_typeid_", /* CFI type identifiers */ NULL }; From patchwork Thu Sep 8 21:54:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970697 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 A04A1C6FA82 for ; Thu, 8 Sep 2022 21:56:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0xM/Oe6r2/0ShUMpawNzXMHYitb4+EarSpEXaI3gRb4=; b=OSw0u6PQ/SodjGI6sHx1d64Q70 SNTazkU6AxGYxCo8t+fcbwrVsyAdOaA6IjV8RBmp27SJsVpwh3IdE9/XyE3Vr+MPDZDbQhxT+qPrf Efj3jr+qXhvxKiA/DaJZoUO6sOHmJEgont397FIvVmdsVakIb1ckZj3cUvrJLMdwEMhvwnSsiST+q SuQO7NxqPBabdbxuBwxvi0/WZ6FlN0ob8VQax6aZooA2AfPR5zVl8/BGeq49USkTyU8aX6DtIe9iW 4vnkpCZdIJL58S+GRjMaExp5CNK0XtrC7X9QKHhBoWdyamxvuEN4M1flED3UOaO+X+141iGrRzqlp uE9/HDQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUv-0095Bw-3h; Thu, 08 Sep 2022 21:55:45 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUS-0094wW-5c for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:18 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-340ae84fb7dso155059127b3.17 for ; Thu, 08 Sep 2022 14:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=NnVV6DTSn3h1DOdTYpHix9zNDIsBWjDQwEgm7WMNa8o=; b=BNenGge5SUwNwtXbkTCyPNFwIVsej/BpXEqBSFZ1Ao8D6PzUX4mQhT2QaqSn+Ty5wx YMcyOidGuKnAMzQ82jKYgDsguo7KcngWE6V/iAuV3riYpmBFEmzHNW7C6slUHiBbfpKl VnUVxF5BQMJ1kqgFN/WEFrDKE6L7XhNKOIxthP3j4JvAwN0Inx7djsdcm8DFcDKKWCxU GzQk1iYQF2OQlyccrX/o7wddl4mG3js6SPOReZ0GrU/xhmdCd983nI0hYJCd/QHr2CXd cb7okIcKhksT5NJhfzCVs3YQFb9RdbYMILHQdDEego3+nBq2lRTsk7e5b7LH/xTRExxZ STOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=NnVV6DTSn3h1DOdTYpHix9zNDIsBWjDQwEgm7WMNa8o=; b=Di2vehmNGLZ5xN1bYr8KoNvrqNZs/rcHqyWfD4T4OdKA7kJLv9mnakKNzrba6Pp96d WuHOvQo1PYHCuEq0WnyEjyr+h3Zgh7f3hTdJj/Vdg3N6PC5Gu7dEnb0l13fg6PNSPVEw aBd4vYoOi5DKM1iWHlqn9yfc3nLXJKBNTzkRdMcUIVMzc+pem6KM8FdCXI7ca3Q5Bq10 wzIwNexTE9iGOLERaW1voJ+I7K3s5t9GxE7UwJvMagvT0zrCUy8GwlAwjisQA7LoRVO2 C12YT5W9tk/H38HXOJza/ptWSGfLHeqnwXIBNMld2UEiuuIagQV0CP/CQD0nDhCVEt/w DsaQ== X-Gm-Message-State: ACgBeo24mR7OfKgf6GNivy4Sb4dPupZJ+hlEk0xjsKED20FrWqDNUmvU BSGR0chRUJY68wKgEr2EqPQXCqCYJlRO0ZeIKEA= X-Google-Smtp-Source: AA6agR6TYyAH85tqugJj1yijMu0EJeXMe93YNQ3Lr1PF7LS9QEk/o3QyLGJ5l5d325CYnFU1XVX1099eHj8op/mP7ls= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a0d:fa41:0:b0:348:7dc3:760a with SMTP id k62-20020a0dfa41000000b003487dc3760amr7026978ywf.106.1662674114778; Thu, 08 Sep 2022 14:55:14 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:45 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=10481; i=samitolvanen@google.com; h=from:subject; bh=UTZgCNN6nFOYuwWv/8NsOLwF8a+iUTF7XgJLM/G80Do=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSzGK9zjlWkYVC46zGoyD+9vaO2YMOksqto1BHN 17EXxXCJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpkswAKCRBMtfaEi7xW7milC/ 922p3yw6iPjuTLhIFuvSMD/7TKtaxymIETTN2upWH0OYR7sjdbZ0H7S3qDxTpLMjy89i3QABNZ4CSN yEHDjoH19M/ifH+cM+SyIj0NmGqUfoyUCLUy5yoP1UE2SWQsIPRdYCgwxyremRzggnBen+6tTPyONd bo+CGaQZqWuku9R5zQ6VZM4liTpGAO8pqd923H9aj9OF1NUv55QSvfrf1LwHs8eGdJ1nhbGmxmuJEp V55Oi9wAAlBKUpr2TU5/iW8ly8oAAHBrWTCLMaLJp4cFHGdW9CAnP0DwCbyVSoh15bHFZAQm2A33UJ PH2C3H/MHRoSQAzo6aozbuGwi/eEZXtK+yBkl0woIaKvsR7QG8ry/Ju+duizFlI6n7mSSHHMtz8NgG Vlrng9Yf/AwIYnC5f4P3opmwQu3fU2vRRMmYVsrx7XGGXHCWNq5tz4cwslycnJ7nXTSMZglszL1w3J 5mYNzLsVs7JPE6fuprWVxJpDDXZZorCI3hYDwEnmmHhaQ= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 03/22] cfi: Remove CONFIG_CFI_CLANG_SHADOW From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145516_239433_68345DE9 X-CRM114-Status: GOOD ( 27.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In preparation to switching to -fsanitize=kcfi, remove support for the CFI module shadow that will no longer be needed. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/Kconfig | 10 -- include/linux/cfi.h | 12 --- kernel/cfi.c | 236 +------------------------------------------ kernel/module/main.c | 15 --- 4 files changed, 1 insertion(+), 272 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 5dbf11a5ba4e..5fd875e18c99 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -754,16 +754,6 @@ config CFI_CLANG https://clang.llvm.org/docs/ControlFlowIntegrity.html -config CFI_CLANG_SHADOW - bool "Use CFI shadow to speed up cross-module checks" - default y - depends on CFI_CLANG && MODULES - help - If you select this option, the kernel builds a fast look-up table of - CFI check functions in loaded modules to reduce performance overhead. - - If unsure, say Y. - config CFI_PERMISSIVE bool "Use CFI in permissive mode" depends on CFI_CLANG diff --git a/include/linux/cfi.h b/include/linux/cfi.h index c6dfc1ed0626..4ab51c067007 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -20,18 +20,6 @@ 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 -#ifdef CONFIG_CFI_CLANG_SHADOW - -extern void cfi_module_add(struct module *mod, unsigned long base_addr); -extern void cfi_module_remove(struct module *mod, unsigned long base_addr); - -#else - -static inline void cfi_module_add(struct module *mod, unsigned long base_addr) {} -static inline void cfi_module_remove(struct module *mod, unsigned long base_addr) {} - -#endif /* CONFIG_CFI_CLANG_SHADOW */ - #else /* !CONFIG_CFI_CLANG */ #ifdef CONFIG_X86_KERNEL_IBT diff --git a/kernel/cfi.c b/kernel/cfi.c index 2046276ee234..e8bc1b370edc 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -32,237 +32,6 @@ static inline void handle_cfi_failure(void *ptr) } #ifdef CONFIG_MODULES -#ifdef CONFIG_CFI_CLANG_SHADOW -/* - * Index type. A 16-bit index can address at most (2^16)-2 pages (taking - * into account SHADOW_INVALID), i.e. ~256M with 4k pages. - */ -typedef u16 shadow_t; -#define SHADOW_INVALID ((shadow_t)~0UL) - -struct cfi_shadow { - /* Page index for the beginning of the shadow */ - unsigned long base; - /* An array of __cfi_check locations (as indices to the shadow) */ - shadow_t shadow[1]; -} __packed; - -/* - * The shadow covers ~128M from the beginning of the module region. If - * the region is larger, we fall back to __module_address for the rest. - */ -#define __SHADOW_RANGE (_UL(SZ_128M) >> PAGE_SHIFT) - -/* The in-memory size of struct cfi_shadow, always at least one page */ -#define __SHADOW_PAGES ((__SHADOW_RANGE * sizeof(shadow_t)) >> PAGE_SHIFT) -#define SHADOW_PAGES max(1UL, __SHADOW_PAGES) -#define SHADOW_SIZE (SHADOW_PAGES << PAGE_SHIFT) - -/* The actual size of the shadow array, minus metadata */ -#define SHADOW_ARR_SIZE (SHADOW_SIZE - offsetof(struct cfi_shadow, shadow)) -#define SHADOW_ARR_SLOTS (SHADOW_ARR_SIZE / sizeof(shadow_t)) - -static DEFINE_MUTEX(shadow_update_lock); -static struct cfi_shadow __rcu *cfi_shadow __read_mostly; - -/* Returns the index in the shadow for the given address */ -static inline int ptr_to_shadow(const struct cfi_shadow *s, unsigned long ptr) -{ - unsigned long index; - unsigned long page = ptr >> PAGE_SHIFT; - - if (unlikely(page < s->base)) - return -1; /* Outside of module area */ - - index = page - s->base; - - if (index >= SHADOW_ARR_SLOTS) - return -1; /* Cannot be addressed with shadow */ - - return (int)index; -} - -/* Returns the page address for an index in the shadow */ -static inline unsigned long shadow_to_ptr(const struct cfi_shadow *s, - int index) -{ - if (unlikely(index < 0 || index >= SHADOW_ARR_SLOTS)) - return 0; - - return (s->base + index) << PAGE_SHIFT; -} - -/* Returns the __cfi_check function address for the given shadow location */ -static inline unsigned long shadow_to_check_fn(const struct cfi_shadow *s, - int index) -{ - if (unlikely(index < 0 || index >= SHADOW_ARR_SLOTS)) - return 0; - - if (unlikely(s->shadow[index] == SHADOW_INVALID)) - return 0; - - /* __cfi_check is always page aligned */ - return (s->base + s->shadow[index]) << PAGE_SHIFT; -} - -static void prepare_next_shadow(const struct cfi_shadow __rcu *prev, - struct cfi_shadow *next) -{ - int i, index, check; - - /* Mark everything invalid */ - memset(next->shadow, 0xFF, SHADOW_ARR_SIZE); - - if (!prev) - return; /* No previous shadow */ - - /* If the base address didn't change, an update is not needed */ - if (prev->base == next->base) { - memcpy(next->shadow, prev->shadow, SHADOW_ARR_SIZE); - return; - } - - /* Convert the previous shadow to the new address range */ - for (i = 0; i < SHADOW_ARR_SLOTS; ++i) { - if (prev->shadow[i] == SHADOW_INVALID) - continue; - - index = ptr_to_shadow(next, shadow_to_ptr(prev, i)); - if (index < 0) - continue; - - check = ptr_to_shadow(next, - shadow_to_check_fn(prev, prev->shadow[i])); - if (check < 0) - continue; - - next->shadow[index] = (shadow_t)check; - } -} - -static void add_module_to_shadow(struct cfi_shadow *s, struct module *mod, - unsigned long min_addr, unsigned long max_addr) -{ - int check_index; - unsigned long check = (unsigned long)mod->cfi_check; - unsigned long ptr; - - if (unlikely(!PAGE_ALIGNED(check))) { - pr_warn("cfi: not using shadow for module %s\n", mod->name); - return; - } - - check_index = ptr_to_shadow(s, check); - if (check_index < 0) - return; /* Module not addressable with shadow */ - - /* For each page, store the check function index in the shadow */ - for (ptr = min_addr; ptr <= max_addr; ptr += PAGE_SIZE) { - int index = ptr_to_shadow(s, ptr); - - if (index >= 0) { - /* Each page must only contain one module */ - WARN_ON_ONCE(s->shadow[index] != SHADOW_INVALID); - s->shadow[index] = (shadow_t)check_index; - } - } -} - -static void remove_module_from_shadow(struct cfi_shadow *s, struct module *mod, - unsigned long min_addr, unsigned long max_addr) -{ - unsigned long ptr; - - for (ptr = min_addr; ptr <= max_addr; ptr += PAGE_SIZE) { - int index = ptr_to_shadow(s, ptr); - - if (index >= 0) - s->shadow[index] = SHADOW_INVALID; - } -} - -typedef void (*update_shadow_fn)(struct cfi_shadow *, struct module *, - unsigned long min_addr, unsigned long max_addr); - -static void update_shadow(struct module *mod, unsigned long base_addr, - update_shadow_fn fn) -{ - struct cfi_shadow *prev; - struct cfi_shadow *next; - unsigned long min_addr, max_addr; - - next = vmalloc(SHADOW_SIZE); - - mutex_lock(&shadow_update_lock); - prev = rcu_dereference_protected(cfi_shadow, - mutex_is_locked(&shadow_update_lock)); - - if (next) { - next->base = base_addr >> PAGE_SHIFT; - prepare_next_shadow(prev, next); - - min_addr = (unsigned long)mod->core_layout.base; - max_addr = min_addr + mod->core_layout.text_size; - fn(next, mod, min_addr & PAGE_MASK, max_addr & PAGE_MASK); - - set_memory_ro((unsigned long)next, SHADOW_PAGES); - } - - rcu_assign_pointer(cfi_shadow, next); - mutex_unlock(&shadow_update_lock); - synchronize_rcu(); - - if (prev) { - set_memory_rw((unsigned long)prev, SHADOW_PAGES); - vfree(prev); - } -} - -void cfi_module_add(struct module *mod, unsigned long base_addr) -{ - update_shadow(mod, base_addr, add_module_to_shadow); -} - -void cfi_module_remove(struct module *mod, unsigned long base_addr) -{ - update_shadow(mod, base_addr, remove_module_from_shadow); -} - -static inline cfi_check_fn ptr_to_check_fn(const struct cfi_shadow __rcu *s, - unsigned long ptr) -{ - int index; - - if (unlikely(!s)) - return NULL; /* No shadow available */ - - index = ptr_to_shadow(s, ptr); - if (index < 0) - return NULL; /* Cannot be addressed with shadow */ - - return (cfi_check_fn)shadow_to_check_fn(s, index); -} - -static inline cfi_check_fn find_shadow_check_fn(unsigned long ptr) -{ - cfi_check_fn fn; - - rcu_read_lock_sched_notrace(); - fn = ptr_to_check_fn(rcu_dereference_sched(cfi_shadow), ptr); - rcu_read_unlock_sched_notrace(); - - return fn; -} - -#else /* !CONFIG_CFI_CLANG_SHADOW */ - -static inline cfi_check_fn find_shadow_check_fn(unsigned long ptr) -{ - return NULL; -} - -#endif /* CONFIG_CFI_CLANG_SHADOW */ static inline cfi_check_fn find_module_check_fn(unsigned long ptr) { @@ -298,10 +67,7 @@ static inline cfi_check_fn find_check_fn(unsigned long ptr) ct_irq_enter(); } - if (IS_ENABLED(CONFIG_CFI_CLANG_SHADOW)) - fn = find_shadow_check_fn(ptr); - if (!fn) - fn = find_module_check_fn(ptr); + fn = find_module_check_fn(ptr); if (rcu_idle) { ct_irq_exit(); diff --git a/kernel/module/main.c b/kernel/module/main.c index a4e4d84b6f4e..0228f44b58e5 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -1144,8 +1144,6 @@ void __weak module_arch_freeing_init(struct module *mod) { } -static void cfi_cleanup(struct module *mod); - /* Free a module, remove from lists, etc. */ static void free_module(struct module *mod) { @@ -1190,9 +1188,6 @@ static void free_module(struct module *mod) mod->name); mutex_unlock(&module_mutex); - /* Clean up CFI for the module. */ - cfi_cleanup(mod); - /* This may be empty, but that's OK */ module_arch_freeing_init(mod); module_memfree(mod->init_layout.base); @@ -2875,7 +2870,6 @@ static int load_module(struct load_info *info, const char __user *uargs, synchronize_rcu(); kfree(mod->args); free_arch_cleanup: - cfi_cleanup(mod); module_arch_cleanup(mod); free_modinfo: free_modinfo(mod); @@ -2984,15 +2978,6 @@ static void cfi_init(struct module *mod) mod->exit = *exit; #endif rcu_read_unlock_sched(); - - cfi_module_add(mod, mod_tree.addr_min); -#endif -} - -static void cfi_cleanup(struct module *mod) -{ -#ifdef CONFIG_CFI_CLANG - cfi_module_remove(mod, mod_tree.addr_min); #endif } From patchwork Thu Sep 8 21:54:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970698 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 3C18CC54EE9 for ; Thu, 8 Sep 2022 21:57:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AwQu0LvkJok4LnZkXEFBC2zwRe432t1sGNZ//amoIB8=; b=z8S9upXlJNyVFEb9IaV7Qzzjhe KSj1J+VlkxYE2LIb2ZNn+ySY1Q4iatR4Z/dZagCmD0SEpslpoD+ixnQPp9wUEeQUbdmKMnzYlE6FQ i34ubsGM4SOBy20kTnlvHdFwj9tXlzuoSp+nq45xuSLFRd7Uv4QkbBuQ8PJmge4zM3/cKCVkkgk71 R5O4RKC4h6xhljs51vMtuy2NYCcZpk5ZZWZFaGGaFwQa3aXoJRXFwrLTo0CLsFuzc03/qPdD/Tei3 jvAyJDDEYRhZ9eIPQF+rk73VbrnumTAU21/Bfx2L1F3ChplXb9/1qR/d7mNx77A02Wv4/VgQzy4q2 Qn5ynAqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPV5-0095Fa-UN; Thu, 08 Sep 2022 21:55:56 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUU-0094xb-VU for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:20 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-345188a7247so123012737b3.22 for ; Thu, 08 Sep 2022 14:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=g3Gq9NjDQ4hoNq7pf0wYq1hQ9S7+uZzv+7qsTdt2KdI=; b=e6ayS0gC7nTSB7sRK6XqhQ8PkPz9hlgp/RG7EOOdhWea6QvJiQZOd6p6yRF1NZYv/o vzQ7PUjvc1GQcMZf/RvGUwpu+aH8P3ZoExhuwot4Tu7nh4eE2MqU4XX/qfmC11xMEW4o Y/AZQ0xzwG2Mar5BAt3A1szuyTFm5NvUtfYqEfXV1CSjQcMQ3Q1HdqhaSkzso9vU/bfF 2S9OU1oxlI5/swmy9dZQTjUadiVrICRahUR+1BkjvlCNWRfP9Mw6o1NCxiHcqC/FEK0/ FLsQPDJso9Ylk5O0+Jzhs1qE+tMp3ptdqsU96cyzMV7BAd396uxnK/WHPUbXM9y+WcfA SKcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=g3Gq9NjDQ4hoNq7pf0wYq1hQ9S7+uZzv+7qsTdt2KdI=; b=3AQgyspyjM2uCxQpiUBkehAN5wYc8hhWDLtDS+7sF5c83+9/AGoXRJlW2OTmDWvyuY 2YpiStvgO1+CDAnBraT2WWKt97EEYI3fLSediwTwvM/+Z3VNKwt3P0hNHGu130SklsTa Mf5X1v2AQPQC/UgdSPTQ6lM2dgwhMsTuDg8JEsCJldAWuPFapyJp+xCRsPWYoqmZPYsZ zPHLTe9vOQ7NoynR9buN1N9u01oPbXR24Pb3U/+eIuV4gM7oOO3aBTPVhs0QmZa1dWKN Y+/tC05CHqLV5AL35JEDA49Hu743NVyzKCmiWPDGY9nq0jEFw/dp+l7D6bafs3KFYdk0 PqGg== X-Gm-Message-State: ACgBeo0Ins+M8gz+WuiZS8w/qDmwtvh0Yg50zQQMHyVHaJ0LXA3zEB7H TD5c8B3eU+TAnmcswc1s7/BvUFBwTa0aAvj2p0A= X-Google-Smtp-Source: AA6agR4oLa4FfONKqbwF0FpWWwehyzcLO0uVvsqUFNdTCDrYLlJiXgNyonePKOhCzmHaZvZqc+/KvgSAGwpx0OzCFUY= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a25:6405:0:b0:695:626f:2f54 with SMTP id y5-20020a256405000000b00695626f2f54mr9342982ybb.532.1662674117353; Thu, 08 Sep 2022 14:55:17 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:46 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3358; i=samitolvanen@google.com; h=from:subject; bh=q6/maWZMNVpRPStuCMK4l2y855666X5QfHf+jlPyW9E=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSzPgBZK/tC4vtUdRH53Ki3URAzr5yoqoKUBNEd 9pDUmUOJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpkswAKCRBMtfaEi7xW7qFOC/ 4zoXFSdT6EVd7MKSkn3bke2rRW5/QfuEhpApzfIEcWm7hYWqvt2j4d0/ZBv/AhDbpfAu63FzvtxKRe LIizJqs3rsDJZpaN8FOfE15jM5ZEhcW+XQhXeBb9cPII1xyUjI50Ewak9+QqMAhJKWkpnhCw0ZiuyF PkSvSEFK7IsX3rt9E5mGQHKwiO6tST5MVjp6wnXwKiilISNiFuddkn8K9CPBqsGqw7fPEvOYNlUNJw Lv8Z2wulw6ah+Tl2+nNV4fPFZsX3KFvWLh0DToEsUurPTa/RX3Is8GCXDKckNFqFTeWwc1UXH9mPuj yLGtLW6UtdSWrCAf8feKWj1r8dLd7yCN+z2mTGNfD8tXyUKkrV/e2tC1ZTz8xlxKGF1kJY+loYhPbr CsUhah3L7kmv88pnkFBqwxaBm+vHrXGYpar87u4ga69xVDbczil5jN333/KQnbR7bBNMtDdatTv7U8 u3+F3CuQjOOfIUjzM2EfPHtSCxBwfwZJKRVf7tIBFv3gI= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 04/22] cfi: Drop __CFI_ADDRESSABLE From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145519_084140_C5CE9B78 X-CRM114-Status: GOOD ( 15.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The __CFI_ADDRESSABLE macro is used for init_module and cleanup_module to ensure we have the address of the CFI jump table, and with CONFIG_X86_KERNEL_IBT to ensure LTO won't optimize away the symbols. As __CFI_ADDRESSABLE is no longer necessary with -fsanitize=kcfi, add a more flexible version of the __ADDRESSABLE macro and always ensure these symbols won't be dropped. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- include/linux/cfi.h | 20 -------------------- include/linux/compiler.h | 6 ++++-- include/linux/module.h | 4 ++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/include/linux/cfi.h b/include/linux/cfi.h index 4ab51c067007..2cdbc0fbd0ab 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -13,26 +13,6 @@ typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); /* Compiler-generated function in each module, and the kernel */ extern void __cfi_check(uint64_t id, void *ptr, void *diag); -/* - * Force the compiler to generate a CFI jump table entry for a function - * and store the jump table address to __cfi_jt_. - */ -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#else /* !CONFIG_CFI_CLANG */ - -#ifdef CONFIG_X86_KERNEL_IBT - -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#endif /* CONFIG_X86_KERNEL_IBT */ - #endif /* CONFIG_CFI_CLANG */ -#ifndef __CFI_ADDRESSABLE -#define __CFI_ADDRESSABLE(fn, __attr) -#endif - #endif /* _LINUX_CFI_H */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 7713d7bcdaea..7bfafc69172a 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -221,9 +221,11 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, * otherwise, or eliminated entirely due to lack of references that are * visible to the compiler. */ -#define __ADDRESSABLE(sym) \ - static void * __section(".discard.addressable") __used \ +#define ___ADDRESSABLE(sym, __attrs) \ + static void * __used __attrs \ __UNIQUE_ID(__PASTE(__addressable_,sym)) = (void *)&sym; +#define __ADDRESSABLE(sym) \ + ___ADDRESSABLE(sym, __section(".discard.addressable")) /** * offset_to_ptr - convert a relative memory offset to an absolute pointer diff --git a/include/linux/module.h b/include/linux/module.h index 518296ea7f73..8937b020ec04 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -132,7 +132,7 @@ extern void cleanup_module(void); { return initfn; } \ int init_module(void) __copy(initfn) \ __attribute__((alias(#initfn))); \ - __CFI_ADDRESSABLE(init_module, __initdata); + ___ADDRESSABLE(init_module, __initdata); /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ @@ -140,7 +140,7 @@ extern void cleanup_module(void); { return exitfn; } \ void cleanup_module(void) __copy(exitfn) \ __attribute__((alias(#exitfn))); \ - __CFI_ADDRESSABLE(cleanup_module, __exitdata); + ___ADDRESSABLE(cleanup_module, __exitdata); #endif From patchwork Thu Sep 8 21:54:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970708 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 DE125C54EE9 for ; Thu, 8 Sep 2022 21:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AmPJn0qtmXN0YR0PC2WCZ6L62KNxR94a98eT5Pr2piA=; b=WTcd1bYpi+RNgF6jwGA16GX6+l 7zUSoYOnz5J6c8xEEFSR5kUGPrXxwLnYalBUICIFTxrFRnvjPMizAmO1isVzkqcNG7FcwxNPk47U9 8L804785EJyqj5Rwitp0t4ZAyJsJL5xLW8aAbIEfamerp5zneL7lk1w79o0KLyssSz02NioWzg4N5 rmdsQJBudKYOrGZNPhDvt/1Skm5gcLpBCNRoP6w2RnpMqggAjL2IRKAOv4A9gX/5DdU4KXAcRZnFk 27pNMLGo0QWyDghgCb2rDewUZHdmFUACGW2XJL+VlE+v47X+PtRzqHF7mDrzL6lhDb5nOyTWeml7q 8ScdIvNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPVQ-0095RK-Tz; Thu, 08 Sep 2022 21:56:17 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUX-0094z5-HD for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:24 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id v202-20020a252fd3000000b006a8f6c5d39bso10882270ybv.21 for ; Thu, 08 Sep 2022 14:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:from:to:cc:subject:date; bh=nWL0aROoRXaq2aFLsQrBYp1EGs3bODIj6Z2ykx/Ykp8=; b=IZ8CvgVBEW+3TNYeXkE5KDChuokHUFERDyR83lR9Hjz13CWKrXH8z4zJBBA5G3U7O7 T6fGQYVJCsldsK3wbLa4BVDEJC6074bYxyJaues3V0GDIN7a0acDUotqPnCDbZMg8CV5 lDpWl4Ul+87dWMR8UDrNz+TdCFMne/luwQAE482wyV/kas2QfVQXoHvMd05hnsJFLEX8 Wg9GHVkjTGHpHedF9ibQjdv6kF+QwdrxS+25ti57Mnlbfu3MEysljO/OGPzF9dZ4VchQ p6lP1w9rGcTgVkK4lIB9dTCvMels03oip3JKvFYFBh7g//V+Al2Be1w89q2AUKwSIIed X6DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:x-gm-message-state:from:to :cc:subject:date; bh=nWL0aROoRXaq2aFLsQrBYp1EGs3bODIj6Z2ykx/Ykp8=; b=h6gatnhLiapG6qAbJ3aYC9m5Ky/0pgP/yxMZBVlogyMN2/qI4t4D/DIQsXynB7RADo l/0NFSb53G4wvWYyHomlWJDaXv4ifyLG278GHLDqrBb/jmYa9WOXLHyROwMXYCM4yZk6 vnpCuTsVRlOZ+nH27ADE4bhXpkVjgovZuUMJ7Pvt+6i/WqZkUsXMIxl9OfL3UzvfFS+c hiwx1IGYNyfYZvzefrR87OxdLl+ByER2tMLGAXogo7KkMggTrWWzNvTgeRSa7V3w7TcA JkfUMUKv5KZZgO8rEuW5+VaB6gEHZJVSQ4f4BE6ACnTAfJBAFiBJ/VyMElhIAaCn2rvg JbOA== X-Gm-Message-State: ACgBeo1pjeRk38/yhbeBC5RkFgnRaKTalxAB4H16ULF0PraO62iiEu4u 5rnMk7pCSOnplk9LQZSxRZEbOiIB434ed6eQMbI= X-Google-Smtp-Source: AA6agR50NiPw/l8/JWBOwCU6g5z471+pH699N76zKI30BjIZuHauhlYyr22x4qjjZZwpvi03Zxx0Rd6+TzLHI08C5T0= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a25:9e83:0:b0:6a7:b23c:289 with SMTP id p3-20020a259e83000000b006a7b23c0289mr8448516ybq.587.1662674120133; Thu, 08 Sep 2022 14:55:20 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:47 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-6-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=15849; i=samitolvanen@google.com; h=from:subject; bh=3zlj9uhGgVvdu99S3z0sryv5ljb8kTjyqDYUlzAvVng=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSzNdnTtM2yogklOpJEkc0SSoM/2VAYCJ7a7iUM nL/lD8iJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpkswAKCRBMtfaEi7xW7u3jC/ 9iJNFKoxSu1pxhi5fTXhPW7L1KVmFJCZku5t1XyI0H6ipC1BXjWu/P11U8tDXWEIUtblQfKR6HB+nH OjNEYyspSHWNUqQ6OpqfNyx0YFGB1AUGIcM3esBeIUx96DRqYS4qYFLmu342tdgh1mYkyfyPrGKnUj 34c9aZ8GHSx/KZB6mcr9OKMw7EXeztnSNL1xQGf0kiDAhWEzQCys7GMcGB0AaYKUgGOuC7QB5StYCG pvJdqtK7PEdnN+tnhawQtL4cLSAJcYdTyV6JhHsJOWDdwKtJAFyh3+uTjXtLcnTQ3RFiGybkaWciAj /+UqTEuy6TXXw0O2DLXlaqN3zSxIvwXp2yGbOzmrIlT40WlJrKIP0FMi4zxCDlmO/oMHMIAvSEWOhh 6qoi+dms2ZnburZ8O5wncxrQARhO1vXjScKwxU2ubYmWqAS+C2X8v0q5aTjG4IoelgXV9f7V45AjSq t3e5DlCLsKjgTv5T/IXBdtFUPmaTdWEuBTUhaaKvnkN28= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 05/22] cfi: Switch to -fsanitize=kcfi From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145521_617626_312008FA X-CRM114-Status: GOOD ( 25.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Switch from Clang's original forward-edge control-flow integrity implementation to -fsanitize=kcfi, which is better suited for the kernel, as it doesn't require LTO, doesn't use a jump table that requires altering function references, and won't break cross-module function address equality. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- Makefile | 13 +-- arch/Kconfig | 8 +- include/asm-generic/vmlinux.lds.h | 37 ++++---- include/linux/cfi.h | 29 +++++- include/linux/compiler-clang.h | 14 +-- include/linux/module.h | 6 +- kernel/cfi.c | 144 +++++++++++++++--------------- kernel/module/main.c | 35 +------- scripts/module.lds.S | 23 +---- 9 files changed, 133 insertions(+), 176 deletions(-) diff --git a/Makefile b/Makefile index a4f71076cacb..43e08c9f95e9 100644 --- a/Makefile +++ b/Makefile @@ -921,18 +921,7 @@ export CC_FLAGS_LTO endif ifdef CONFIG_CFI_CLANG -CC_FLAGS_CFI := -fsanitize=cfi \ - -fsanitize-cfi-cross-dso \ - -fno-sanitize-cfi-canonical-jump-tables \ - -fno-sanitize-trap=cfi \ - -fno-sanitize-blacklist - -ifdef CONFIG_CFI_PERMISSIVE -CC_FLAGS_CFI += -fsanitize-recover=cfi -endif - -# If LTO flags are filtered out, we must also filter out CFI. -CC_FLAGS_LTO += $(CC_FLAGS_CFI) +CC_FLAGS_CFI := -fsanitize=kcfi KBUILD_CFLAGS += $(CC_FLAGS_CFI) export CC_FLAGS_CFI endif diff --git a/arch/Kconfig b/arch/Kconfig index 5fd875e18c99..1c1eca0c0019 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -738,11 +738,13 @@ config ARCH_SUPPORTS_CFI_CLANG An architecture should select this option if it can support Clang's Control-Flow Integrity (CFI) checking. +config ARCH_USES_CFI_TRAPS + bool + config CFI_CLANG bool "Use Clang's Control Flow Integrity (CFI)" - depends on LTO_CLANG && ARCH_SUPPORTS_CFI_CLANG - depends on CLANG_VERSION >= 140000 - select KALLSYMS + depends on ARCH_SUPPORTS_CFI_CLANG + depends on $(cc-option,-fsanitize=kcfi) help This option enables Clang’s forward-edge Control Flow Integrity (CFI) checking, where the compiler injects a runtime check to each diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 7515a465ec03..7501edfce11e 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -421,6 +421,22 @@ __end_ro_after_init = .; #endif +/* + * .kcfi_traps contains a list KCFI trap locations. + */ +#ifndef KCFI_TRAPS +#ifdef CONFIG_ARCH_USES_CFI_TRAPS +#define KCFI_TRAPS \ + __kcfi_traps : AT(ADDR(__kcfi_traps) - LOAD_OFFSET) { \ + __start___kcfi_traps = .; \ + KEEP(*(.kcfi_traps)) \ + __stop___kcfi_traps = .; \ + } +#else +#define KCFI_TRAPS +#endif +#endif + /* * Read only Data */ @@ -529,6 +545,8 @@ __stop___modver = .; \ } \ \ + KCFI_TRAPS \ + \ RO_EXCEPTION_TABLE \ NOTES \ BTF \ @@ -537,21 +555,6 @@ __end_rodata = .; -/* - * .text..L.cfi.jumptable.* contain Control-Flow Integrity (CFI) - * jump table entries. - */ -#ifdef CONFIG_CFI_CLANG -#define TEXT_CFI_JT \ - . = ALIGN(PMD_SIZE); \ - __cfi_jt_start = .; \ - *(.text..L.cfi.jumptable .text..L.cfi.jumptable.*) \ - . = ALIGN(PMD_SIZE); \ - __cfi_jt_end = .; -#else -#define TEXT_CFI_JT -#endif - /* * Non-instrumentable text section */ @@ -579,7 +582,6 @@ *(.text..refcount) \ *(.ref.text) \ *(.text.asan.* .text.tsan.*) \ - TEXT_CFI_JT \ MEM_KEEP(init.text*) \ MEM_KEEP(exit.text*) \ @@ -1008,8 +1010,7 @@ * keep any .init_array.* sections. * https://bugs.llvm.org/show_bug.cgi?id=46478 */ -#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN) || \ - defined(CONFIG_CFI_CLANG) +#if defined(CONFIG_GCOV_KERNEL) || defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KCSAN) # ifdef CONFIG_CONSTRUCTORS # define SANITIZER_DISCARDS \ *(.eh_frame) diff --git a/include/linux/cfi.h b/include/linux/cfi.h index 2cdbc0fbd0ab..5e134f4ce8b7 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -2,17 +2,38 @@ /* * Clang Control Flow Integrity (CFI) support. * - * Copyright (C) 2021 Google LLC + * Copyright (C) 2022 Google LLC */ #ifndef _LINUX_CFI_H #define _LINUX_CFI_H +#include +#include + #ifdef CONFIG_CFI_CLANG -typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); +enum bug_trap_type report_cfi_failure(struct pt_regs *regs, unsigned long addr, + unsigned long *target, u32 type); -/* Compiler-generated function in each module, and the kernel */ -extern void __cfi_check(uint64_t id, void *ptr, void *diag); +static inline enum bug_trap_type report_cfi_failure_noaddr(struct pt_regs *regs, + unsigned long addr) +{ + return report_cfi_failure(regs, addr, NULL, 0); +} +#ifdef CONFIG_ARCH_USES_CFI_TRAPS +bool is_cfi_trap(unsigned long addr); +#endif #endif /* CONFIG_CFI_CLANG */ +#ifdef CONFIG_MODULES +#ifdef CONFIG_ARCH_USES_CFI_TRAPS +void module_cfi_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, + struct module *mod); +#else +static inline void module_cfi_finalize(const Elf_Ehdr *hdr, + const Elf_Shdr *sechdrs, + struct module *mod) {} +#endif /* CONFIG_ARCH_USES_CFI_TRAPS */ +#endif /* CONFIG_MODULES */ + #endif /* _LINUX_CFI_H */ diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index c84fec767445..42e55579d649 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -66,17 +66,9 @@ # define __noscs __attribute__((__no_sanitize__("shadow-call-stack"))) #endif -#define __nocfi __attribute__((__no_sanitize__("cfi"))) -#define __cficanonical __attribute__((__cfi_canonical_jump_table__)) - -#if defined(CONFIG_CFI_CLANG) -/* - * With CONFIG_CFI_CLANG, the compiler replaces function address - * references with the address of the function's CFI jump table - * entry. The function_nocfi macro always returns the address of the - * actual function instead. - */ -#define function_nocfi(x) __builtin_function_start(x) +#if __has_feature(kcfi) +/* Disable CFI checking inside a function. */ +#define __nocfi __attribute__((__no_sanitize__("kcfi"))) #endif /* diff --git a/include/linux/module.h b/include/linux/module.h index 8937b020ec04..ec61fb53979a 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #include @@ -387,8 +386,9 @@ struct module { const s32 *crcs; unsigned int num_syms; -#ifdef CONFIG_CFI_CLANG - cfi_check_fn cfi_check; +#ifdef CONFIG_ARCH_USES_CFI_TRAPS + s32 *kcfi_traps; + s32 *kcfi_traps_end; #endif /* Kernel parameters. */ diff --git a/kernel/cfi.c b/kernel/cfi.c index e8bc1b370edc..08caad776717 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -1,105 +1,101 @@ // SPDX-License-Identifier: GPL-2.0 /* - * Clang Control Flow Integrity (CFI) error and slowpath handling. + * Clang Control Flow Integrity (CFI) error handling. * - * Copyright (C) 2021 Google LLC + * Copyright (C) 2022 Google LLC */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Compiler-defined handler names */ -#ifdef CONFIG_CFI_PERMISSIVE -#define cfi_failure_handler __ubsan_handle_cfi_check_fail -#else -#define cfi_failure_handler __ubsan_handle_cfi_check_fail_abort -#endif - -static inline void handle_cfi_failure(void *ptr) +#include + +enum bug_trap_type report_cfi_failure(struct pt_regs *regs, unsigned long addr, + unsigned long *target, u32 type) { - if (IS_ENABLED(CONFIG_CFI_PERMISSIVE)) - WARN_RATELIMIT(1, "CFI failure (target: %pS):\n", ptr); + if (target) + pr_err("CFI failure at %pS (target: %pS; expected type: 0x%08x)\n", + (void *)addr, (void *)*target, type); else - panic("CFI failure (target: %pS)\n", ptr); + pr_err("CFI failure at %pS (no target information)\n", + (void *)addr); + + if (IS_ENABLED(CONFIG_CFI_PERMISSIVE)) { + __warn(NULL, 0, (void *)addr, 0, regs, NULL); + return BUG_TRAP_TYPE_WARN; + } + + return BUG_TRAP_TYPE_BUG; } -#ifdef CONFIG_MODULES +#ifdef CONFIG_ARCH_USES_CFI_TRAPS +static inline unsigned long trap_address(s32 *p) +{ + return (unsigned long)((long)p + (long)*p); +} -static inline cfi_check_fn find_module_check_fn(unsigned long ptr) +static bool is_trap(unsigned long addr, s32 *start, s32 *end) { - cfi_check_fn fn = NULL; - struct module *mod; + s32 *p; - rcu_read_lock_sched_notrace(); - mod = __module_address(ptr); - if (mod) - fn = mod->cfi_check; - rcu_read_unlock_sched_notrace(); + for (p = start; p < end; ++p) { + if (trap_address(p) == addr) + return true; + } - return fn; + return false; } -static inline cfi_check_fn find_check_fn(unsigned long ptr) +#ifdef CONFIG_MODULES +/* Populates `kcfi_trap(_end)?` fields in `struct module`. */ +void module_cfi_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs, + struct module *mod) { - cfi_check_fn fn = NULL; - unsigned long flags; - bool rcu_idle; - - if (is_kernel_text(ptr)) - return __cfi_check; - - /* - * Indirect call checks can happen when RCU is not watching. Both - * the shadow and __module_address use RCU, so we need to wake it - * up if necessary. - */ - rcu_idle = !rcu_is_watching(); - if (rcu_idle) { - local_irq_save(flags); - ct_irq_enter(); - } + char *secstrings; + unsigned int i; - fn = find_module_check_fn(ptr); + mod->kcfi_traps = NULL; + mod->kcfi_traps_end = NULL; - if (rcu_idle) { - ct_irq_exit(); - local_irq_restore(flags); - } + secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset; + + for (i = 1; i < hdr->e_shnum; i++) { + if (strcmp(secstrings + sechdrs[i].sh_name, "__kcfi_traps")) + continue; - return fn; + mod->kcfi_traps = (s32 *)sechdrs[i].sh_addr; + mod->kcfi_traps_end = (s32 *)(sechdrs[i].sh_addr + sechdrs[i].sh_size); + break; + } } -void __cfi_slowpath_diag(uint64_t id, void *ptr, void *diag) +static bool is_module_cfi_trap(unsigned long addr) { - cfi_check_fn fn = find_check_fn((unsigned long)ptr); + struct module *mod; + bool found = false; - if (likely(fn)) - fn(id, ptr, diag); - else /* Don't allow unchecked modules */ - handle_cfi_failure(ptr); -} -EXPORT_SYMBOL(__cfi_slowpath_diag); + rcu_read_lock_sched_notrace(); -#else /* !CONFIG_MODULES */ + mod = __module_address(addr); + if (mod) + found = is_trap(addr, mod->kcfi_traps, mod->kcfi_traps_end); -void __cfi_slowpath_diag(uint64_t id, void *ptr, void *diag) + rcu_read_unlock_sched_notrace(); + + return found; +} +#else /* CONFIG_MODULES */ +static inline bool is_module_cfi_trap(unsigned long addr) { - handle_cfi_failure(ptr); /* No modules */ + return false; } -EXPORT_SYMBOL(__cfi_slowpath_diag); - #endif /* CONFIG_MODULES */ -void cfi_failure_handler(void *data, void *ptr, void *vtable) +extern s32 __start___kcfi_traps[]; +extern s32 __stop___kcfi_traps[]; + +bool is_cfi_trap(unsigned long addr) { - handle_cfi_failure(ptr); + if (is_trap(addr, __start___kcfi_traps, __stop___kcfi_traps)) + return true; + + return is_module_cfi_trap(addr); } -EXPORT_SYMBOL(cfi_failure_handler); +#endif /* CONFIG_ARCH_USES_CFI_TRAPS */ diff --git a/kernel/module/main.c b/kernel/module/main.c index 0228f44b58e5..70c0b2c6fef8 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include "internal.h" @@ -2597,8 +2598,9 @@ static int complete_formation(struct module *mod, struct load_info *info) if (err < 0) goto out; - /* This relies on module_mutex for list integrity. */ + /* These rely on module_mutex for list integrity. */ module_bug_finalize(info->hdr, info->sechdrs, mod); + module_cfi_finalize(info->hdr, info->sechdrs, mod); if (module_check_misalignment(mod)) goto out_misaligned; @@ -2660,8 +2662,6 @@ static int unknown_module_param_cb(char *param, char *val, const char *modname, return 0; } -static void cfi_init(struct module *mod); - /* * Allocate and load the module: note that size of section 0 is always * zero, and we rely on this for optional sections. @@ -2791,9 +2791,6 @@ static int load_module(struct load_info *info, const char __user *uargs, flush_module_icache(mod); - /* Setup CFI for the module. */ - cfi_init(mod); - /* Now copy in args */ mod->args = strndup_user(uargs, ~0UL >> 1); if (IS_ERR(mod->args)) { @@ -2955,32 +2952,6 @@ static inline int within(unsigned long addr, void *start, unsigned long size) return ((void *)addr >= start && (void *)addr < start + size); } -static void cfi_init(struct module *mod) -{ -#ifdef CONFIG_CFI_CLANG - initcall_t *init; -#ifdef CONFIG_MODULE_UNLOAD - exitcall_t *exit; -#endif - - rcu_read_lock_sched(); - mod->cfi_check = (cfi_check_fn) - find_kallsyms_symbol_value(mod, "__cfi_check"); - init = (initcall_t *) - find_kallsyms_symbol_value(mod, "__cfi_jt_init_module"); - /* Fix init/exit functions to point to the CFI jump table */ - if (init) - mod->init = *init; -#ifdef CONFIG_MODULE_UNLOAD - exit = (exitcall_t *) - find_kallsyms_symbol_value(mod, "__cfi_jt_cleanup_module"); - if (exit) - mod->exit = *exit; -#endif - rcu_read_unlock_sched(); -#endif -} - /* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */ char *module_flags(struct module *mod, char *buf, bool show_state) { diff --git a/scripts/module.lds.S b/scripts/module.lds.S index 3a3aa2354ed8..da4bddd26171 100644 --- a/scripts/module.lds.S +++ b/scripts/module.lds.S @@ -3,20 +3,10 @@ * Archs are free to supply their own linker scripts. ld will * combine them automatically. */ -#ifdef CONFIG_CFI_CLANG -# include -# define ALIGN_CFI ALIGN(PAGE_SIZE) -# define SANITIZER_DISCARDS *(.eh_frame) -#else -# define ALIGN_CFI -# define SANITIZER_DISCARDS -#endif - SECTIONS { /DISCARD/ : { *(.discard) *(.discard.*) - SANITIZER_DISCARDS } __ksymtab 0 : { *(SORT(___ksymtab+*)) } @@ -33,6 +23,10 @@ SECTIONS { __patchable_function_entries : { *(__patchable_function_entries) } +#ifdef CONFIG_ARCH_USES_CFI_TRAPS + __kcfi_traps : { KEEP(*(.kcfi_traps)) } +#endif + #ifdef CONFIG_LTO_CLANG /* * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and @@ -53,15 +47,6 @@ SECTIONS { *(.rodata .rodata.[0-9a-zA-Z_]*) *(.rodata..L*) } - - /* - * With CONFIG_CFI_CLANG, we assume __cfi_check is at the beginning - * of the .text section, and is aligned to PAGE_SIZE. - */ - .text : ALIGN_CFI { - *(.text.__cfi_check) - *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*) - } #endif } From patchwork Thu Sep 8 21:54:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970709 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 A4238C54EE9 for ; Thu, 8 Sep 2022 21:57:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nmcbMLf1poCqr8b1CAYNamjFolEt4duPPSIXbo9wvWA=; b=0pjU7V7pl6OpFGYf1fyuUz8v20 d+OaERIbReuU0dLO1vZolY1Vrfh/DkwFvtEipP/tnYoc95a5vYOZJWMMj2+n4TJz6n52Fp7gTaihE M0kbJPZOs8sCzuEcrb2tmjQN6bxf+7pT8Kso4vFdAbNpJ2M6xt3KjOwDAtXeBjFC6sH9E7bqGWTJ1 PQqBYguuhN6TVDrHViyLl84m83zQ5f9LtMWmDbboR6VmF9CdfunPc+gTmUS1H2fr7C5eSqCgKuq7z w1IvRNvFG6HSSb+PzoPFsY64qlOWWQpgBujM81d78EPSPUIFAvkkkTA5BkeXnZ95ZY1X0ZVedfICD EhnE1dGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPVn-0095gf-W0; Thu, 08 Sep 2022 21:56:40 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUa-00950G-3W for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:26 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s15-20020a5b044f000000b00680c4eb89f1so17241ybp.7 for ; Thu, 08 Sep 2022 14:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=Gg7blUelcbN7qCzxZRpzw0uqSkfWrgRvEPc3Jh+AGuI=; b=ia0mK6/3LNsDfoYzbHMLDe/Bm1t826rzdpHAzZD5775IYWo4gZwL/vhPEACv3v4i34 lq8oC5OmgNyajyhPpb1WyFRIREwi56qcUb0xYjeodQU2bgPGqBYzVvZtVnNOMbs++dUZ UEfQ41zDLzfgGBeUZnE84Wg1Xvxk0UFi3F3FTVPpJUrG5dfAqRgKVfuDymS6niBwZv9G gJaED/gEDYQP0tRcV7yC8FCnerRS7w/kgE9o2/R8MdsXMYNfRG05I1aGgBTlB+G6Q/jo hw9BorlSsY0Byownprpk3/jgEUoE83i7P5H9k/rzRinpjgr9ZLEQhJVy8nl6EUzZSRB1 oa+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=Gg7blUelcbN7qCzxZRpzw0uqSkfWrgRvEPc3Jh+AGuI=; b=5bQbMFsamxFiVMuuV7HSAL8gXwn7s/hxROJBpRSZjgNO75S09sgEMRb4P5r3mIAKB/ L2ODna/BFaZ4UyeT6me2f35tEBOj0fAtcqC6cL398o6JW6T5WGOtlGRpllfWzCYPUgwe W4+VE51SQTkv+L2RRqu/lvex1fFpvL1p1a8Sp+tJsi3RkQ6AMfJUDwN5J9oAMc/iGxQl 4kPTxGEiq4rH19xBwDrrrU4ULQhTvgxlQfbHfgV83LyuQNi5utEmKK07j8w4FaI1Dulc xe2QRs+VO4J7ASqN3CkUYSdDmJITailrZSbj9wM+scqzUrsQvxJLQBsFyptS04ibahQu TRcA== X-Gm-Message-State: ACgBeo22cnew3qjNj6Znw2eo0IKWLXNcG15mhxB0u7LQIqN0NcsY8hpt bP1mlkildIosbVHT/rqQbUla5Xl9XP1Bi2PFg9A= X-Google-Smtp-Source: AA6agR4X+8dv6wxztc3FFDp1riYH8GRhKqIOBYUaVMcoH5wOteT0L/O9RmbG5Wnl9HfvSlwB/mJrCWySI3f6n0PQNmI= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:6f8b:0:b0:346:4554:9c4c with SMTP id k133-20020a816f8b000000b0034645549c4cmr9580284ywc.252.1662674122538; Thu, 08 Sep 2022 14:55:22 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:48 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-7-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3414; i=samitolvanen@google.com; h=from:subject; bh=64pVxZWyQcGNuQmdr6/Dl0+aZxLli0ezdxw+xqvhWN8=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmSzxWLFazYBWZrnKGdYa76NwTUQXE13SBQSA60z IffYke6JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpkswAKCRBMtfaEi7xW7pz3C/ 4nl7102I5DmW5DNSsOybkktukaOfZLGTigGAZeHlmXot3PR3vQifVocPxdq8dFjyHhC27vFzyrj8QW 2+yeEA2G0hmpDUJosWLHVFqCOtRAnXSYO2Y396cYc4xBWqF8PhMgVltaIJJahzjcdEIOF9fkPt0CBE GaG8RtPs4/zr3Pbs9ZC4AdUuvj29Q9ms7vyK5qs994VRWe4SRdQlg0Bj+C6qxvHRWuPMiPaeVmHTHu Q/GYlSf+8cwYrZCq7IfSuE7hkYo214TaXi9NwQ9aElLfgyiZHGttxh+ws7Kin1+cVxcdL4wd73m8W5 NSgriSje09Ch/qPNR4aBDJOZwYxo2OAjCm2Q24l9TrzlbBZqVx+AYH+1xqPbaEwpve/qRRxf8HJ22A 7ZaVaYp95JhAWDd40cc3La4gZt6i05A0HYpO/XlL62H2TgyEgMI0WfT9xQrQzByi96j6gH2ZS0mVRc Nw3RVwbMWguE4ppgggFszxEqZ7Xk/cmKpGUzMTYMj4BKU= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 06/22] cfi: Add type helper macros From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145524_518089_4E02281B X-CRM114-Status: GOOD ( 17.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With CONFIG_CFI_CLANG, assembly functions called indirectly from C code must be annotated with type identifiers to pass CFI checking. In order to make this easier, the compiler emits a __kcfi_typeid_ symbol for each address-taken function declaration in C, which contains the expected type identifier that we can refer to in assembly code. Add a typed version of SYM_FUNC_START, which emits the type identifier before the function. Architectures that support KCFI can define their own __CFI_TYPE macro to override the default preamble format. As an example, for the x86_64 blowfish_dec_blk function, the compiler emits the following type symbol: $ readelf -sW vmlinux | grep __kcfi_typeid_blowfish_dec_blk 120204: 00000000ef478db5 0 NOTYPE WEAK DEFAULT ABS __kcfi_typeid_blowfish_dec_blk And SYM_TYPED_FUNC_START will generate the following preamble based on the __CFI_TYPE definition for the architecture: $ objdump -dr arch/x86/crypto/blowfish-x86_64-asm_64.o ... 0000000000000400 <__cfi_blowfish_dec_blk>: ... 40b: b8 00 00 00 00 mov $0x0,%eax 40c: R_X86_64_32 __kcfi_typeid_blowfish_dec_blk 0000000000000410 : ... Note that the address of all assembly functions annotated with SYM_TYPED_FUNC_START must be taken in C code that's linked into the binary or the missing __kcfi_typeid_ symbol will result in a linker error with CONFIG_CFI_CLANG. If the code that contains the indirect call is not always compiled in, __ADDRESSABLE(functionname) can be used to ensure that the __kcfi_typeid_ symbol is emitted. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- include/linux/cfi_types.h | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 include/linux/cfi_types.h diff --git a/include/linux/cfi_types.h b/include/linux/cfi_types.h new file mode 100644 index 000000000000..6b8713675765 --- /dev/null +++ b/include/linux/cfi_types.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Clang Control Flow Integrity (CFI) type definitions. + */ +#ifndef _LINUX_CFI_TYPES_H +#define _LINUX_CFI_TYPES_H + +#ifdef __ASSEMBLY__ +#include + +#ifdef CONFIG_CFI_CLANG +/* + * Use the __kcfi_typeid_ type identifier symbol to + * annotate indirectly called assembly functions. The compiler emits + * these symbols for all address-taken function declarations in C + * code. + */ +#ifndef __CFI_TYPE +#define __CFI_TYPE(name) \ + .4byte __kcfi_typeid_##name +#endif + +#define SYM_TYPED_ENTRY(name, linkage, align...) \ + linkage(name) ASM_NL \ + align ASM_NL \ + __CFI_TYPE(name) ASM_NL \ + name: + +#define SYM_TYPED_START(name, linkage, align...) \ + SYM_TYPED_ENTRY(name, linkage, align) + +#else /* CONFIG_CFI_CLANG */ + +#define SYM_TYPED_START(name, linkage, align...) \ + SYM_START(name, linkage, align) + +#endif /* CONFIG_CFI_CLANG */ + +#ifndef SYM_TYPED_FUNC_START +#define SYM_TYPED_FUNC_START(name) \ + SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* _LINUX_CFI_TYPES_H */ From patchwork Thu Sep 8 21:54:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970710 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 C93B6C6FA82 for ; Thu, 8 Sep 2022 21:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=QWua5BIcn7fHY+3i5nEYrBasV9AFN2MJU8mG1+MJgjY=; b=Qb0CdW+bqoucfYl5zPLmpAnPJj bgLAyeqNcOLze6WFAE9RQ+jU5lbXvAnCEI9floQjTqPmoz2yTIwQAuYvjEB22JrhAwtzgOSF7tj1A DIx5z06IoBZwFNBRKlD5w/QiiyLf6iQIyrL4NGlBKKq88gwKujySBQ6mmPFNQJv6rDsssop2fNVPu DWLhdc8Xvc1XpScLh1Jii+Wh3ZQfMEQ3h9BDe+P6tFvwfB3rfb6RDwWIPEH3PnXTt1cDmKf6M/d6N mjXlR24Mt9o5NkiH9WDph83OcqpB29KoOecVPoPV3ysFOnWgRA2k241sSRXPAWU6nSZQRVFpXaVEk 813tmMJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPWF-0095za-I5; Thu, 08 Sep 2022 21:57:07 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUe-00952Y-7W for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:31 +0000 Received: by mail-pg1-x549.google.com with SMTP id 128-20020a630486000000b00435b18f71b3so1936800pge.19 for ; Thu, 08 Sep 2022 14:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=hxVlN6rWLARdYy3dC6gMYDiNdzPlrI9Em0RdQMqLWyE=; b=YixyhnGLxPM5IyBq+Cx3ROpfwgkmWSL/S+Z9WY9aAlV7aqP076z0Be803EmoxgmZSI QPaV8mCVsgLhPK0aWX376YklGiCJfSTQGO1TR9S0NuD23n3U49BRqiD9JQRLbsJS1gPo KDdIn8Ft5t+LqAtHkX2xDrILJvARG24X0A1g3yXOFgW4s5rrBn+hl8I8C1z7wNlYB5sS B5b4ju+vHNFK6prjhEKAeNilCbI2oaOjKYSm+B9K8L0AQmCslqzX6I5rLytuYw+tivqQ fj5gWZIuFxcERHDKBIHCixAvaqoKbaIi7sNWgZ6OjyRKxDhxAeTOB1qkIq/GII7+iKz3 2mPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=hxVlN6rWLARdYy3dC6gMYDiNdzPlrI9Em0RdQMqLWyE=; b=ikKmz9WH4naRurJkHCpiO2FPSWfbFMAoAUNvorEENlwFZQn78oV1ep6NqZVV51w+8H TMhcxNgtexyDa9tOc27wcUC/DXVU4+DLMPgPN/1eOg7DvAqO8T76gvsb3npxgERIv5Bg z4o92H0Y+8o5G7WmEHhrlI3hdyyw4BeTD8lZGm4y8rfGlkJFdVDgly9EwRzIK5xsTKxR K7CeP0609Y5DfdvCnIaFi+iEhq2xEBrPdSV9lo4jn9ynCNoL10ja9+qu/omu1ns60nv/ fEZWEXCHuLlhO+jBdSoR7JqHEHJpxU1iOhLhG+ItJtWjn84Rq72CG5LU0aC5uJ6jaYvE LQ+A== X-Gm-Message-State: ACgBeo1p4RUak2r4ZhNbc/qqHckA9rfio9ZSNJ5i6clz6Mnp7+DdBcS7 wD7RUhDKro59wf83pOUrFLXGHHOilipIS6VJKCY= X-Google-Smtp-Source: AA6agR65qo+hoOIT4XctxXEnKYpVkqbDPe1kpMaIsXT3ELQK8UbHn7uKhuVpWc1mlSHvRk67rOv9sIorlVrSO2geSOA= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6a00:ac4:b0:535:c08:2da7 with SMTP id c4-20020a056a000ac400b005350c082da7mr11099784pfl.69.1662674125665; Thu, 08 Sep 2022 14:55:25 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:49 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1770; i=samitolvanen@google.com; h=from:subject; bh=Y4Uf5ZGPYU6AVUx35/Ny2uohOGmi5MxjylrWIxxHQXk=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS0Or7SZXmXRk+ugEb0v0gF1mhowC/k7HonApWp lUIZjtGJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktAAKCRBMtfaEi7xW7rh9C/ 9iq8SJMhpp0douzn0NEiuSP+kUubtmt5lc4Ok7KEerIJ/4MOPE+/l7P1ebhCfDc9WP0hGgMpwU/x0t SJk/5fVgawWQ+TwNz5JgujDI77rc2mVF5orGjQoukvQ9vBOvYnvttyAO8/r189bsgyQicv9rhmTBpY EcXryiDMh3OmYogpOQQsbtgPmHgVLy6xJzU/dU0s8jD5F/A3gQSWdJH8KUqJNsaW/CGS1u9pfiSHtr XNWjIJfmS2QQBXL+cJh0XD9OHMcnS8zIgUMxXywsk1AcobJws5sQYF4uPhOg5agf8SCVeR2vemS4ig 6UfOqd8bUCL7kpK5vGnAv+NDRItdIzJWQiukTpzP379idLXQ07ItKJFjXcLeh0p6/K6q53vum6j+HX gtICAhP23tyItKQUf+XD6MaKkqENs0dgpVPjNynyYBpbJgTcOdInrZfntnE9z7YEnHQNIWq7bZQ6Lo VWytjgNgdX/N5z5lbv2dVuSB0Cbc7hlz3BBDwnxPLuvOs= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 07/22] lkdtm: Emit an indirect call for CFI tests From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145528_303951_7EE2B95A X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Clang can convert the indirect calls in lkdtm_CFI_FORWARD_PROTO into direct calls. Move the call into a noinline function that accepts the target address as an argument to ensure the compiler actually emits an indirect call instead. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers Tested-by: Kees Cook Tested-by: Nathan Chancellor Acked-by: Kees Cook --- drivers/misc/lkdtm/cfi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/misc/lkdtm/cfi.c b/drivers/misc/lkdtm/cfi.c index 71483cb1e422..5245cf6013c9 100644 --- a/drivers/misc/lkdtm/cfi.c +++ b/drivers/misc/lkdtm/cfi.c @@ -20,6 +20,13 @@ static noinline int lkdtm_increment_int(int *counter) return *counter; } + +/* Don't allow the compiler to inline the calls. */ +static noinline void lkdtm_indirect_call(void (*func)(int *)) +{ + func(&called_count); +} + /* * This tries to call an indirect function with a mismatched prototype. */ @@ -29,15 +36,11 @@ static void lkdtm_CFI_FORWARD_PROTO(void) * Matches lkdtm_increment_void()'s prototype, but not * lkdtm_increment_int()'s prototype. */ - void (*func)(int *); - pr_info("Calling matched prototype ...\n"); - func = lkdtm_increment_void; - func(&called_count); + lkdtm_indirect_call(lkdtm_increment_void); pr_info("Calling mismatched prototype ...\n"); - func = (void *)lkdtm_increment_int; - func(&called_count); + lkdtm_indirect_call((void *)lkdtm_increment_int); pr_err("FAIL: survived mismatched prototype function call!\n"); pr_expected_config(CONFIG_CFI_CLANG); From patchwork Thu Sep 8 21:54:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970711 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 5C424C54EE9 for ; Thu, 8 Sep 2022 21:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rb8e3RPcyGP2qpiGqdXpHfO2iZFWrQtRMSBPMYfjsyk=; b=aiE6bnq+AISlbkrNRwUYH92jyy Ly/ZxCmlpaCDDQI0FsANzQAjw/zMOh9f2ZTyHFHRBo0ZbcJxeqtFi+IsJGoJ8ZMhyBFu1INH0J99q DqcqrSyXpgAwqYot2+K6xi4/VXiBOuXKOCTynizrkJXxeS6csZp7NaVPnPcAbdJRUR0JPpnKfDzgA twHmPyi9wO+0ojyGMGm0NN9l5tYnr3ggRypdyQwHKDZnoMR9YdFa0XJMG2qUdvux8kXoHNRVs6HHa WP1otnel+tD0KWg5hiM1kkWe9Nuy3tvhiWPqfFmS7/o0HpHxhWCwiKMbkKlsy38ibtp+uwLhUvnmj Y5RJsqhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPWg-0096O9-P2; Thu, 08 Sep 2022 21:57:35 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUf-0094z5-Ce for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:31 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id v202-20020a252fd3000000b006a8f6c5d39bso10882473ybv.21 for ; Thu, 08 Sep 2022 14:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=koezPCxm32fHAwZgdGqKK7XqmRXL9JxASzrYTVD4m+E=; b=JSacEPUoej5v/XIN7Hsi8+T5GHAejPEIXTMi6W7AKQLC5hVqZnvtkNAu5BK6krzUQx fctP5X9cs9aaG7Slukq3widQl5Sz3Cg4B2+9Ms/40HHHiPhW+ORwgrMpQFg4g2DD6vyP nsbocmqQcPUoKOu9GBsszyWW5Y/9pcHmD1tong6jGdtvxt1q98M9IMk9vq27vD9xYIlm X5YII9Nz1tn+CVFWxqczzbj3f8cmmHd52JOITZuOclM3trrztiE9Anovjz5avPkqa+tl mNVIYYwqwAqyxAbBXm25Fyh9l2MDmpgRTRoUJ5NAd2cCa7cVJSAWyrMN3tEzDgFbbiIe 6TEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=koezPCxm32fHAwZgdGqKK7XqmRXL9JxASzrYTVD4m+E=; b=oLEJyZrt6RUCojuYiUTWdFzeE8bVGw9SmIMs5zuT8Y7CF1d12AJ32NC5lJTKFe1Qbg IukautdMySHnVTRjr3PjgAaG9hxcoZgEd02TBaXAbJMd7HkTWaF1r1EdTk49EVAj1ojJ K7LgVOOfTxbVmVewwMx7EuVvDICLuq878yH30bS+o8NiMqTAtFRC64aor5q2metJJhS+ XymD2AE0Z2HJa5mRD4k/CMQh+DMw+ECduSE4t179MItUKK+6U4EKX6x/rWRPSbaWmBAj EfN6bpbIcsEP7Nj3cM29j0XVTL8SQZh+3v7fFvC076Xa37ze/GPiwIDD8ScLuvi7vQRW 0nDw== X-Gm-Message-State: ACgBeo0n22aMD0PaWjVnk6cU+n7luS5M9y9a7nVJa3QAxeLk5KPAJgHI kLOXUuQMJQR/3cyvd1ErrgrlpvWEZ8kDrv5JOlU= X-Google-Smtp-Source: AA6agR4f3SYEc+Bp0TdIuCv586ybfdJDVN30qGCNPGKAFJMjsSrHsBG3kNu8QkrrVyppevzh+B3tK1Z4CU58zsMdLI0= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a25:3486:0:b0:6a1:881a:5d86 with SMTP id b128-20020a253486000000b006a1881a5d86mr8937712yba.323.1662674128390; Thu, 08 Sep 2022 14:55:28 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:50 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-9-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1807; i=samitolvanen@google.com; h=from:subject; bh=jyM+rGxWUU219XYY5/O2nBNl+QplLQ4hASchurrzdpo=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS0202vID3CXZ0XLmebB+d9NIzgSUGtOWGy99hv ue7C0ruJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktAAKCRBMtfaEi7xW7lPxC/ 9lKOPhgsglfXR1fj5L/0qgYqxVBFIG9R2MnXno1UwVmdTTRPq0bkQzscG3ZpD7ATu2TIr53T1Edqxa yuQxpw1bh5TSssxhwO6IU7t5pOMBdP86oaYB2aEUoAFRLV16cwaX3ei3GpZl9y/mD9QGlDzconUw2f JaNKLMZshc/LblHCMDbxS8I8wIe8AEjCb5QEIxM7P9I2wAPAxx4/4mDDj8ivfGS3tzIMF1EXYYFkv0 wHyzUefM39JrhnAXhKtJ+5JSsakAbxyGBuFX31X5YeQhoOvbR/eqylaRbt7Tej1510BlgG+zIxM4go U3JlUJiPPvWfW/rych3iQYkqRHFcpJLtgshmb3HaA64wvo2hwTTFK82MJeP2qDRxZJPY8gDK0dR0v2 UxktEOG6eZ4oLvqy4bI1mp5dfETqiJ16qfIZ7BPnnCOG71n04ZjUltD6AAhj6pPHqMNHNYVnnUdFS7 OThfxGxDoCPjO+/PYXGv9Mn7QoeBz+hDGxY9/SQR8lC+c= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 08/22] psci: Fix the function type for psci_initcall_t From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145529_451790_9CA94C38 X-CRM114-Status: GOOD ( 12.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Functions called through a psci_initcall_t pointer all have non-const arguments. Fix the type definition to avoid tripping indirect call checks with CFI_CLANG. Suggested-by: Mark Rutland Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- drivers/firmware/psci/psci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index cfb448eabdaa..75ef784a3789 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -274,7 +274,7 @@ static void set_conduit(enum arm_smccc_conduit conduit) psci_conduit = conduit; } -static int get_set_conduit_method(struct device_node *np) +static int get_set_conduit_method(const struct device_node *np) { const char *method; @@ -528,7 +528,7 @@ typedef int (*psci_initcall_t)(const struct device_node *); * * Probe based on PSCI PSCI_VERSION function */ -static int __init psci_0_2_init(struct device_node *np) +static int __init psci_0_2_init(const struct device_node *np) { int err; @@ -549,7 +549,7 @@ static int __init psci_0_2_init(struct device_node *np) /* * PSCI < v0.2 get PSCI Function IDs via DT. */ -static int __init psci_0_1_init(struct device_node *np) +static int __init psci_0_1_init(const struct device_node *np) { u32 id; int err; @@ -585,7 +585,7 @@ static int __init psci_0_1_init(struct device_node *np) return 0; } -static int __init psci_1_0_init(struct device_node *np) +static int __init psci_1_0_init(const struct device_node *np) { int err; From patchwork Thu Sep 8 21:54:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970712 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 3D57AC38145 for ; Thu, 8 Sep 2022 21:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=IiMintN/0JGxOf5+sqaybsoOyh6xlFZfbyUP54W7Qik=; b=Y/1W18keErquK8UNbsy7YFTfGb lXhhGHRnX77Huem5gtTLBvhQSN6YAfPmC3aBYU8vbo4Y8EH1eUQpXfNjIzhhFdBCch9dWsNcNrrVR BMWuMpCblqyFZVWmPC0eexAcSHV/EBQghzTOMic1irRIZhSO2oSXdFVdq/0+kJyqXzpBW1BpA9iWW m0FpfxMtJXbUiAvx3YngCWfYIGBzgpPWuqXzZx7kd4DjURJXn4ojy4oJHI+xBfHZjlYLR2dRjKTQo yWt5l7ZQgH1mvACQL3jMws9jJB9qufILb6REei/KtnjKecDY4bf5hlvpLJBgbRqQBNNTEXKdksHwi y3ttohqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPX2-0096fu-KW; Thu, 08 Sep 2022 21:57:57 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUi-0094u9-2c for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:33 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso155067967b3.14 for ; Thu, 08 Sep 2022 14:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=kd7nRdxqflfjkfBCCsD2lZrnoq302piOWQSyjQDRjtM=; b=rCh4lr1ufkzl4yS8kF+nfMcpwrlAzOVRSRecjzWmLGhjmCv9VTxM06OUyO8ZyYsMuv iE7KV9UdwWWI1W7jhW4fA3vXVwkgh+S5HxsyLNXQ6sQJO9KnXJhew6G0ucbCHk+1UzJp KmEHPLdMXhsbCOP8FapKLPiMxGMriLHn4RIb7/bVitT/Onx8woP45mW6I6E3qnvyjpvU IVHo6anrbJEBbjhNSckgwkMhLCuLf34ij48QwW8Lm/UkCUCAv15Euq1bKDi/95ss8kqt vwpJYHxrsLgV3A4xMpTiEOr9bs4MocSIMUWHRaYCUZ43Kyj8m08y1c7GmluFkLfFq7HR PT1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=kd7nRdxqflfjkfBCCsD2lZrnoq302piOWQSyjQDRjtM=; b=E4sMqV5UG1Svsw++vOim1NCK21XArkmVTAHXl82d8RsjkI54KIsXZ4LZPwdD57LpFL HVmw4ekQE2BnoxH8XahlNzWVKsJqI68cR0GduapHCea8HO4odKL1998yHUFu2d+b/4kY KCQbGbLfsMPe+03EdcVh5HxmgUxZzpqaayw6U/WYOB9B8lWesYx/vKsosDF0jVFiPiSl QrXDNTUJ/YuiWmI1uICBXtXrGnVC1HnbsLwZ8CsVntyZWk0BTnJlcIhWgsS9eHBnmEeN plfARMviZvCmO7dRpm1yYwHCzhJNiiAOuAjgiYRkFk7ZRlFcGPAB7oUqxuEF0UxX2+Dj qQDw== X-Gm-Message-State: ACgBeo3e+VnI8Zbi53bqB6NhRAq0eS2nGBcOnMJmD2JKvwVmpMh5Wul9 G9pHRnVMKwJD0ZVSdqbe/Y5qVv7HI0jlHR2nZHY= X-Google-Smtp-Source: AA6agR4KPWa5oXR9Ayg51w4kgTXhrwlsnnIwkIfkpKq1aF2MmA18JoPmR1m2Vj4mtaD5P058LPjkenrWxG9bUpOnOPo= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a0d:d5d1:0:b0:345:31d1:89af with SMTP id x200-20020a0dd5d1000000b0034531d189afmr9736636ywd.456.1662674130884; Thu, 08 Sep 2022 14:55:30 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:51 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-10-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=4469; i=samitolvanen@google.com; h=from:subject; bh=ZXDeWwVnHEvuHIlmhqXxiwu6hNYWmJItX6GE8bo4AiE=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS0ngozdPycUs52NDlFvKM6/yfKrCRvnRnqh9tm VzwT4tmJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktAAKCRBMtfaEi7xW7iBmC/ 44MOwJkkMAY9jfQS3hg2NgxpRx1Cqnq56fPQZCNbTFhgw+X9TuavRXXudgD2TNdcMlgmfj5R8pFL20 WO22k4Q0+dowr7xau/bDAlqC21Dt5VFqbhkQEk9dayxnkebGEIU2Oon993gW9+qTPEIuoQm2PWE4Cz F8Xqt3AsD2NbJE2pQlVht2stSPGDVMWli7P1u2w9JF+3zDT5oKHeNXoHGIKEEq3uuX/BH5zC6KDsgA a3k/RB3By7mzhF/2LDQkZ0hStWDPelx8WL0QMToeU9oqWlhTSggEwFHv96NCAA9wRPNoEYeb+SRuN2 HjRrQWMXpHFYEnGNn/O/i8b5IZF+NzzpheLKi0f7v//WUMJSroCGFrim7FxAY6GHw+OrfRiAcQXUtB 3Kv9nRuXNj4thhhE+FOYai/D+ghfrC/yTsqLZy5wb0Z4vWDAUft5cJ66Hla7IjCYVQkrtbUjxhjIiR Yd0k9DwonyvbgyuK4wjcYpQKxK20YJWvITEf9mTCfYm3w= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 09/22] arm64: Add types to indirect called assembly functions From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145532_157369_3B13E096 X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With CONFIG_CFI_CLANG, assembly functions indirectly called from C code must be annotated with type identifiers to pass CFI checking. Use SYM_TYPED_FUNC_START for the indirectly called functions, and ensure we emit `bti c` also with SYM_TYPED_FUNC_START. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/arm64/crypto/ghash-ce-core.S | 5 +++-- arch/arm64/crypto/sm3-ce-core.S | 3 ++- arch/arm64/include/asm/linkage.h | 4 ++++ arch/arm64/kernel/cpu-reset.S | 5 +++-- arch/arm64/mm/proc.S | 5 +++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/arm64/crypto/ghash-ce-core.S b/arch/arm64/crypto/ghash-ce-core.S index 7868330dd54e..ebe5558929b7 100644 --- a/arch/arm64/crypto/ghash-ce-core.S +++ b/arch/arm64/crypto/ghash-ce-core.S @@ -6,6 +6,7 @@ */ #include +#include #include SHASH .req v0 @@ -350,11 +351,11 @@ CPU_LE( rev64 T1.16b, T1.16b ) * void pmull_ghash_update(int blocks, u64 dg[], const char *src, * struct ghash_key const *k, const char *head) */ -SYM_FUNC_START(pmull_ghash_update_p64) +SYM_TYPED_FUNC_START(pmull_ghash_update_p64) __pmull_ghash p64 SYM_FUNC_END(pmull_ghash_update_p64) -SYM_FUNC_START(pmull_ghash_update_p8) +SYM_TYPED_FUNC_START(pmull_ghash_update_p8) __pmull_ghash p8 SYM_FUNC_END(pmull_ghash_update_p8) diff --git a/arch/arm64/crypto/sm3-ce-core.S b/arch/arm64/crypto/sm3-ce-core.S index ef97d3187cb7..ca70cfacd0d0 100644 --- a/arch/arm64/crypto/sm3-ce-core.S +++ b/arch/arm64/crypto/sm3-ce-core.S @@ -6,6 +6,7 @@ */ #include +#include #include .irp b, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 @@ -73,7 +74,7 @@ * int blocks) */ .text -SYM_FUNC_START(sm3_ce_transform) +SYM_TYPED_FUNC_START(sm3_ce_transform) /* load state */ ld1 {v8.4s-v9.4s}, [x0] rev64 v8.4s, v8.4s diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h index 43f8c25b3fda..1436fa1cde24 100644 --- a/arch/arm64/include/asm/linkage.h +++ b/arch/arm64/include/asm/linkage.h @@ -39,4 +39,8 @@ SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \ bti c ; +#define SYM_TYPED_FUNC_START(name) \ + SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ + bti c ; + #endif diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S index 48a8af97faa9..6b752fe89745 100644 --- a/arch/arm64/kernel/cpu-reset.S +++ b/arch/arm64/kernel/cpu-reset.S @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -28,7 +29,7 @@ * branch to what would be the reset vector. It must be executed with the * flat identity mapping. */ -SYM_CODE_START(cpu_soft_restart) +SYM_TYPED_FUNC_START(cpu_soft_restart) mov_q x12, INIT_SCTLR_EL1_MMU_OFF pre_disable_mmu_workaround /* @@ -47,6 +48,6 @@ SYM_CODE_START(cpu_soft_restart) mov x1, x3 // arg1 mov x2, x4 // arg2 br x8 -SYM_CODE_END(cpu_soft_restart) +SYM_FUNC_END(cpu_soft_restart) .popsection diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 7837a69524c5..8b9f419fcad9 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -185,7 +186,7 @@ SYM_FUNC_END(cpu_do_resume) * This is the low-level counterpart to cpu_replace_ttbr1, and should not be * called by anything else. It can only be executed from a TTBR0 mapping. */ -SYM_FUNC_START(idmap_cpu_replace_ttbr1) +SYM_TYPED_FUNC_START(idmap_cpu_replace_ttbr1) save_and_disable_daif flags=x2 __idmap_cpu_set_reserved_ttbr1 x1, x3 @@ -253,7 +254,7 @@ SYM_FUNC_END(idmap_cpu_replace_ttbr1) SYM_DATA(__idmap_kpti_flag, .long 1) .popsection -SYM_FUNC_START(idmap_kpti_install_ng_mappings) +SYM_TYPED_FUNC_START(idmap_kpti_install_ng_mappings) cpu .req w0 temp_pte .req x0 num_cpus .req w1 From patchwork Thu Sep 8 21:54:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970713 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 E3E59C6FA82 for ; Thu, 8 Sep 2022 21:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Orf1YLxAkT/Xrhb2WBEvzSInmK3n7ppFHaSRVxkRpYQ=; b=EuJVvJzZ3B76jdpLo+UYM8bSZT eAyb+h2jxcp+HSNqyuo8X9rxFzkTgNVqgMynxNnQjRugZ9FFshpzJeIS/JAOP3EkAqOtrnh9xyQxP 0mBazesoDiogaBL8K3tVTuaiGclO8FQIAGOhOyaEYOH719rPqC2mMChXPAqKESkHtlm9Z1At2fZq0 /yECB+65Lg3rYgm/6I6XlvRldBKYVGIvcHPhGY5W2GlI0ZPHTLErUjf0ySqfDw0zfcOGImoDhpf56 o5puz2zJz57jILd1TCwRgmmHCKsxuAakAVQadf+WZNu9+QmBIJgHK/ssZeYxPhD4eacJbjLXG1dxy 2oU604gw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPXW-0097AX-QH; Thu, 08 Sep 2022 21:58:27 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUk-0094uY-KX for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:36 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j11-20020a05690212cb00b006454988d225so9653ybu.10 for ; Thu, 08 Sep 2022 14:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=xUIiGKSm4wduWg23Tu0syDKyb899Hy/7xlDBrVmam7Q=; b=dOoGcHJVg127tDE6kjSdTfMsgzXzcqub02GrdOZQzyIJFfFX3Dzk4sgyyp/QY395Ts mH/ZbZXT1NEp8GEcjCJ0n4kO8gontmtFMPoLU+0ecx6tHoic3N1kie9uYmDWndODx3SU 3AZwI10g4IR/s7QvDVqawVh5EJhOnHtA22/JpSZWqOp0BLWnmZ2hcyBkPPZ+cCmehgX4 Osh6088+SIG2c6gcj+dfoyABrZWN9/bglT/6kuJvJaqyCcXi8z3+3p8VgAE3KklAr+pG uhVhoBXbMtSmCnoSKgM5wmod9uhv45NYDypqOcRWMEnO4cilWfZsMc8mZm5FXsdhwx6b 9bJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=xUIiGKSm4wduWg23Tu0syDKyb899Hy/7xlDBrVmam7Q=; b=mwDPyuFl1bYnvxxNinry81so5Ebz5g+XUhKMFAdxbLbMBVVljaNqOd6lEhzVNyIu8u lFK0ozr+S82DcuA1MTy1AYrMPC93YjddX644OnL7vfcda64jfqJ7k0eDHZtz7odyurwA 3JHl7QFmyWGO24JyKDbFO/2vixP0phOpxGdm58uhxNTytyU6IrvkZdLvG5OoheqnA6/u p51CqGtnXCYTywISf4xV6uQd4JFris2GvMs9dV06uUxlxWcDVmE0P8sCuWeN40v4GQ/8 1KRpxNyzC1X8Qum3hLj60RILwEhPQaov5sYOyrkYa2VSPUE3o9EoA7bHrYY0s7NbGl3e D6HA== X-Gm-Message-State: ACgBeo3r3y3Cbe1SqqP+BsUbS5IIajUS9t44EjqmGTsneN0PkyfXNfJC Ff+mAqsAcpyPO/I13Unx22L+R8PfEPtzC1paEIw= X-Google-Smtp-Source: AA6agR4vUDRVfqHUaReM1w5Kq0C6YAR1yqQtsuNTjhE1wQty1NhZxF2XtFK0o05oiiyebsiqQoGqIYzwRprCNlYaocM= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:d34e:0:b0:336:7428:dac8 with SMTP id d14-20020a81d34e000000b003367428dac8mr9601628ywl.94.1662674133445; Thu, 08 Sep 2022 14:55:33 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:52 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=6625; i=samitolvanen@google.com; h=from:subject; bh=XyaKOjBIyR6ipHRlO473Yg9X007Ywd+Fmw0kdF0HI3M=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS0ASWNwETssmwBh5NxM4y8wY0XXHT/43rDPqGd 8Ukdeo6JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktAAKCRBMtfaEi7xW7h4pC/ 0XqDoxj/PKBgq5swD0AxtBotx8Kc1w3kQb7O2RPMJWTse4Kd+PGOqS54jAH3LbS/aZXl4YLukAegj6 vXqR3JMXIuef7nEWUkymKAIrsDNh2wxSo5iRfZdY7SLEfI2rR+1v28+edSWtvBRt8zHcmHOiWCvgjD ZKb9PHcvS04XX+G6PRpF821r8QrB5+hlbqf9MePw/OVFXNkZH05uYmHgRfBayF1jRipnLLori2U5qK Vlj0E7flyBe+KTeNYKj/bd6IXuvJrcWOyhskDGWe2dDiIcnBNOiR1ZRR0+kupspuOV88ozhqFjJejL Z95DGowPaFcWRNNlAk05INALkgtm2mOd8uGAvbAUHPcQeHm+XanKcO5gTPA3Dne1iZIklgdy6o3kgN CCJ/VoAOFZg/sO4xjUbgw9deevs6TllbQDFPY1RE/GzQP4iNnc7YgsSUFHaA+Ewc6yi8UeGdMNUOcN PkRjMCV/BthVjYiD+Yj1S9oIndBZoJeS/ETK6in0OfP3I= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 10/22] arm64: Add CFI error handling From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145534_765383_C4EB0CD3 X-CRM114-Status: GOOD ( 20.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With -fsanitize=kcfi, CFI always traps. Add arm64 support for handling CFI failures. The registers containing the target address and the expected type are encoded in the first ten bits of the ESR as follows: - 0-4: n, where the register Xn contains the target address - 5-9: m, where the register Wm contains the type hash This produces the following oops on CFI failure (generated using lkdtm): [ 21.885179] CFI failure at lkdtm_indirect_call+0x2c/0x44 [lkdtm] (target: lkdtm_increment_int+0x0/0x1c [lkdtm]; expected type: 0x7e0c52a) [ 21.886593] Internal error: Oops - CFI: 0 [#1] PREEMPT SMP [ 21.891060] Modules linked in: lkdtm [ 21.893363] CPU: 0 PID: 151 Comm: sh Not tainted 5.19.0-rc1-00021-g852f4e48dbab #1 [ 21.895560] Hardware name: linux,dummy-virt (DT) [ 21.896543] pstate: 80400009 (Nzcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 21.897583] pc : lkdtm_indirect_call+0x2c/0x44 [lkdtm] [ 21.898551] lr : lkdtm_CFI_FORWARD_PROTO+0x3c/0x6c [lkdtm] [ 21.899520] sp : ffff8000083a3c50 [ 21.900191] x29: ffff8000083a3c50 x28: ffff0000027e0ec0 x27: 0000000000000000 [ 21.902453] x26: 0000000000000000 x25: ffffc2aa3d07e7b0 x24: 0000000000000002 [ 21.903736] x23: ffffc2aa3d079088 x22: ffffc2aa3d07e7b0 x21: ffff000003379000 [ 21.905062] x20: ffff8000083a3dc0 x19: 0000000000000012 x18: 0000000000000000 [ 21.906371] x17: 000000007e0c52a5 x16: 000000003ad55aca x15: ffffc2aa60d92138 [ 21.907662] x14: ffffffffffffffff x13: 2e2e2e2065707974 x12: 0000000000000018 [ 21.909775] x11: ffffc2aa62322b88 x10: ffffc2aa62322aa0 x9 : c7e305fb5195d200 [ 21.911898] x8 : ffffc2aa3d077e20 x7 : 6d20676e696c6c61 x6 : 43203a6d74646b6c [ 21.913108] x5 : ffffc2aa6266c9df x4 : ffffc2aa6266c9e1 x3 : ffff8000083a3968 [ 21.914358] x2 : 80000000fffff122 x1 : 00000000fffff122 x0 : ffffc2aa3d07e8f8 [ 21.915827] Call trace: [ 21.916375] lkdtm_indirect_call+0x2c/0x44 [lkdtm] [ 21.918060] lkdtm_CFI_FORWARD_PROTO+0x3c/0x6c [lkdtm] [ 21.919030] lkdtm_do_action+0x34/0x4c [lkdtm] [ 21.919920] direct_entry+0x170/0x1ac [lkdtm] [ 21.920772] full_proxy_write+0x84/0x104 [ 21.921759] vfs_write+0x188/0x3d8 [ 21.922387] ksys_write+0x78/0xe8 [ 21.922986] __arm64_sys_write+0x1c/0x2c [ 21.923696] invoke_syscall+0x58/0x134 [ 21.924554] el0_svc_common+0xb4/0xf4 [ 21.925603] do_el0_svc+0x2c/0xb4 [ 21.926563] el0_svc+0x2c/0x7c [ 21.927147] el0t_64_sync_handler+0x84/0xf0 [ 21.927985] el0t_64_sync+0x18c/0x190 [ 21.929133] Code: 728a54b1 72afc191 6b11021f 54000040 (d4304500) [ 21.930690] ---[ end trace 0000000000000000 ]--- [ 21.930971] Kernel panic - not syncing: Oops - CFI: Fatal exception Suggested-by: Mark Rutland Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/arm64/include/asm/brk-imm.h | 6 ++++ arch/arm64/kernel/traps.c | 47 ++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/brk-imm.h b/arch/arm64/include/asm/brk-imm.h index ec7720dbe2c8..6e000113e508 100644 --- a/arch/arm64/include/asm/brk-imm.h +++ b/arch/arm64/include/asm/brk-imm.h @@ -17,6 +17,7 @@ * 0x401: for compile time BRK instruction * 0x800: kernel-mode BUG() and WARN() traps * 0x9xx: tag-based KASAN trap (allowed values 0x900 - 0x9ff) + * 0x8xxx: Control-Flow Integrity traps */ #define KPROBES_BRK_IMM 0x004 #define UPROBES_BRK_IMM 0x005 @@ -28,4 +29,9 @@ #define KASAN_BRK_IMM 0x900 #define KASAN_BRK_MASK 0x0ff +#define CFI_BRK_IMM_TARGET GENMASK(4, 0) +#define CFI_BRK_IMM_TYPE GENMASK(9, 5) +#define CFI_BRK_IMM_BASE 0x8000 +#define CFI_BRK_IMM_MASK (CFI_BRK_IMM_TARGET | CFI_BRK_IMM_TYPE) + #endif diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index b7fed33981f7..3c026da95bbc 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -991,6 +992,38 @@ static struct break_hook bug_break_hook = { .imm = BUG_BRK_IMM, }; +#ifdef CONFIG_CFI_CLANG +static int cfi_handler(struct pt_regs *regs, unsigned long esr) +{ + unsigned long target; + u32 type; + + target = pt_regs_read_reg(regs, FIELD_GET(CFI_BRK_IMM_TARGET, esr)); + type = (u32)pt_regs_read_reg(regs, FIELD_GET(CFI_BRK_IMM_TYPE, esr)); + + switch (report_cfi_failure(regs, regs->pc, &target, type)) { + case BUG_TRAP_TYPE_BUG: + die("Oops - CFI", regs, 0); + break; + + case BUG_TRAP_TYPE_WARN: + break; + + default: + return DBG_HOOK_ERROR; + } + + arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE); + return DBG_HOOK_HANDLED; +} + +static struct break_hook cfi_break_hook = { + .fn = cfi_handler, + .imm = CFI_BRK_IMM_BASE, + .mask = CFI_BRK_IMM_MASK, +}; +#endif /* CONFIG_CFI_CLANG */ + static int reserved_fault_handler(struct pt_regs *regs, unsigned long esr) { pr_err("%s generated an invalid instruction at %pS!\n", @@ -1052,6 +1085,9 @@ static struct break_hook kasan_break_hook = { }; #endif + +#define esr_comment(esr) ((esr) & ESR_ELx_BRK64_ISS_COMMENT_MASK) + /* * Initial handler for AArch64 BRK exceptions * This handler only used until debug_traps_init(). @@ -1059,10 +1095,12 @@ static struct break_hook kasan_break_hook = { int __init early_brk64(unsigned long addr, unsigned long esr, struct pt_regs *regs) { +#ifdef CONFIG_CFI_CLANG + if ((esr_comment(esr) & ~CFI_BRK_IMM_MASK) == CFI_BRK_IMM_BASE) + return cfi_handler(regs, esr) != DBG_HOOK_HANDLED; +#endif #ifdef CONFIG_KASAN_SW_TAGS - unsigned long comment = esr & ESR_ELx_BRK64_ISS_COMMENT_MASK; - - if ((comment & ~KASAN_BRK_MASK) == KASAN_BRK_IMM) + if ((esr_comment(esr) & ~KASAN_BRK_MASK) == KASAN_BRK_IMM) return kasan_handler(regs, esr) != DBG_HOOK_HANDLED; #endif return bug_handler(regs, esr) != DBG_HOOK_HANDLED; @@ -1071,6 +1109,9 @@ int __init early_brk64(unsigned long addr, unsigned long esr, void __init trap_init(void) { register_kernel_break_hook(&bug_break_hook); +#ifdef CONFIG_CFI_CLANG + register_kernel_break_hook(&cfi_break_hook); +#endif register_kernel_break_hook(&fault_break_hook); #ifdef CONFIG_KASAN_SW_TAGS register_kernel_break_hook(&kasan_break_hook); From patchwork Thu Sep 8 21:54:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970714 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 4C701C38145 for ; Thu, 8 Sep 2022 22:00:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=y5toU0EEQL01Ond11n7jxOAtjtkpVq5cmWp8qW6qk4g=; b=qFETWhDl0VYMgOuu0KK82DKDUl ZduIHWcoB7MM3rBm828nRnrmnPGy/m/Gzei58pkgSjxf6CH8pHlmh6cPnsZoJA9vK47l9Jki4hwFh 36PvJPDDSZAn2+FLxJxPQF/UDI7VuuUVWf4NNUKqhk2brRuFWv8GLE6dfIS43QH04UwoYQ8sOrfH7 xoNWS/AX1Fse5poaBrnCnAixwSLa9VA4v5XM6TXv9GWdIpIIf+Mc3I1gpSh4s+bQUsuF06ThyeafQ su+eya0WkeFBfpWUaKXpOl16LDj4oRMbLjxn9uTLrYyrLfW1kQpbG0AeScY9XLCMcBztH8oCeJzq/ labuFSWA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPYD-0097lF-KG; Thu, 08 Sep 2022 21:59:10 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUn-009595-EI for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:38 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id k126-20020a253d84000000b0068bb342010dso33624yba.1 for ; Thu, 08 Sep 2022 14:55:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=7KCsYNBshzyqwz+l0HUO/3yj7Ulbak1Wm5CokVvWHxw=; b=DIhHROG1myYjjEhpDDuovfl12YIR789djqDBc/0u/J1mp/jTmDj1ZA274AXNCs0wnQ lmt14cCOg5xAV7lpluAZTs012V2TcViqt6Fd409oZVvFj0p9wbyvt/LLFB+NybSwk91K u+9M7YxBEfhfH2yyQGo/p6f85J2cc94NIvHZ/LuVGNYFFtuYWd5VHEkjDRPgyPNMunJi e/ovvDDwGfEoxULnywfqVplYbYMPNWVdNE3/YMVhdGKHwKfEZzBXlGUkX/CD3xlhu3Gm oMSNueVp741XRM009sKhSfbf+/5jCQGMUjjw7oSD0hz+mRDipd5luQd+9JHtoAWUa3OS yXCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=7KCsYNBshzyqwz+l0HUO/3yj7Ulbak1Wm5CokVvWHxw=; b=rd3YbZbYKgyLwd8dWxgFYeMjPjb+pL/yqoo13AMvuT/JSoffpkZAQJVb16dcvJIfPz HjcQGejs3uXN3Q1Fva6vOY38MKjGhRu9XxecBa+hlQnsO7T2xJf8iwEFWleGm7j7NNnx dbrpfkwitq5zpSWmmY9VP0XC5QUpa/6KdMo4qveEB1iRlLTivicN1OYbKSB9kLkIFvGB Cao5ambgOM4NVcDppQY3dWm4tt+8BCKyLNhZ2koPduu0jKeEAtY4ITCZc9rxa/jNrLWl c/HDpuqjjZXmQa/CffnSPXPyrCnoALs1AzO3IxV8fB9mDX5QNMrqYQu7RWf+mZIIZxjZ dVAw== X-Gm-Message-State: ACgBeo1GduxBJdazUqOYLYK0KML5XAeyDOXG6VQlWm1fFdrzmqKp02/p f2z737eSD+4nMUGqiXJZHMXgb1ilxYgwMhP5HkU= X-Google-Smtp-Source: AA6agR5oVGKtFANNU7ak0LdUo3bvPwshuUK58VUOg3cK732UV0PIyD9J8Zk0uzMLvmO6Ic7KKJZaWyMaNzKdVNVUY2c= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:1004:b0:6ad:aa9e:9116 with SMTP id w4-20020a056902100400b006adaa9e9116mr7779751ybt.559.1662674136099; Thu, 08 Sep 2022 14:55:36 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:53 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-12-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2488; i=samitolvanen@google.com; h=from:subject; bh=m1Q5lb7FoUHpFsHkDA6V80I7lJPiOUDvsppC/5IlC90=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS0+ybYcokQLe7u09cDWs1pssmZveUQDbXyShfl 0qFpXlqJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktAAKCRBMtfaEi7xW7kQbC/ 0WWiPP1mHnTVz7t1OngMVyaUyb9neZlJ7OpbOI0EfIIimSACkarT2JkjTEAgQ6++DdZZqsf36LWQd+ 0ZWcdl0DBqmyCCGe+5XV0PpYBYXczvoQ1yR3TSanBdkj6bZLiHubjFuVvagyLlXgC3wgh3wVHSOf11 vQKDFRyM5YiUNuhYYzdUCRvP3PbSenGg7miRaKoQxsZJUaCp4emo5/1BwLM55BH9gh8SHH2yiy08Pm csUoyf2U9XeAmXvcEjeBRb5lRlkPpbrSR8lTtXSd32UpGpxjuH2+nJS78hEgDLEB9jgYYmE7lITsFQ M942EAKeJ5oZPGNa/DuLNOHA17MEfry/ZhOJZm2s69FLdlWIlLJwYt5LsJ291JgMTbfgIzcLoeeW3G +Ar89i8WELO94059y9xGW8R0mQnXUoZrUspfi+/WBxox0/tqZseCbvv3RC0dIHL8rt+Z22cvOZk1z0 SqsrbinWt5ANVjNqClElsYpuxViZTY7OFOaXinxzeJHeU= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 11/22] arm64: Drop unneeded __nocfi attributes From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145537_504081_BFC7DBA2 X-CRM114-Status: GOOD ( 13.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With -fsanitize=kcfi, CONFIG_CFI_CLANG no longer has issues with address space confusion in functions that switch to linear mapping. Now that the indirectly called assembly functions have type annotations, drop the __nocfi attributes. Suggested-by: Mark Rutland Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/arm64/include/asm/mmu_context.h | 2 +- arch/arm64/kernel/alternative.c | 2 +- arch/arm64/kernel/cpufeature.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index c7ccd82db1d2..bba0e630c8bc 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -147,7 +147,7 @@ static inline void cpu_install_ttbr0(phys_addr_t ttbr0, unsigned long t0sz) * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD, * avoiding the possibility of conflicting TLB entries being allocated. */ -static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) +static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) { typedef void (ttbr_replace_func)(phys_addr_t); extern ttbr_replace_func idmap_cpu_replace_ttbr1; diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 9bcaa5eacf16..d2c66507398d 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -133,7 +133,7 @@ static void clean_dcache_range_nopatch(u64 start, u64 end) } while (cur += d_size, cur < end); } -static void __nocfi __apply_alternatives(struct alt_region *region, bool is_module, +static void __apply_alternatives(struct alt_region *region, bool is_module, unsigned long *feature_mask) { struct alt_instr *alt; diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index af4de817d712..ca6e5ca7104e 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1685,7 +1685,7 @@ static phys_addr_t kpti_ng_pgd_alloc(int shift) return kpti_ng_temp_alloc; } -static void __nocfi +static void kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) { typedef void (kpti_remap_fn)(int, int, phys_addr_t, unsigned long); From patchwork Thu Sep 8 21:54:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970770 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 E495CC54EE9 for ; Thu, 8 Sep 2022 23:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7ri1mx4Dmo56wSvsFFRuHNTDe/84kBo2oBIhGHTQL9w=; b=wQaah48ba9/uXuaZHg2P/8w8DL rapVYLcfVh9sNOYmlE0tsJaKu6B1+ayVirXnRDs4OXsRJYuKkSmXEkZvJWhXAfvtx7jeqArRP1eYG QDdt2e0TCaTjKkhEHBHrQ/FJ8qK0g90or6OpY1E1vaNEZVDe5yX1yeLa1fhLZ7ahLv/7iT7EXK0Rm TMGmKJuGRoUDrPLuKyU2bkxaMWCDMfBIX6IpgZWm4cfdJKc6hKY7/oXIf9jefCcNGSBhbO+uglVS+ nDC3qsQZz7zk68Onr0St8EY+BQEu06piS0UG29fT/qQ/ByfRqJ8RCX6A62ENuNCJURUuIUxvujUQh i8tB7VZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYt-009ckG-Ox; Thu, 08 Sep 2022 23:03:55 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYP-009cZb-VF for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=l/P3ICq7gexrMqe8SVvEbDdbAWpxQuadkoKvFylJkqo=; b=Y0KQGKNQf+gNXUV1PQ73d5Ayf1 2mI5ENe82NEMuKATTcnWArRXgZWuwEdG88PPxH68sSvamZVj2I2WC54XqTzdgYqZzHN5UMH9f8DyX 6e8Szav44JefHID308B/e5UARkkGdkgWCpHkLgesEw7wGmv78E4zsLmuysgZknlIvRbEM4W2xvQ50 NLCqYMTrUHJ5r/sTtv1h8Uytyiex4ahLyC1HD/qx29rVu9UQWV3dHd+SDyQqWTyovmObY29PYzOjG f/PlvVaFW6MyzRTyImTjO4Ktk7eMaqRnymnWO5YDITpIGsZXgj+NYrAOp6mJHTDjPp3GrixPHAzZn +RyG78Xw==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUw-00ApiG-5K for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:51 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-345482ec6adso101071337b3.18 for ; Thu, 08 Sep 2022 14:55:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=l/P3ICq7gexrMqe8SVvEbDdbAWpxQuadkoKvFylJkqo=; b=UD1ccXbRxz7Xi9ICwlivWXurmIf1Xil1VOXbXD+17fH0lgPb4/B2u8dw9zKCKXtt/3 sukLBKdMi754n+cnRVt7aJ6aF2qiIdjb7Tn7iFTED/shpoGeLxWfI2tpJd6IXSfGZ8t2 e9TK8HrAKj1NqLMpBNiEuvmWbQDwZFxQ8L1xUiyXgQTP5i1G1q5VBEgqHvYsdib61Gcp Of/JLPj0u8QieOMW6PDwecAc7/Y1Va52p7dY25pE3xpJSyiWqYAm5/hSkdGclfIJiuZL C2UHCzXvpzIyy/qrOKHG9tJWSZNaAoTKvJvr+avmfT1psQpkThKEw3GhAPdmJa4D/bV7 Hr1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=l/P3ICq7gexrMqe8SVvEbDdbAWpxQuadkoKvFylJkqo=; b=3N4jgnKAvfAu1MDAWgvt+yuSthGcNEjlgbTSEdHBcji+1eOqcZM1Tk7EPbxhHjAToa kWX/yQ/+4S3bwQc76duzKJp1lLO0K51ni8iQ8ffRAKANAZQt/LL5FZcITZPT/rGZnQy/ wC6Mja7sllqAFwUg81gDCpZtOoPdlaVgqHrh2uwRksn19mp46PsX46VD9g3TSTAHj9RP Nh6E54YYKqOpajdrspmXDMMfw94VP2O2QQNURUTllPJ2EYsrhT31Z+qKvh9J3T9EUeFz XfeTIbVKspUy1Q1YLTG6TMnNx8WuHmnXfeoepp0y3Y/poye04mnbTPJZaL+/FCNaV84x WQeg== X-Gm-Message-State: ACgBeo3PKBOYbQTSasSE3tAUQxY1wh11TMFQftpzJf1Lck15eytlcOc8 lW3xTGafnLG6l4TJvGLQipFMpOroICMH0Lfot8k= X-Google-Smtp-Source: AA6agR5a0urzcgqtiNi5U9w+rnOkqDqa5tT2drcbxAab7k4RS46CA4kYqncx6Fwz1a0FDqqjBnC3YLNEgfnP18OQ3Tc= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a25:fe0e:0:b0:69e:7884:5006 with SMTP id k14-20020a25fe0e000000b0069e78845006mr9202550ybe.579.1662674138614; Thu, 08 Sep 2022 14:55:38 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:54 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-13-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1029; i=samitolvanen@google.com; h=from:subject; bh=w1Y02HzgeI7knEEHZIsxDg9VMOLQptocTxv/oc51D5c=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS16oHvirVLE2hytnBruHp3nBLqOD6x/WQZ2qt4 k4D51yOJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktQAKCRBMtfaEi7xW7rtWDA CXo6kB5HgNU1fcH0EhWUjrQsIumv8nz+i3x4vs5z30oE5HTRA51x2U2Nj4SgyDDY+V7G3AvUwJPgJg +kh0h/5jfijyYIrOTp2uo2EwB7HGCftq2TsfHjHbWza75F8VwBo3dDZrkPSaYvyKB7YRRlPNZeaUZU mIa31uMuqI6xdH5hSQC6zE6Q2yRZgDmPlNhZjiS/bm5AQQI6TS7I2Jj22NX6XTDphP6IsaZV0Rfh84 pd/NRoIzlZ2qsoyx8ywRjV0rtvE0GZvGKXazpkxzM9JAdR1ClstW9ayMVYXZsFK4RGZr3NXn9ZX5xY VTbTQvixgrAiEeQxvNoNp1SPMqoWWbiE2irbxsBcWQLaQorjCc961X61Z+oexGMcZveQgMIlx5F3d8 5kK17TKdfDnyFXi23EhOL8a8FIHs2t01MVbt+2yu9FluH26SdZ79Fq2C4aUCaIZYwXl32I0fLjzDr6 HDN9J7SFmEbYwlMfsxgEGsmu1LWGTJCDCgZARrqumu0hw= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 12/22] init: Drop __nocfi from __init From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225546_807193_211F0B52 X-CRM114-Status: GOOD ( 12.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org It's no longer necessary to disable CFI checking for all __init functions. Drop the __nocfi attribute from __init. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- include/linux/init.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/init.h b/include/linux/init.h index baf0b29a7010..88f2964097f5 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -47,7 +47,7 @@ /* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(".init.text") __cold __latent_entropy __noinitretpoline __nocfi +#define __init __section(".init.text") __cold __latent_entropy __noinitretpoline #define __initdata __section(".init.data") #define __initconst __section(".init.rodata") #define __exitdata __section(".exit.data") From patchwork Thu Sep 8 21:54:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970771 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 DDF80C54EE9 for ; Thu, 8 Sep 2022 23:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=50ZdMiG0KCOQES6TTP01qBTop7JNyGRSqglDZsMtneg=; b=2ngKdiwa985njVvfWsRRv0wFq9 aChz3kXfphnpW1BOTxzxgC51scV8PKyJ8nOTsVKGCGHGaJMIN4VxNBzfLVJLWZVVREGzZPMzrKjuj BAgRQa2cmrApC41sqodiYXDTPnnneYQggGOfS6/ril+c5zi0d6p1ZSUIW4rVX/0kFffCPg0ca+lpp JPmeegVb1tX0vQgtOC/6u4VZqmt+T2V4bT74V88X78hmeXEWo92YJB3fign6MDOhUFgHJX8SX7fPd gEx9yw7rtVTShj8M+AB4n79JB6pruYHNhE4jWMn2LuRa5hOmv5nf9fHOJHVwRCQStH2e6CfeK+OiY nR2T8eLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQZD-009d20-I9; Thu, 08 Sep 2022 23:04:15 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYU-009cZb-Q6 for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nVJuCRZFiOKjcgDzOiON7GnbFw8l3H4+M/UIBuq716A=; b=hzAAfmPwhUR/Eceu6KKHvG5Cp7 sm9bYvD42mNH9MFDJkjaYEjr5TdRvTBcJv4Zv98Ibk3OnydwfqIgUSw8TdghRjSJwMwD4fT4wp6zy PRBOd4StRGe6WTRnvTBzTgIV/jHEn1cObTYu/auNiJiBMIX3iap3GYhFdY8IJSsvwuCRHPe1nckK1 CXTTcsts9FD8VQ21awkWRfk7o1uusrPzQKoqXUHQR7d5V10n4pJ5YqZRLdTh5ar+Hv6hbH4SokaOt OtxhLFOGCPr2qIywFEMBmy7MV0oaQ3+qGfoC1J+rOqjMgoPwWG1GcB6UUM1dQyrg3LkoNkR1uSceN JuwPkcWw==; Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUv-00Apif-HU for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:48 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id f3-20020a056902038300b00696588a0e87so28385ybs.3 for ; Thu, 08 Sep 2022 14:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=nVJuCRZFiOKjcgDzOiON7GnbFw8l3H4+M/UIBuq716A=; b=eN/8i1D/vATeIQD65/jlq2ad3UXPIbG0ihZWjcO9a9q5jiHPVwWyOXzBlY6xHvxHUc eZ4N+xX0j33G5M/j/q+uG98g0alxX6W1PO10Wf9se5bjs2oEx5Wb0wNV8mQeAhW/smDo qnQDqIbmVBcKSlPvgaEbUK2vwWR9wXQ9RTn66iB+VmRMezifht6hj8NRSPjwfi+ChIQG 3WyPL8VretIWJAvRZY72acfQVMJFnmBwa3s5DSMpFQGUwhEeNueMMaauXKRmhgVuyVdF 0VYDX1ly/PL3NVda0z+A+IA6UvGQxN83hSrYgwRWNSfehs4FdaXPvYDf+crgjcqYHn4a vzvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=nVJuCRZFiOKjcgDzOiON7GnbFw8l3H4+M/UIBuq716A=; b=a38IH+Dc2F+gqGuWmEdet937jpsbIIGMmXARN7a5VdMXl/HzNRWAVMk+ZPlT8UttoG 5/fLrtNMhE6sgufPMRbRnwwqeRskjmdjVGxRrrtB4l1JcM7Vo6OCx1NtIZdGqXn7g2vb FFr4wRe4TB9gr8a8NkDiRFdXYedjd9BZizcKQKjbJheGwTLMJzA3VkcayDlqRJJ0gXwm zmeWRb3pu2oGGAIEdzU1Bq9nnsTjl/rH7I8FvWjfsxMQJ+TOETYZR+koX3hKjV28hIHV 3GQNMd9Evsmx3A9cMJu6AGXCTRrfJNJ3ZqYq7WYiHv8RNgaCBAcDBtTaRBbw0KVLPqYH A/Hg== X-Gm-Message-State: ACgBeo31VQ/nuFO3uBbPhhsb1W6T43mGFz+zTL/Ah50QeCW9sjNxa5r/ D/8DUAnjrb3uIPz7D2GNXGwbGulTjwm3fFL49wA= X-Google-Smtp-Source: AA6agR5DfwfM0XccFEMr3z3JD+l4duBgSQ3NeeMnm3VD+CyqOtYCAf4ZbixIQIy5/0q7kRKjuLgOG8/eeVOSSwQdQYE= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:91d:b0:672:e583:9ed9 with SMTP id bu29-20020a056902091d00b00672e5839ed9mr9270680ybb.225.1662674141192; Thu, 08 Sep 2022 14:55:41 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:55 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-14-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=7576; i=samitolvanen@google.com; h=from:subject; bh=nyEfjFnzWhpm01bBNm0duC3vRmG3jrqNCTbOmyVKuqE=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS1gXCwikEA41+95htM7367G130ucWT6xEF7oVu kt7sawqJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktQAKCRBMtfaEi7xW7hxRC/ 4wzEk+rM2ywbVvCu2pWG9r92js1+BFxzRzhIY0O7cOVhheCaRfYvpXdTMn8WApj04b7pAAgi0QXmIA EeB2omE/XqcrsZOyZfvPREa9IBkCGRsDfk/zc+2obFCroZttP75vW6bXgHf+nOmh0RRsrgp3CAp2lJ qFFLrf+ysPi9jpG1McThp9tUF+kq/jagglF5rLd/4x7GFaL5Pb5BRt1L2spk47kNitDjzI6wXjK25K t0MSBker0UJQ8pP2ikQyy8oa9UBwfoEnQ+EI/sGgUbvhStIKvcFLfm9cRP2sD9wxudmWCEciS7tkPy n1fJfBVW96ZZxwDBLOKsgWszseEGY/Z+c+2J9J4WWMQ66JgKCNs+uBssJap+ShR625jyJBt6jPD8lk EkCkmOGLfj8nYiKxW8pTUgsH0YcXXlGh/x2LVsN1y3ym/8I3GCkyMovYOx3wvOu9Rv0gohh0y73l67 tU+au9puX0b0Azc/TLpAOCNze2FT5GepuPlBoq/s5MVYs= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 13/22] treewide: Drop function_nocfi From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225546_249596_A27A607F X-CRM114-Status: GOOD ( 18.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With -fsanitize=kcfi, we no longer need function_nocfi() as the compiler won't change function references to point to a jump table. Remove all implementations and uses of the macro. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/arm64/include/asm/ftrace.h | 2 +- arch/arm64/include/asm/mmu_context.h | 2 +- arch/arm64/kernel/acpi_parking_protocol.c | 2 +- arch/arm64/kernel/cpufeature.c | 2 +- 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 +- drivers/firmware/psci/psci.c | 4 ++-- drivers/misc/lkdtm/usercopy.c | 2 +- include/linux/compiler.h | 10 ---------- 11 files changed, 11 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index dbc45a4157fa..329dbbd4d50b 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -26,7 +26,7 @@ #ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS #define ARCH_SUPPORTS_FTRACE_OPS 1 #else -#define MCOUNT_ADDR ((unsigned long)function_nocfi(_mcount)) +#define MCOUNT_ADDR ((unsigned long)_mcount) #endif /* The BL at the callsite's adjusted rec->ip */ diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index bba0e630c8bc..d3f8b5df0c1f 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -168,7 +168,7 @@ static inline void cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap) ttbr1 |= TTBR_CNP_BIT; } - replace_phys = (void *)__pa_symbol(function_nocfi(idmap_cpu_replace_ttbr1)); + replace_phys = (void *)__pa_symbol(idmap_cpu_replace_ttbr1); __cpu_install_idmap(idmap); replace_phys(ttbr1); diff --git a/arch/arm64/kernel/acpi_parking_protocol.c b/arch/arm64/kernel/acpi_parking_protocol.c index bfeeb5319abf..b1990e38aed0 100644 --- a/arch/arm64/kernel/acpi_parking_protocol.c +++ b/arch/arm64/kernel/acpi_parking_protocol.c @@ -99,7 +99,7 @@ static int acpi_parking_protocol_cpu_boot(unsigned int cpu) * that read this address need to convert this address to the * Boot-Loader's endianness before jumping. */ - writeq_relaxed(__pa_symbol(function_nocfi(secondary_entry)), + writeq_relaxed(__pa_symbol(secondary_entry), &mailbox->entry_point); writel_relaxed(cpu_entry->gic_cpu_id, &mailbox->cpu_id); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index ca6e5ca7104e..d8361691efeb 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1713,7 +1713,7 @@ kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) if (arm64_use_ng_mappings) return; - remap_fn = (void *)__pa_symbol(function_nocfi(idmap_kpti_install_ng_mappings)); + remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings); if (!cpu) { alloc = __get_free_pages(GFP_ATOMIC | __GFP_ZERO, order); diff --git a/arch/arm64/kernel/ftrace.c b/arch/arm64/kernel/ftrace.c index ea5dc7c90f46..26789865748c 100644 --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -56,7 +56,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func) unsigned long pc; u32 new; - pc = (unsigned long)function_nocfi(ftrace_call); + pc = (unsigned long)ftrace_call; new = aarch64_insn_gen_branch_imm(pc, (unsigned long)func, AARCH64_INSN_BRANCH_LINK); diff --git a/arch/arm64/kernel/machine_kexec.c b/arch/arm64/kernel/machine_kexec.c index 19c2d487cb08..ce3d40120f72 100644 --- a/arch/arm64/kernel/machine_kexec.c +++ b/arch/arm64/kernel/machine_kexec.c @@ -204,7 +204,7 @@ void machine_kexec(struct kimage *kimage) typeof(cpu_soft_restart) *restart; cpu_install_idmap(); - restart = (void *)__pa_symbol(function_nocfi(cpu_soft_restart)); + restart = (void *)__pa_symbol(cpu_soft_restart); restart(is_hyp_nvhe(), kimage->start, kimage->arch.dtb_mem, 0, 0); } else { diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c index ab7f4c476104..29a8e444db83 100644 --- a/arch/arm64/kernel/psci.c +++ b/arch/arm64/kernel/psci.c @@ -38,7 +38,7 @@ static int __init cpu_psci_cpu_prepare(unsigned int cpu) static int cpu_psci_cpu_boot(unsigned int cpu) { - phys_addr_t pa_secondary_entry = __pa_symbol(function_nocfi(secondary_entry)); + phys_addr_t pa_secondary_entry = __pa_symbol(secondary_entry); int err = psci_ops.cpu_on(cpu_logical_map(cpu), pa_secondary_entry); if (err) pr_err("failed to boot CPU%d (%d)\n", cpu, err); diff --git a/arch/arm64/kernel/smp_spin_table.c b/arch/arm64/kernel/smp_spin_table.c index 7e1624ecab3c..49029eace3ad 100644 --- a/arch/arm64/kernel/smp_spin_table.c +++ b/arch/arm64/kernel/smp_spin_table.c @@ -66,7 +66,7 @@ static int smp_spin_table_cpu_init(unsigned int cpu) static int smp_spin_table_cpu_prepare(unsigned int cpu) { __le64 __iomem *release_addr; - phys_addr_t pa_holding_pen = __pa_symbol(function_nocfi(secondary_holding_pen)); + phys_addr_t pa_holding_pen = __pa_symbol(secondary_holding_pen); if (!cpu_release_addr[cpu]) return -ENODEV; diff --git a/drivers/firmware/psci/psci.c b/drivers/firmware/psci/psci.c index 75ef784a3789..bc6b5a12bf74 100644 --- a/drivers/firmware/psci/psci.c +++ b/drivers/firmware/psci/psci.c @@ -334,7 +334,7 @@ static int __init psci_features(u32 psci_func_id) static int psci_suspend_finisher(unsigned long state) { u32 power_state = state; - phys_addr_t pa_cpu_resume = __pa_symbol(function_nocfi(cpu_resume)); + phys_addr_t pa_cpu_resume = __pa_symbol(cpu_resume); return psci_ops.cpu_suspend(power_state, pa_cpu_resume); } @@ -359,7 +359,7 @@ int psci_cpu_suspend_enter(u32 state) static int psci_system_suspend(unsigned long unused) { - phys_addr_t pa_cpu_resume = __pa_symbol(function_nocfi(cpu_resume)); + phys_addr_t pa_cpu_resume = __pa_symbol(cpu_resume); return invoke_psci_fn(PSCI_FN_NATIVE(1_0, SYSTEM_SUSPEND), pa_cpu_resume, 0, 0); diff --git a/drivers/misc/lkdtm/usercopy.c b/drivers/misc/lkdtm/usercopy.c index 6215ec995cd3..67db57249a34 100644 --- a/drivers/misc/lkdtm/usercopy.c +++ b/drivers/misc/lkdtm/usercopy.c @@ -330,7 +330,7 @@ static void lkdtm_USERCOPY_KERNEL(void) pr_info("attempting bad copy_to_user from kernel text: %px\n", vm_mmap); - if (copy_to_user((void __user *)user_addr, function_nocfi(vm_mmap), + if (copy_to_user((void __user *)user_addr, vm_mmap, unconst + PAGE_SIZE)) { pr_warn("copy_to_user failed, but lacked Oops\n"); goto free_user; diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 7bfafc69172a..973a1bfd7ef5 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -203,16 +203,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, __v; \ }) -/* - * With CONFIG_CFI_CLANG, the compiler replaces function addresses in - * instrumented C code with jump table addresses. Architectures that - * support CFI can define this macro to return the actual function address - * when needed. - */ -#ifndef function_nocfi -#define function_nocfi(x) (x) -#endif - #endif /* __KERNEL__ */ /* From patchwork Thu Sep 8 21:54:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970769 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 9465CC6FA82 for ; Thu, 8 Sep 2022 23:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=s311ZOL6E+o4GBpczAvHNyothHENbtZROkz/mWlD4Mc=; b=eFlKIjU/DzoYprrpd3y9ordPZu VFI3NBgILo9sQONtDV2vO+Re2uM0tgg4CdiAercbt1lJthpu0tUvWMp4yG18Qe4EwZc21X0TnigSP WvLBlA2HrhGshk/4bKDdYdWxbhWFmGPIb+f7BjuWaPKPxLhjQynhyJ0hBsHjGtaSkuR6egToIbEQ6 QnuflJPN7kD5AnfM3707JybX1Z2IyrnfGNSzpa0pLMG6NkhW0+8vvTn9tqDDfSdVUY7d7tkXI3hC7 4WIaBcCPwvF9EZB7AYjM2Y/aM/du1nIzmWSs3wrjvf1EL5rHxY5M8c0hijM5UnWDc6tqBgPKU5UXl 6zOBvu+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYi-009cga-HF; Thu, 08 Sep 2022 23:03:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYO-009cZb-8M for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rhfWVw2Tt6GniVljFSWWIZP6qvrP1Bt+EpFQklJviQg=; b=c2sPLj8s6uC2MuQYpoznO7lAOd X8j9fb+hYt98f7F6qWTzX7cor0zEJS1WaY5hHTOmbatOzusEfDcAILxfExY54YZP6oaktY1Q0iT0K SEuM0eLUbYUAcQWW+AO3KFJFX+zcbV5Fza5jLdwqSzwmDZ4MwxtubZGNz4iPovogumUYXmM5wT6wR zNf2v/0JuWyReVr+cF/2MTUvf12/JWwiK1RutxT+g74z1zPbkUof4VEapTNgXjDG8Z/Sv5+rT2Gyq 8GKoPiTGk5Q8Ck0GLQJ2O+81SGF9YgxTTER8kYBe1/ze9iDKSD38e20z+XRPC1lD+iv711iMI5m/7 p6MVzvnQ==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUw-00ApjB-Cp for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:51 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-345158b6641so123029427b3.8 for ; Thu, 08 Sep 2022 14:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=rhfWVw2Tt6GniVljFSWWIZP6qvrP1Bt+EpFQklJviQg=; b=rBEPQ4+OEMorFD29QkedGsA5RpGHUqTP7GLuQ0VPeUKArjbKJU8SW+fxXED2Vd5a1h JJUUSU520wi2pjhCxnuq64qsHd7eeRMOLTOxRcJREUzEeMCnZffzC9Sejn5br6Dp3oRI VtYNY/fx0j2QmFk6XksNtrBgzLzZc7TZuBNeE1R7P3dhP8AW0152lJLseebduBWoGVwY 56ZWPGa+w9Poid6Sqb4ezZ8XSDwmza2TOXUIpjx5plHpJsxzs8aTSsCu3tvyVQfzL4Yq +vz6teO2Y1xnr+a4/sJVXBA8aGm7OpXVW/b+4LPfwoav6RhVJFXhZfDrJxw8jeUR7dLb c0SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=rhfWVw2Tt6GniVljFSWWIZP6qvrP1Bt+EpFQklJviQg=; b=p4oobE3kvnFSR5NeOJHmD1vVSkLwCDBOAnwRmRrmp8T8hbeD11eJxt3ypHR7hAO4uX KB1MAs8W/NENsr/SwDvHrzNorSlWgZom8sp0V+cCjOXqPUOQuMHaILfzc63tCFgy9phQ 2Khxo3O6ZeMjnVAI7IdZwgQkVJhqOPDGBbQVdIhBnEvEHJvCPs9+z2yQEuwCXnN0JXGE KiRmBOMHTJWukqCQcZuq8YYKnzNwDBhblYJY4sTLkOwKZ16OKVayE81jStJv0Zgg4evr J/Ejf065UAPu+ytosqreS/hDIDsdcFgAahkjNClBQPDdevTCFaD1Ej2TVpIFTZ0kJ8qx m6CQ== X-Gm-Message-State: ACgBeo12DeWTbdkLsnUGt1yxQJ8tf2pJ76sHsafnjVzVyCbyiZprasUt vtX6+cpdR3B4uD1oe5nLIrrIzcIeCuoVK3dalwI= X-Google-Smtp-Source: AA6agR4VEuPwY0OLtERuEFUSCoro8TKqIchnXzuH3Fn0GxKp01Y7VKyK5nLSYCSe8NlEN8Re6tpG69iiBtglmydYWFk= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:a055:0:b0:345:1b99:ed4e with SMTP id x82-20020a81a055000000b003451b99ed4emr9315882ywg.328.1662674143700; Thu, 08 Sep 2022 14:55:43 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:56 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-15-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2636; i=samitolvanen@google.com; h=from:subject; bh=w7QGhX+Lm2u0dGfo5IkCUJxEEQABg5P9ss63DNtvmfM=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS1pTQ7rbPML1xK3u3MyRnli2UqPoMtOjmJxcUm IFPo2WSJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktQAKCRBMtfaEi7xW7l+3C/ 9AJdP32IFBSwJ7l2Qym+RBRnr2ygFJQYgT1jNXFKJ9xpuJIadyULM6tlc8ytuNOwFEV+GZmK7GAUzY fl9ZCj5ZBpeNQD2a9xAEEqKgTyWFYTNcMoGQo5PiHm7rWb5AQ+nvPPnf85/qKp+rwgzULwfVIld+eD FWRTqltYYgZAzgpZYfOCpRrGPOaqR9In1p9rLuyY8Be1/2J1L+Ee1GwtSs/sWW+AlnQ8ZzJs9qrK2m dLb084sArMyaehwUYetynBFE7OB75y2bxXFJ/xThRF8muTmxxh5kabj/uKOqaSE+fcD0ozIZQlmtlt g+T3ZgD3tKdwL16ckdrWO4h/QV4q9xl4kwT1DrUyt+PRxclovxjt//IUNblQ6qc6zbvpt9Oa6qk4p3 YF0hXH2cZQ27IY2KxWq2Yux8LPDHQFIsN1eSOo1TZ5eh14FO8rq8Caf8fkJ6NmCKZVh+AZ0d+fW1r6 kNPtER09RCEOJgr553VIBlOmBbi0KAwQohDMzytED2ld8= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 14/22] treewide: Drop WARN_ON_FUNCTION_MISMATCH From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225547_192487_34D5A147 X-CRM114-Status: GOOD ( 15.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org CONFIG_CFI_CLANG no longer breaks cross-module function address equality, which makes WARN_ON_FUNCTION_MISMATCH unnecessary. Remove the definition and switch back to WARN_ON_ONCE. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- include/asm-generic/bug.h | 16 ---------------- kernel/kthread.c | 3 +-- kernel/workqueue.c | 2 +- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h index ba1f860af38b..4050b191e1a9 100644 --- a/include/asm-generic/bug.h +++ b/include/asm-generic/bug.h @@ -220,22 +220,6 @@ extern __printf(1, 2) void __warn_printk(const char *fmt, ...); # define WARN_ON_SMP(x) ({0;}) #endif -/* - * WARN_ON_FUNCTION_MISMATCH() warns if a value doesn't match a - * function address, and can be useful for catching issues with - * callback functions, for example. - * - * With CONFIG_CFI_CLANG, the warning is disabled because the - * compiler replaces function addresses taken in C code with - * local jump table addresses, which breaks cross-module function - * address equality. - */ -#if defined(CONFIG_CFI_CLANG) && defined(CONFIG_MODULES) -# define WARN_ON_FUNCTION_MISMATCH(x, fn) ({ 0; }) -#else -# define WARN_ON_FUNCTION_MISMATCH(x, fn) WARN_ON_ONCE((x) != (fn)) -#endif - #endif /* __ASSEMBLY__ */ #endif diff --git a/kernel/kthread.c b/kernel/kthread.c index 3c677918d8f2..28a6b7ab4a0f 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -1050,8 +1050,7 @@ static void __kthread_queue_delayed_work(struct kthread_worker *worker, struct timer_list *timer = &dwork->timer; struct kthread_work *work = &dwork->work; - WARN_ON_FUNCTION_MISMATCH(timer->function, - kthread_delayed_work_timer_fn); + WARN_ON_ONCE(timer->function != kthread_delayed_work_timer_fn); /* * If @delay is 0, queue @dwork->work immediately. This is for diff --git a/kernel/workqueue.c b/kernel/workqueue.c index aeea9731ef80..16df315d2a3d 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -1651,7 +1651,7 @@ static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, struct work_struct *work = &dwork->work; WARN_ON_ONCE(!wq); - WARN_ON_FUNCTION_MISMATCH(timer->function, delayed_work_timer_fn); + WARN_ON_ONCE(timer->function != delayed_work_timer_fn); WARN_ON_ONCE(timer_pending(timer)); WARN_ON_ONCE(!list_empty(&work->entry)); From patchwork Thu Sep 8 21:54:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970715 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 9E720C6FA82 for ; Thu, 8 Sep 2022 22:00:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=3kl9p4bFWCKjxG8dlezMo0Zwcs8x7TXC8H2pSnFVhbQ=; b=06HVQLbkqRsfRmOiY17TK/AnrE qTCf3zy9rnroRRTgV4CYLrf+Je2ADRF1/B8YJx2tp0Sc8IhHmtmld+jxJKYV1VcMFkiHcaxocJp7Z dOw41yc/pnjPbOkGV+FSJpvMh79n2Yzb4BQp6mfqlsZhlA+GxTk0Gt9kNt2wVyMJ/oVhgiQ/z+2DX SISBiYzLLHwq0kGzXHr/MCXQe9Sefeg7Wp1uowYzqxZAnKVo0aiO8t9b8AeNj1hYBf+CWs+ZL3SRS fl8eEANTOt/uYyaIY9Th1+xVd7M0oVu1sU8BTELZm2V6pqc5QLS/f5MoZIoMi/bcFD6+x3nARBGv0 AlUvPkcA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPYm-0098Ia-Kv; Thu, 08 Sep 2022 21:59:45 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPUx-0095CX-Pl for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:49 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id k13-20020a056902024d00b0066fa7f50b97so20287ybs.6 for ; Thu, 08 Sep 2022 14:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=P5XeXy2GIaSKYLkYAqglVvjH3kuWJ9tPWJSwe0Lo+wY=; b=hx62HzwiHzddRJHYtkXI4QajxL+odl+FO37dBOwfzxb8NNyzv4/yv9wyRADQYJHrDX JWYICnxQ4HQoyr+yvMUobWEYirWtQ3HKANeu1Y10LPfeC8jSnGodKUs0g3EtRQ4kT6Qd 0D/oc6nRgHCzFZSC18Qkj01D2+egHql1wXi106mydKoVY9hY4FURlxCXXnmzShibH931 phOl2Z0Pl+pvetz46HRs02jeeQFZkr5T3Ek1VjoeP/LjPvf1uU0rMP/1kLJXm6t+6ap/ LclWruX1iYwlH8NynScn/a6VSNGCyHyGI3XOynkr7rwXG4AHts4qQprn8mhR8A+VZd33 cRqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=P5XeXy2GIaSKYLkYAqglVvjH3kuWJ9tPWJSwe0Lo+wY=; b=n4flM49E8XBy79qVJp8Zq6gbzq2R1PfWPqHfDoeKZvalgyZnwt4tJ1sDzlyjXx29jW KU/GL8gn1XLe+Pqyp1ayUQOoHQrtbrPbnoiE85IT+um1/qKa55yajMMnEvm2EnFmqGzz GeqK3By0XBpgDxENK4bHTssLnCHi1/LCKahYRaBdp9L1MO5uPSbuviP5llyhijLR92i4 CxplzdKyq2tQW1icmkDA2mCGbZw0z4I8V3AeFSk2t1m+lYZvZh6B4UXPc/Tv62wYhBcO qli5VU39Hh8wWNcDKCivbf/mO6vzA0IeqqDAhJlEWR6DJMFMO9FRR2lUhsw0V/rnuhWN o5Cw== X-Gm-Message-State: ACgBeo0MyJXZTG9RQGs7clbaN4GgXT++R6fcHK/gLC/9PxmVLuK1A7nm eg/vXsZB36JO1nhErhIUjZPReEh2GiQdv28CwIQ= X-Google-Smtp-Source: AA6agR4HGxS3+r7EWurz3pEdejYHxzCA4+e4KopmW1I2S8OfDWvRZ5OIQmq1djGZpkTpe4gyzuVYJnGHX359T2kom9w= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:10c2:b0:6ae:131a:eac3 with SMTP id w2-20020a05690210c200b006ae131aeac3mr6582686ybu.276.1662674146355; Thu, 08 Sep 2022 14:55:46 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:57 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-16-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2291; i=samitolvanen@google.com; h=from:subject; bh=mON8m7x3rUfa1D0nlNPBxEehMr1A/zDxXAQAEngsFEg=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS1cVYdHINNLoBeCZ9uFVNyEFfBwFNRQPTvzufN DW569WSJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktQAKCRBMtfaEi7xW7n1fC/ 9ntySdFzUO3oTsyY2vU09I6p+wIqQMm9FgTwxmaQG1446FzMM4pSm/SX4JhZE9j5JO8X+roj+rnp/z hoLKBrMvE4bR6IyFTxO7Mvy3qSC20smGCBNQEzlDovULvMTBcz9vOxRopVfnk1UYwSrW9ctflDk9nk 4LAs9n5qb3YgtVh/R/Z8eYLffSUyid4RzFUP2hrOI9q4u8FDJmS4YcLXzXQXdrINqm1HCS+DuVZb2M cdX+RhevB8yVxZTIf7jZ/lUySTbyUOmjWUD8pHjbJcoo1ntxHci8Vmq1K4CjD6c3APzuxeX590QJkn KBYWzy/6MpMlQgqnqc+zSj9GPWNf3cOKfDlgR7zqw8OW/C1YzhnW9F1HGhVHZFo+7ezUBee0CAFSQI gcxtb0a8Df7ZA5bqq/2Fvw+mJSr2Po2uEi1HUVMcMh0t2DWkOSFxvudPDClnFcZve5BqD8NPpHJYmZ eVj3Qsqgk+JqnpMPVr/Oucx4m4puzPjSBwSLTyV7Uh0w4= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 15/22] treewide: Drop __cficanonical From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145547_858016_6A73C783 X-CRM114-Status: GOOD ( 15.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org CONFIG_CFI_CLANG doesn't use a jump table anymore and therefore, won't change function references to point elsewhere. Remove the __cficanonical attribute and all uses of it. Note that the Clang definition of the attribute was removed earlier, just clean up the no-op definition and users. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- include/linux/compiler_types.h | 4 ---- include/linux/init.h | 4 ++-- include/linux/pci.h | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 4f2a819fd60a..6f2ec0976e2d 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -265,10 +265,6 @@ struct ftrace_likely_data { # define __nocfi #endif -#ifndef __cficanonical -# define __cficanonical -#endif - /* * Any place that could be marked with the "alloc_size" attribute is also * a place to be marked with the "malloc" attribute. Do this as part of the diff --git a/include/linux/init.h b/include/linux/init.h index 88f2964097f5..a0a90cd73ebe 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -220,8 +220,8 @@ extern bool initcall_debug; __initcall_name(initstub, __iid, id) #define __define_initcall_stub(__stub, fn) \ - int __init __cficanonical __stub(void); \ - int __init __cficanonical __stub(void) \ + int __init __stub(void); \ + int __init __stub(void) \ { \ return fn(); \ } \ diff --git a/include/linux/pci.h b/include/linux/pci.h index 060af91bafcd..5da0846aa3c1 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -2019,8 +2019,8 @@ enum pci_fixup_pass { #ifdef CONFIG_LTO_CLANG #define __DECLARE_PCI_FIXUP_SECTION(sec, name, vendor, device, class, \ class_shift, hook, stub) \ - void __cficanonical stub(struct pci_dev *dev); \ - void __cficanonical stub(struct pci_dev *dev) \ + void stub(struct pci_dev *dev); \ + void stub(struct pci_dev *dev) \ { \ hook(dev); \ } \ From patchwork Thu Sep 8 21:54:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970766 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 2B5E0C54EE9 for ; Thu, 8 Sep 2022 23:04:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=4RX/BzAdY3TCoYvyayjptKAFM6SgYucDX7Yw84bJ2Zw=; b=ULbrj99p8rbRMM12oBEJ63UAlM geYpVnWLl0KtBULjlZpKgwpCl/dwdd9xynECckrD9TRIz562EMakMTRGDngwrb52A7h2Y36dO6FWg nQtXS4x6A3dInkxoimSNIU3FAoQHYchUA0QOR/2+5TgTQf/Pb5TgMTLsRJMTY2ouuf9mU49VKtsiT LnRw0RICusxd4lruB4I81jSzM4S5QTjSZR56bjRQy2QBzui+zdyUigeUk0ydFYObod4e1yyCoViUs BOHickrnmMlkK6fH3rrgq3FDQS+MlzcpnUiE+csm2WyCZVTzFpK672FvZ1RhmP1lcFEVufmy0xu2E s5k8YqgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYH-009ca4-AO; Thu, 08 Sep 2022 23:03:17 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYF-009cZb-U5 for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=usXbLw1pM2KvyZoDBuKyHSuX2iW4zvZIVdDHW6Ts0ZY=; b=ZroSWHvvLrGUMNCnFo/raGOyq7 mOpXmLrnIuvkrq71cupHvFyZNgjFzy2ewKnBpBl7VDjsVOjNUMZRGkyiqfEH03MrMeO8sJVPBL2+5 8bNt1b5ztIlO39oORDOf1OmvoOPYbaVVAAMBIDj6/BeFX+Mwu7mGgMMGOfAEKNdQtPklHvO72Otl4 /j3Rbo00++pGOhVZ/VaISA97v9EOWPBut/bz7z67MGZJGcj7/n27s7qD1GjCGqpxJR1tGZ8esbCHS oS0kkQmvdPybXJIH1CpC15rGm5SqtHV3baHjQ4LaNL+i9ohCzmT5RSomQbNlMXEoAh0UVKqAAaWOc 5tzObGlg==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPV0-00Apl8-6m for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:53 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33dc888dc62so155253007b3.4 for ; Thu, 08 Sep 2022 14:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=usXbLw1pM2KvyZoDBuKyHSuX2iW4zvZIVdDHW6Ts0ZY=; b=AE4JUukv8f9Zob1CSZjp3nG8WCaj3ktDo/dMYs0duivx37HcX6QQwPd62gAfqdbaOp ptanisTDbgqESxDW0iDctlddt1gBINtCfgVxMm3AorZg6MHImPBAGieJc7i1uOt7Ic5u e2EnKCy0bJiG/q+SSXxzDIswsm+9j3fTQhgLDvainjBzLtGVH7pqzyDI0rCIir4aTOlL JL7f8C8gUvah7VB+5UzO6n5ibwm2KLG8F9D2rMwm84+DU46EsQ4CHToWmPNIYB8qnjfA S7aP3kqsWt0J/j/dl6au199648A6c81VVr0lt1CkqxXM+61lSRu/wnEGVe/8d4zJGZMe 2+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=usXbLw1pM2KvyZoDBuKyHSuX2iW4zvZIVdDHW6Ts0ZY=; b=VRKpzESRKBGqyBNOsGncqx7+O3KJvZB6WbO+EFo0rogwMcWBwL6sb0rHqz8viyQeAX FgTthNC0ME5qXck2+ft6nlDEDhzK/OJ4A/iC0/O2qs6exkbPMfKThgQcvlZ8BggiCclt 4wOi+BzS9WexrTWgV5LXlHkTd312bzBdLYjEcnnWCvnktMWbfRqsyE1hTpIqXfKFzefq QkAuOalj8q03Wm16yXHWsQOymY/PIQMRfZqF3dMtSRtcdgEfE5en2cNUMNiIxF4hIhJk 4qNtMUdt/orQ1dowTBNLzgyY50BvXj77CgIPib60z5rEbit4+b13b0qZ44LO1Q+XmVAG XjtQ== X-Gm-Message-State: ACgBeo3d1bTTdDTGKIva/P63yhEKXhaOUuTkxTVtXNeFKPHgJS8NcS+6 GMrplgGaSBYEc1knU+WG7JV5fchvxisI2E/V0Pc= X-Google-Smtp-Source: AA6agR5WT7zakLIVotfkCP+Ltu8T016sdQ/qMO5CU/j3xR9ORhLtwu6lkBY4eBv6Q8pR6ikFX1Dtzbh+lC7Opjk3qVA= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:6f43:0:b0:335:9e7e:ad25 with SMTP id k64-20020a816f43000000b003359e7ead25mr9472870ywc.518.1662674148732; Thu, 08 Sep 2022 14:55:48 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:58 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-17-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1445; i=samitolvanen@google.com; h=from:subject; bh=OojUc6gvhYO7/nvSgMu6gZvuX/wXQ7p5p2ix4YG74Ww=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS18ATy8CgQuYAQJpe1UeWUw98XLd/V3+KW2F/u 4Z+6kC2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktQAKCRBMtfaEi7xW7lSuC/ 4sfH5L4f5/2SJ64jvWTm+1lc49S13k5MpSk0eZ/UEsUKzTgzzu4i3s7Q9UqdkRmWmqhbZylhnZgFbP GNleTbZK4sC/NyBAMN9DqIujnWeWRIghfmZSMzF1NWoHIa8Si19YuRXRTnnVfB/KWCwcAi5MDKfWQE eqwZCJKcO9hjR3Pnxe25vrAj54m6F3Q0bk1QY0bfYbfyMhC3XAW6WEGUJaI73A08owc1LxwtpRVj1N MYDySP7kr7EF6/9u1H8SjmdLJlLCins4r3I/1dbOPQ5eAMqCW4LV/SbIdF+yDRhRMOfV2VjFyfAbxr mdleL7w8DTTDlCbr+Klc/IenrmmnOOwDQDZwysQbJ7Ovt0tbfNphd/tAdItunYuMjg3U+GiGuWEG2j 5M0n4Vyh7DU44YcziEwli2nYR/R/UUgv+RJpgz2QqW3Ld05ic5w8yjfU65prGhAypzJzeqx9BnOZg6 hZR3WFUEeET3Wqby5DqrJb95y73h3aP44Ssz5htKs3W8Q= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 16/22] objtool: Preserve special st_shndx indexes in elf_update_symbol From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225551_152155_FBC882EE X-CRM114-Status: GOOD ( 14.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org elf_update_symbol fails to preserve the special st_shndx values between [SHN_LORESERVE, SHN_HIRESERVE], which results in it converting SHN_ABS entries into SHN_UNDEF, for example. Explicitly check for the special indexes and ensure these symbols are not marked undefined. Fixes: ead165fa1042 ("objtool: Fix symbol creation") Signed-off-by: Sami Tolvanen --- tools/objtool/elf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index c25e957c1e52..7e24b09b1163 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -619,6 +619,11 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, Elf64_Xword entsize = symtab->sh.sh_entsize; int max_idx, idx = sym->idx; Elf_Scn *s, *t = NULL; + bool is_special_shndx = sym->sym.st_shndx >= SHN_LORESERVE && + sym->sym.st_shndx != SHN_XINDEX; + + if (is_special_shndx) + shndx = sym->sym.st_shndx; s = elf_getscn(elf->elf, symtab->idx); if (!s) { @@ -704,7 +709,7 @@ static int elf_update_symbol(struct elf *elf, struct section *symtab, } /* setup extended section index magic and write the symbol */ - if (shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) { + if ((shndx >= SHN_UNDEF && shndx < SHN_LORESERVE) || is_special_shndx) { sym->sym.st_shndx = shndx; if (!shndx_data) shndx = 0; From patchwork Thu Sep 8 21:54:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970768 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 25712C54EE9 for ; Thu, 8 Sep 2022 23:04:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=p6RcDEQ/eenkxqxbvDTFuTw/zOlhPNJgTUDaW/fDDBM=; b=0e0DqU2aDBJwokUakEsrRXOZsI ZIKu4VYomyCoi4eX/kT2iRhIwYSXsKprtSaVbvt7CSmagZgo8W0EBpu7m5FetFC+xCmUlmH0ltRqi O+ilTzZyUKibUuk4KU1TZn1+tGKMzQlKGCMI8vmsDf0kt8izyFmlRsj4t5WJhLCBeHUotaPg0h5RW krcjRJnlYYbmZkB0hXjFqLEbnCxQU0knA3M9r5jKs1BjiDcd+9oPZiEzP4v0ap5u3tyiagHIgaYGG ioBTKZh1QlkF/k/VHFyrVt/SzhDa1gryAz/5de8+tU6QQN0X4/EJD9mJEDPkfx7rjQkp5gunAOeDr ABduHo0w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYZ-009ceZ-8K; Thu, 08 Sep 2022 23:03:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYN-009cZb-NY for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=XmniUTEr3IsWekZR2qFDZKEfj9hJcfqgCneNiF7ztZE=; b=VqvquV+FU9mm4s392Rdigs2uKp 2xVWhaBQXd1pnc5np88kUXJBNygJk+AAKnKQzcAguv1efSHkLm5TTPJBScuODuWwcd6u1gUlCv0IA fDajf5WMjFxt3sp8ASUEXuNq8vrE9N2oWeXekHk0VD0GbQde9Rb08swnQJESyc4su1zumxKzajXmC QsQ3cMwHsaaMKGiFUNCebh59ABsfKW0TQzqIIv/GecHCrjTjUwPDqSJFBDy77Cy1v+tgyJ1BzXLg8 lnKolI2DDkvlxaPfj6UUnjoBKfS29oSKuQbbI3EaO5n3P75YahrjY9IrM72SpXGGHacMK3yyXTXvo gsQly41w==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPV2-00Apm1-Ri for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:54 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3452b545544so110526337b3.3 for ; Thu, 08 Sep 2022 14:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=XmniUTEr3IsWekZR2qFDZKEfj9hJcfqgCneNiF7ztZE=; b=WCxXiMf9jt0TJXqJVxEGpO5FIe1m1i3ZGCw5CoV/rJ85nw+sR7A+6ka1r8pSYvcykj fdhPJfWapSH0tUHrJ7JwfesE8ueKIfcYHTxrBbgThkGTRj8VuUmZhwmCQ3RzlNEM2ecD z8ix+vkJAFymmihF+AY2LlKW9zCy2OxSuz73nD3s3LFpsgclOFOYtOtx3tG5ZwDIz+bP A+khvfFMbTOSY81mGX3NqvYc+QXhfp46q/BRrc+yAFDotGxiveN3rjh0XY2tB1HOxaXY FYx8Y77WPZ5fIYqlsyAut8OvfzqgiV3dRvDT5sKW7C/HCJM6xuapQF9Yzw/zFOz0vgK0 uWcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=XmniUTEr3IsWekZR2qFDZKEfj9hJcfqgCneNiF7ztZE=; b=SQAumPGr/BWOtWF440speZ0splJTBxWo1MLcooMbGgLQcr1TRQ5f2Huh8tOaftTWvU 8LRo38aOg4syNPd2DN2J3+xzM7PrDriGOW03GfoTNKXH8fpNld9J0CUGWKIF363BwN9Q c9rowQa2S8F43nNyVBizEhagzNWUBdXiSPMWWKthzcnTFzi6FN9yQopnfobsKzevYIZn E/p23rraMws0pXUNtCn9XNR+uribNvAcl/UpnD4m6bktEpyVAlTdr0Ac96dezNmqUUdL dpI7wJDKhw9RY6ZfT3sqKoj60Nl8eIwdlPh8LNaj6d6Eqd82gsIY9G5O69sFTJmNjOOA 0EZA== X-Gm-Message-State: ACgBeo3LzpHB88OLEdOU8fQB9KAbz6sibHwcgamzNv0tKhN9N1A69xJQ Ma4lHaAwTEXX6lawb6pFEQYoPbClzl1Anh0EjfQ= X-Google-Smtp-Source: AA6agR6M76LG+TWjK8L+F7Pickv1R6NBQMbIyPbnehQFyZI7o5/G4d6MfhU8IvsMdeYW6PT4y2h9Gv6HjQVCTyH+TGA= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:8a81:0:b0:33d:829f:644d with SMTP id a123-20020a818a81000000b0033d829f644dmr9392736ywg.439.1662674151325; Thu, 08 Sep 2022 14:55:51 -0700 (PDT) Date: Thu, 8 Sep 2022 14:54:59 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-18-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1889; i=samitolvanen@google.com; h=from:subject; bh=NWDsac0IgzNSFTJgx7iH+qos7yriFkDjm7ciN3deLwc=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS2QtXco+6cnttk3ziU1CPssT9FS0Gu8RLffJMX DuiPTDqJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktgAKCRBMtfaEi7xW7laHC/ kBCEQg3rEEpwp43GQ48GjqbCieliDghyyZPPBekjsBnBNrdnG8Vm9GOSBSH6jHBKRoAaPBYbHnmBxJ hbAnIoe8iH/1aMV4X2XS0DnwRarAgGvwIT41btmUEvxO+gDCKbg/1aKwS3k77DRva2rgu6fxSqbY2s OprIgnrE7+GivPv5e0Mmvr0Hm9YIpYVHRLl+3eLqWZGc9nzlWEmVmnZkVM+RbbwCUfzbxeQ1BY3ykL ZvfY5iLCkg0vVolw3s6qlVYn2LwCoGvB66ee8Z5DiX8ZyGfNaPypyV/1qr5xvpAfJroafshKOsowU5 +v/x6ze8NdAuOZ+7YdikfQwEELuZ9XXt63bCQ+UD/J8pjGQ8KBUSaXQLOKPmBga5+06qVi4a+PEfeq M84OhWdJiTRngnFB9fEWgGdP8L+iNYPNVB/x/IwOzi7A2pgIj0eJgShn2uIHPaPynu8nokZaaRX8EM Lm6ye3lWt59SFbyI0JEQFniLfVDG47lRJQZrTQ4ptFSUs= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 17/22] objtool: Disable CFI warnings From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225553_188994_2EFF059C X-CRM114-Status: GOOD ( 12.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The __cfi_ preambles contain a mov instruction that embeds the KCFI type identifier in the following format: ; type preamble __cfi_function: mov , %eax function: ... While the preamble symbols are STT_FUNC and contain valid instructions, they are never executed and always fall through. Skip the warning for them. .kcfi_traps sections point to CFI traps in text sections. Also skip the warning about them referencing !ENDBR instructions. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor Acked-by: Josh Poimboeuf --- tools/objtool/check.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e55fdf952a3a..48e18737a2d1 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3316,6 +3316,10 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, next_insn = next_insn_to_validate(file, insn); if (func && insn->func && func != insn->func->pfunc) { + /* Ignore KCFI type preambles, which always fall through */ + if (!strncmp(func->name, "__cfi_", 6)) + return 0; + WARN("%s() falls through to next function %s()", func->name, insn->func->name); return 1; @@ -4113,7 +4117,8 @@ static int validate_ibt(struct objtool_file *file) !strcmp(sec->name, "__bug_table") || !strcmp(sec->name, "__ex_table") || !strcmp(sec->name, "__jump_table") || - !strcmp(sec->name, "__mcount_loc")) + !strcmp(sec->name, "__mcount_loc") || + !strcmp(sec->name, ".kcfi_traps")) continue; list_for_each_entry(reloc, &sec->reloc->reloc_list, list) From patchwork Thu Sep 8 21:55:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970716 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 1AFE4C38145 for ; Thu, 8 Sep 2022 22:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZDSVwTM+QLfPWNIt2fpRGBQa8ZYlCyrcN6QYYewXe4c=; b=Tx+QrNWqqVlx0h5bVsFRUWF0Ov WmK5QdZ6Db1KN92yQB5TmafNi7vM8YnLJTVczkO1uiwkoMfNFOzGbLxlNrfUlzObQdrGBtVsH6AEf esYFbdLnwAghYyUtPFon81+h41kNLVt9T3a4g55xS2dAhP5CCYFTcZyE4EHMoAtofHCHYJpOjfzKB jHKgdikhiA48T2v0u0m8UnwEurAOQ/o+QcpOhNE9n/SsXXZtiJJazUTMYtK+czfBSxL3hef65XNHu R/LtMsFUsIWLwa3VxkotpyZTSxfuajIcWRLZI9rSoOtbEW53DCKC6SNk1tv38a9VBMOLKOIYMi5ro +cJPVs4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPZP-0098hO-H6; Thu, 08 Sep 2022 22:00:25 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPV7-0095FO-0o for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:58 +0000 Received: by mail-pg1-x54a.google.com with SMTP id a12-20020a65604c000000b0042a8c1cc701so9676866pgp.1 for ; Thu, 08 Sep 2022 14:55:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=vm5veKXR+O2rRgDax5LpSkLTaTy6Og98Noar0uvmDBg=; b=ZH4pBF7GcHnWh2rdS1M78dhaZ11K8L+Sgzed6KJoRLi3j8jXB817lSxBYasnKxh35l ZgnZlL9KZKdVv/EEmU4Tr+fZQkPdIzGmxpc5X5xhaFXzDlmMeZThq26jacwbWTgmbIt+ mEOWKEGQf60wrEwM3JZDw9Jzp39hksE1mVbxmtBIAb5U04hNo0rDQzSQy3qp0ANVY3Nx mKwCjtrn4M5SR6N3Ntr0p4SQUb7v7l9CLXjBfW3uSHAXgNiORV7YYLQU3pmYbuhWBylE YBOxayLfIlv8bl+W/GJkrVOltIx+Nqz+DUXVpTpgY3U82wYjYp/kQseaYZQPRushhMm5 TAOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=vm5veKXR+O2rRgDax5LpSkLTaTy6Og98Noar0uvmDBg=; b=NDFpNyOuGwss5e6k4VHuk8WwHWr7yg3yOtSPZbYRa1sT4jAnD1+S82YOUua49xCFIW OXr1ragzwhRbRkLRGrBigELlA07i8iyJPDIkZ5d4M20Oc2FNcsZ/KnUtPRpS8V80RPhL NjvhOswh/kc+/UcilSTp06YKGvdylKCXGILvuT8uMJqbj3PU/1KLNRFywLwxJ8UqXG7i dJTnEjHRqC1LcGDWYlTOjpqzOd7SiQQrBf4ZOQRER7Q2h1Kk+IzYieHNu3YRTjXG/6Yf To/q21W9FLlauMxNSySsJUW3XJdUnte5Pzl2mCKKYfKcNgAAQbGOaJaPXNqH9wqo82fN b5Mw== X-Gm-Message-State: ACgBeo3DrQNaDKXepX5GuR5bm0dDz6iiDmb7hyXAvWBIFDFEouNP5/T2 8BWR/rxXOHTmyJflaLcVqDSmyjkiVByhkXF+GoY= X-Google-Smtp-Source: AA6agR5WnOKxTdr/25i3BNZh8IUmQ/bEKkkDvPQH35RzmIpWPpUdr+e8HDfZfjjiwD8/thKx3eVCYIJ3WfNg33P35jo= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6a00:1390:b0:540:b6b6:e978 with SMTP id t16-20020a056a00139000b00540b6b6e978mr3321390pfg.8.1662674154442; Thu, 08 Sep 2022 14:55:54 -0700 (PDT) Date: Thu, 8 Sep 2022 14:55:00 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-19-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1418; i=samitolvanen@google.com; h=from:subject; bh=9OoxBGSeValXYdhbTF14Jfw3MpaGMV549rycOq8LEaw=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS2qkSmjV+l0koJEkW3Ra86NWCQbdAoQUKsCsKu US5kAIeJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktgAKCRBMtfaEi7xW7pPDDA Cn2pbnV5bcnzoGc8JddgQnV8D4DQRGk/vp6Uu/MGcpttE+hmRYXGnxPteqSuac3HNTSxdxiMaQbfi4 tBYcvtA6mZVp5tIWr3/aPPuCXplinZdK/00vI41ck/OgxL6dJAJOalxRJzlbGGoQcXuHN2qEF0xHTr /m3yfieyINfDIDo4hlAU5NQcvyjTWGcpk1tkvYoRl3NFUC5Tcu91qUajnAkFemmoRTlvav6BDdgLve 6I7D1tpAsuiRpM7MiIB9WdPztgJcnq3wGcE5+hlQyM3NNPYVKNJRkBwUyTGRzbOQ5MNHbAUE/uYTuZ UXkp9zyheMNGsyjM8WiRweAG84GbTPpJfv2qdX2QzOuq8OeMyHCx3/gNnAHfS3cz+ZwsyKBUTB95XM /xIO9SBobBIFVshdiOGryKwpvtyHrmgoTm36g2d0vRyq+zF59jNJhd4zf6kaJcYjXsGyh4SAyVxQtH 4CwhKkIc22A/byAV/q1kus+z4aFPKT0NFo0RM2dCxr0y4= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 18/22] kallsyms: Drop CONFIG_CFI_CLANG workarounds From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145557_085885_377C7F5B X-CRM114-Status: GOOD ( 11.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With -fsanitize=kcfi, the compiler no longer renames static functions with CONFIG_CFI_CLANG + ThinLTO. Drop the code that cleans up the ThinLTO hash from the function names. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- kernel/kallsyms.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 3e7e2c2ad2f7..b27e6ea31f8b 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -159,7 +159,6 @@ static bool cleanup_symbol_name(char *s) * character in an identifier in C. Suffixes observed: * - foo.llvm.[0-9a-f]+ * - foo.[0-9a-f]+ - * - foo.[0-9a-f]+.cfi_jt */ res = strchr(s, '.'); if (res) { @@ -167,22 +166,6 @@ static bool cleanup_symbol_name(char *s) return true; } - if (!IS_ENABLED(CONFIG_CFI_CLANG) || - !IS_ENABLED(CONFIG_LTO_CLANG_THIN) || - CONFIG_CLANG_VERSION >= 130000) - return false; - - /* - * Prior to LLVM 13, the following suffixes were observed when thinLTO - * and CFI are both enabled: - * - foo$[0-9]+ - */ - res = strrchr(s, '$'); - if (res) { - *res = '\0'; - return true; - } - return false; } From patchwork Thu Sep 8 21:55:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970722 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 06E94C38145 for ; Thu, 8 Sep 2022 22:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=OpLTYQcmAel9AQ7n9e7H1FCRPBjrJEuaWerOWPamrxg=; b=nKHgkJkEQtphIOr6teXILW9Tex 9iJC5uGRfFH/wnTmuwXxgniQAD0HvshA419dpBQL5wqBby9a4m1kQm8q2U7r+BAddVuXNwUj39+Nm lDWAZ+d5SPWFqNIVXs9qIYWBlY7ecgPkfzEMVIo1XmwhWRZ+hahsvR9ERU3R6GxN9KpeyOhhfqbCT bWoIGtFSMAt5BaKNXdYGV2ti8qFfmcgzojo3eY0tSqxOxEg0K3iwmyvhx0678oYfROzzcf9xKuDVC 8AX0GEBhHGY1XADiWCdoa4Pj7L476xr/NpcSFF4UyiE72OG0iP1+hQ2cxn+TJozIX+wiWb9wH7YZI XReN6opg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPa9-0099Hj-2l; Thu, 08 Sep 2022 22:01:10 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPV8-0094uY-6l for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:55:59 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j11-20020a05690212cb00b006454988d225so10199ybu.10 for ; Thu, 08 Sep 2022 14:55:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=yl11LIApBFscsnI+fScXVW015zNFVVk9U+TQyeaAxKE=; b=GneJREjJ6ADU4W7/ReKz/IuR9lVLfatPLfDz2sHd3Z0TSlegPeJdDw7OSG8XNao9Cc XClfbsayKVd0y+X+4JXAICNqa2OmvX2ENIWqoO6k+faEZ++p7TFHmvVIzScdINlVq34F FN9jeMDz1qOKCPO1TOf5xFWdwH0Q9N4CA8VT14OghYhxjRIAqYYgPoFwiKHkJJO8faXR 5pKZIxZYHX87ntAT+fga2CjaHC54Aq6tAB4RyMWklOlrc6Vy1C3SjghwdOmNw+THrcgT /og9oY6PpFsR6SL7WBqBv9KsZq6cMPm7WIn8a+QGZzkpgDzvQXJVjquHzJpUkRz4PCME GBPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=yl11LIApBFscsnI+fScXVW015zNFVVk9U+TQyeaAxKE=; b=qzmB46e4qwUrv18RoMoRxMLtrCgYQE4peCyqW062VAl7LGv9qjGTZqFFvDzhAivDCS ZUCnER8K78/7wJkeAoP1sAEOYpkM+X3zkj6S2TYncbJfHPl9ZS8ea4ejzCWDfhzP7cKq SnV1iPC93k9VUNgdZFcGxBtYNtAXs5sPAJrINRCion1fOlstTHUvW/+0dJhBSwCNBGkm H1e4ml3Uxx1pGAXKZVIe7VqII7+Nuggc74aeA2cGGBx5D0Rb5QDveD0VIfoty/6N4DLS GANkovLpNInclYIKJQvP9qGTcXD5FJqe3OfqA7AZmb4ZoO+gubWqiCkRoXzWHXKfZXp5 sJ3A== X-Gm-Message-State: ACgBeo1OahftwyCP/Cgat+fs/t4QkGrrNiA39nN3AVisPiQnF7U282xY XivvjDp+1amgunfGDLXUUwZoCTCuDrFWQeJaDiE= X-Google-Smtp-Source: AA6agR4ULRG2fn/4MvHB7Upa4n4ytCQI8NCVc7O2QP5EfzzC8LFh7M6fWp3jHy5tpAo982OuvoU6oY8hq/cyyMrvUpE= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:1453:0:b0:345:5b61:d495 with SMTP id 80-20020a811453000000b003455b61d495mr9322121ywu.261.1662674157100; Thu, 08 Sep 2022 14:55:57 -0700 (PDT) Date: Thu, 8 Sep 2022 14:55:01 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-20-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=900; i=samitolvanen@google.com; h=from:subject; bh=8UKd2RwBqIGRpxvWBctEPftksuo7xy3etrWY4ppBfO4=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS2DEX9D50vsIuHptb4slNB2Z5bL4svRnxLqioZ ax2niESJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktgAKCRBMtfaEi7xW7gaHC/ 4mJOr67kF8bJ5ApvzJHi00OaK7Hya3xvWpMQ1V8eIEgWBZngw8eWVT15v70FQgGT6QtYYPXLn1tAg0 fm5a0oS5rhFD8zNfE8d1wnHg+N1ATc0YkU8K/cUqrt/GTaIVPEiSpEAttdBYmLoeQN+pqgbN/oWl0J eYEh65EgL1UUMwLkDYkIGmuJfmeirnJ/Z45+IAbPrkI66qz5DtAZWu+EdRSBVn8FQ6CIo5Fl1P9fEr DXNtA4y61L6ed+iwmnYG8KMu2ytOV1PxpyBxjtrpvoPUZpp2iqjQUiVpZ5xNFm3IO85ZsmgHL8EEdL 3uUTCKAVxd+5SuiSx7S93dcY08+rV38yOAADTl4j5NhZLaYP9Br1LxwrbOF2GZ8dbIEOigx00ihAIx S/Lqi3OGZb9xvPNrL7JsuqhpGNIpnFxka61Wfyxxn09x5v7r5nrWooRTunJGxtvMCeIl7PMifw1TSJ OUz+6dT2Vz2mrA6hAhSFQR+ArqVExBMkQSPubSrVGgvQk= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 19/22] x86/tools/relocs: Ignore __kcfi_typeid_ relocations From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145558_261195_AD9C38BE X-CRM114-Status: GOOD ( 10.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The compiler generates __kcfi_typeid_ symbols for annotating assembly functions with type information. These are constants that can be referenced in assembly code and are resolved by the linker. Ignore them in relocs. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/x86/tools/relocs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c index e2c5b296120d..2925074b9a58 100644 --- a/arch/x86/tools/relocs.c +++ b/arch/x86/tools/relocs.c @@ -56,6 +56,7 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = { "^(xen_irq_disable_direct_reloc$|" "xen_save_fl_direct_reloc$|" "VDSO|" + "__kcfi_typeid_|" "__crc_)", /* From patchwork Thu Sep 8 21:55:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970767 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 3EC5AC6FA82 for ; Thu, 8 Sep 2022 23:04:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ZtKzl+66KZl6PgJNBflT3IoH+0AEHZzBsl7Se2RzDsQ=; b=Hiac5Pwxk3WyIyg3EguiC7MuDp azy+ysYLz6pQjewxgOZyx7PqswlKuBR0z2pxpfUIBdO4hfnNxjizc7XIGlwBcVpmPj6Dgfmi1C2gD FqSPCS4h5Oh+GfoxiiJwFION2TbaH/dyX4lwPPzMG45PjwYC/KLgbd5UcWV+7wleNl3ANdDFu86XJ xfOjrt2tbbVzDAn57qDRN9qqF1lgWHl3Puq6BT3UV8v9vCF7Dbf8IhgloQYXyyrobEjzhyjfZb4zP 4AwuUZXGaUqticdLJavZizXR8dBxBiNJpqQZSrVOLD3DKOhYZoMzLbbK7Rps56WSJpBOEycuR6mou 2/wgjK9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYQ-009ccz-7f; Thu, 08 Sep 2022 23:03:26 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWQYK-009cZb-Bp for linux-arm-kernel@bombadil.infradead.org; Thu, 08 Sep 2022 23:03:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FOdYXA0ZEZeFGxTEMOy2snMybODZGQ47ZcBKwefAZGA=; b=ETaM5lTeGl6pMlKfjfiVrE+mFv csvOJukb2ygVRiNK7izRKo3m6W/B0mFXfRHuqD4PIcdhCW2wX7edXsexTFYv0YFkIrXTP7d1cxg13 Vyjzw61euf7uJ/VwdXGd9unr4+0xxzEG8EyY/ZyosvHL810mouZPB85IUYhwIdyMpg4lnYlmcGLQy SVFtyEvp2vuNZ1x4vf5kMqho3nl8uLTy6CVjGWkaV3chEZE6CSg/65xzleI3MBO1JPK/MXkPXcQyT N/QT0yP6iOPHoraOHMRLsy7XbENalWfwD74sUfhw/9HUoHNN9qXR/8n0Voq5iVNfcduFaDRLUtpw1 Uxoo7Gew==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPVA-00ApiG-Jy for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:56:03 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-345482ec6adso101078407b3.18 for ; Thu, 08 Sep 2022 14:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=FOdYXA0ZEZeFGxTEMOy2snMybODZGQ47ZcBKwefAZGA=; b=GCSdO2MEVxK9Oj8yCp1RL84HIPE9phdOwXrJh29yO/AXhQFcrwmazIXaEN3Vvc8prJ 7ibgUM9AZ7+foHp1KylElJCOy7X9yOqmNEoW7PKfHsZtniYmCw55qKU76hK8tekk5OV/ rpRwlF6mZtZnitdMW/1TUt31NjUvXIKRx+OAAPaaAbd22IQE9mjLJJALlVwP2x9d3FbP nobraqTLx7PMNnEsmxmWnHhZftRCorEBcPUzCc0FU86A2ew6qfEdVQQb0yplG2HmXB7n gwXnVTHME+tj6Ho+35AFVkeKPDjAOgSq/s8Jm0l10Zike7UShj+w24OW5yulnPF/YWgB l4zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=FOdYXA0ZEZeFGxTEMOy2snMybODZGQ47ZcBKwefAZGA=; b=3xaD1KGY3/mr+6LWC4lHqAEZC16Yd9nIzmtmYjlYPjgdKrfmF7MAC+r4vb6v2eCwp2 Wde5X2AYCOJAFn3m6eHPEOJL7y8fP6m28OSeH1QjAE1M9u+JlMx8WsXh2Hay+xFq4Wv6 AXC5mjaT7gNNwKjXEF2nNeiAf8yA7PUoruVk45pvW2YpsuxFXNndankgfdZKJ+fpq+PQ ZvucqJVpgYAeH3X1ktQvmMkBqY3kYu8QLXfM6l0X/LIK6OczGt92jAPUAtg17QSWsiDH HF5WAMYZGL+t0XdvoJavCC1tDJ004mH0qk2XoWPg958VHgLPF+pJ5NNfHRmrTyi+Jd0B dyTg== X-Gm-Message-State: ACgBeo2RK4oq0EdjW8fv7CNrpE2hyMY6sad/XXdKPTDssfnqKmBWAhw6 afZ4p3gs0VmwVl6OUo66o6W5Gpnatlo7Mcd9Jc0= X-Google-Smtp-Source: AA6agR4cwjBEM5ngeMz8OJhUS51aCH+VLhWHgGYQpEix4smq/bn6oTZsK/+QG6LhZrt8Fuq/YMF07fwi7CBwTNUFS8U= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a81:5443:0:b0:329:cd12:e96 with SMTP id i64-20020a815443000000b00329cd120e96mr9699307ywb.68.1662674159576; Thu, 08 Sep 2022 14:55:59 -0700 (PDT) Date: Thu, 8 Sep 2022 14:55:02 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-21-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2981; i=samitolvanen@google.com; h=from:subject; bh=TQl874bpqor9ywOwc/gV6IgIv3bUozCx00xHJLAs6To=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS2MZhLrVqCh+oVTKnuRWIFqHKJ0AmFaxnTOHKh baPVjUaJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktgAKCRBMtfaEi7xW7qOnDA CmOfqxEdlesooL2UZiKRNbfdKmUYKJEkWYpZ39pIT4gX5llHPRn6ulSLkNp/mpKf88x/xhOklD9zlH GiLtZYFS8G8/uqM9YX0g5f2F4ep4e0WopNmnCl0DDaTTq8GwNtlmEfNaQHeZCcSBJww6He/cMp/Ek4 lEZ0hLPA/m4qmzQ2GE5ZIqSBcloIoDguBz6X3Kg9m3rtsygaxc5/SrDQLqup2EhKK5G8FteV02jRgR CLIT0bxMG4+1eHVprQFdIAIkXReIiwySwVjaptn/WRx+Ky++ixFr+AQvmyRL+zPb0b3Z0H5RqKNMxD ZB8QlSghcEMwJdLW1QPU15rd6hUXWmIYz3cJdIjzotbK+4NrKYL2irVmwVJ6U1GRxISLh00K5ZGOXv w2rq6rP3uqyEX0O1uf2ZEOUb62+cdJ07dG0qCuXfCftAp7XvAgWFdtcbeA072ywsoMQaZrrooGxNMP MiWdBTEFRIWOc9uhAD+adP4VPsCu6//QntQqutTSkPLPQ= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 20/22] x86: Add types to indirectly called assembly functions From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_225600_901555_9D230DC1 X-CRM114-Status: GOOD ( 13.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With CONFIG_CFI_CLANG, assembly functions indirectly called from C code must be annotated with type identifiers to pass CFI checking. Define the __CFI_TYPE helper macro to match the compiler generated function preamble, and ensure SYM_TYPED_FUNC_START also emits ENDBR with IBT. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/x86/crypto/blowfish-x86_64-asm_64.S | 5 +++-- arch/x86/include/asm/linkage.h | 12 ++++++++++++ arch/x86/lib/memcpy_64.S | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S index 802d71582689..4a43e072d2d1 100644 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S @@ -6,6 +6,7 @@ */ #include +#include .file "blowfish-x86_64-asm.S" .text @@ -141,7 +142,7 @@ SYM_FUNC_START(__blowfish_enc_blk) RET; SYM_FUNC_END(__blowfish_enc_blk) -SYM_FUNC_START(blowfish_dec_blk) +SYM_TYPED_FUNC_START(blowfish_dec_blk) /* input: * %rdi: ctx * %rsi: dst @@ -332,7 +333,7 @@ SYM_FUNC_START(__blowfish_enc_blk_4way) RET; SYM_FUNC_END(__blowfish_enc_blk_4way) -SYM_FUNC_START(blowfish_dec_blk_4way) +SYM_TYPED_FUNC_START(blowfish_dec_blk_4way) /* input: * %rdi: ctx * %rsi: dst diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h index 73ca20049835..f484d656d34e 100644 --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -43,6 +43,18 @@ #endif /* __ASSEMBLY__ */ +#define __CFI_TYPE(name) \ + SYM_START(__cfi_##name, SYM_L_LOCAL, SYM_A_NONE) \ + .fill 11, 1, 0x90 ASM_NL \ + .byte 0xb8 ASM_NL \ + .long __kcfi_typeid_##name ASM_NL \ + SYM_FUNC_END(__cfi_##name) + +/* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */ +#define SYM_TYPED_FUNC_START(name) \ + SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ + ENDBR + /* SYM_FUNC_START -- use for global functions */ #define SYM_FUNC_START(name) \ SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S index d0d7b9bc6cad..dd8cd8831251 100644 --- a/arch/x86/lib/memcpy_64.S +++ b/arch/x86/lib/memcpy_64.S @@ -2,6 +2,7 @@ /* Copyright 2002 Andi Kleen */ #include +#include #include #include #include @@ -27,7 +28,7 @@ * Output: * rax original destination */ -SYM_FUNC_START(__memcpy) +SYM_TYPED_FUNC_START(__memcpy) ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \ "jmp memcpy_erms", X86_FEATURE_ERMS From patchwork Thu Sep 8 21:55:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970723 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 99A4BC54EE9 for ; Thu, 8 Sep 2022 22:03:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hCZFPC/2OcZuqOU+jnPnuVsI0eQWIftVyT67qr1sQZw=; b=mNbcbX/l4EMD4QLnmg3qD13MzW gAOd4kgmDyFscdumI5QaolUdrv/LXXcK/m4d+nwbJeIp3W1gDQDoAFmkUY+9OowPgiBeTtQZ6plAJ 6Ow4Wm2J0i1uw6P/HXmIrruqluwv/hMuPez+wseBRwR1QpOIPSIa8HkJ7nK6S04QoRZyrPBW2i+oR 1NCuEevRXL27aWq5hc4ca9+CqbqzdlvEbsF30R+wFCIWMWS0kzAw6Pf8Ohbzv0nop7KEwScH96i9B NWz46TuVe2A0BW3FgjEj1ZndkucEGDpOx61PNx8oCJTD/quwqCiLeAgLBUeF8ze3PJOsOoxOrr5YD QYdMC6Sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPax-0099xS-7d; Thu, 08 Sep 2022 22:02:00 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPVD-0095Jf-RK for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:56:05 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s15-20020a5b044f000000b00680c4eb89f1so18214ybp.7 for ; Thu, 08 Sep 2022 14:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date; bh=YYrJQHPp1VsbrnyKnikDXxJr0Q0IFfWdTrn7QSp/nlU=; b=RAO9dBKDPKviMcOwBkkzZY0G3x+gnPOK29NFIOS/Zr8789LtLOlEaeHEybcNsvLdIW K+pwExbWGqldW8BJjVtsPZMGTJR3YhH90i0Txv330av0oqQtT/I4/nvWGh5MKlakz2so 5hIN+nonzm6i3iZB181y8mY7MbESrP96/nYqECARK6XBLztCpkuitNQRkrC/fKBt390x C1uQ3nyJhQju/9EuNJyjkAoZ68HF9wch5/WFjrih+g8E79RhgyzSuuDTd6bYOLqDJcZ2 y7uASan7GCfY1xHDXgLVyn2OJADPTnjC8NCdgKG5ywLhIO7aMrDjSH/GSa7QdsPmgHM1 CyIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=YYrJQHPp1VsbrnyKnikDXxJr0Q0IFfWdTrn7QSp/nlU=; b=FRR6HzyB93cDu40aotKyprYlSsH3AJTNoy7Vpca52mPdHGZmFgLNkKqrNTwndovQIF yM4ntZ2K2pBoD0CBMKV/hUlh1eS5xhVF1KBT7c2paWhKgV8inxvd8OF3LNpxT0pLjeqv QIpTdhwAeZvrDj2mY/DMA3xnL0nZb2Dm+XdtJg1cxwIJoCvUC4JSQxFn8jknvScoLeez NzFgU31flvVUPuyIVL7SngH5MA2qM/iSnaXaEPOHxnsskdfpkcLko0UbltqhLLX6K5AH 0rzciYHgM2wGbphuNJCgZwqw5pGQO6nnBV0dwAWELdZHnjVPqxaCa2jDQtX+KZrvdOri uGFg== X-Gm-Message-State: ACgBeo1Zrz4NXGgDnYu8O4z5f/LUE8NH7EihOrdZgq6JTgoC2YrCh2Pi +ylGtmdx5vhIMlnbyqctAdMVVa215YQgxK5zm+Q= X-Google-Smtp-Source: AA6agR5Q1US6p1T5MS7XFebio75PXfPm+oTSo10BuqyTKkQ0gqAhJ38ETDbGBcDqV94PluTx9li4JMCPkaAkCGoLKLU= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:1543:b0:6a9:adf8:14f9 with SMTP id r3-20020a056902154300b006a9adf814f9mr9806374ybu.271.1662674162251; Thu, 08 Sep 2022 14:56:02 -0700 (PDT) Date: Thu, 8 Sep 2022 14:55:03 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-22-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1011; i=samitolvanen@google.com; h=from:subject; bh=UWuLwE4y600ClTatyK0xTSLvu56hvYR9AUlhuy/RYBM=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS2BBGj4qMjQc0TkhRxkWipukSgdHFHNJbxjALg KA9XqJGJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktgAKCRBMtfaEi7xW7tnDC/ 0YewJWckrPSkwmm2Cp5oCkhzPhtbyWs+Y0ti12HWfm4sxYzV1zNPdfoO/xlWW4YUT3EGNpRhm652XA 1YZnjCMK8RJ9VL0Mkj7BJ885cDES9oNpu/gFc5tvXbign7Whrk+XzM/OStzrXx7yhwZYc+B8eIBZD7 /sv3RgkBqGX7aNahcU4xiVpdwE9rdGjjov/qxhkiKbltHSgKqBzPeAagsC/HXzYiAJlS/HUVSc/1Oh USSeATQh0fDw+EKujE2ITbZC9M2xnRw4dltthWBXcJupkTYvL+AkR6N1b5Nym/rwwYCYftIuFUZyVF EzVcnJCbq4gaQpyF85+NOzZUESoUrn0BLrMWYvfQae/Ekp6s0jQWwsIy18tgEV6VaDF8gS3nzAh6KX 3zL1l5wpZ7U0i197vi++LJVnvNti2UHclotv6EWBHZkZyGdf34HOHcAgdCxorRqu6n4mbDVi3q+yzs EEJlV55qqrvRL3C2yd4Mt1uIUXywud8dPE1BGXLm4eKII= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 21/22] x86/purgatory: Disable CFI From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145603_904241_D893240A X-CRM114-Status: UNSURE ( 9.99 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Disable CONFIG_CFI_CLANG for the stand-alone purgatory.ro. Signed-off-by: Sami Tolvanen Reviewed-by: Nick Desaulniers Reviewed-by: Kees Cook Tested-by: Nick Desaulniers Tested-by: Sedat Dilek Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/x86/purgatory/Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 31c634a22818..58a200dc762d 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 8 21:55:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12970724 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 7C3C2C54EE9 for ; Thu, 8 Sep 2022 22:04:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=llvaC2tzrC2zZ8JRDZ3/5f7O5ieihznutYqhgEcwnFs=; b=IiyZwkI1UipVhMRAwdXzESCZSF q+m70xwUubIOROI7Jnvi1rW8UnhleKKrNesWBGR9Qkz8oPLwr180HLFjFWwu+5D4uW9iY7xqTXlDT VUBH90YtwICubL4PADqCzC17tN7q+2Mq6RKpzPaCnHpAZWzNlGmbtfvgraSfTSIRaPFVaNtBbTi7T T7PF/IVrvZPK83LshFugfPXW/2VcyRqFwBbbtJ5M3ePLeaWZ7mY3C/t5gpFrKW04OgwpDjb/wU5uN c9vbjRTr+VzZo/2xY1pduY91KHxixXbLsruuM2Qsgo5lcEL4y/Ind4zsWo+zOXDSItQRgfftMes6Y XqYtbUfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPc1-009AU9-GK; Thu, 08 Sep 2022 22:03:06 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWPVG-0095Kf-9j for linux-arm-kernel@lists.infradead.org; Thu, 08 Sep 2022 21:56:08 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id i23-20020a25d117000000b006a8efe963d4so15638ybg.8 for ; Thu, 08 Sep 2022 14:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:from:to:cc:subject:date; bh=W2MsBDkHm4U561OaJvANeeC9kk6FHubd1inZB5J9C7U=; b=ozPRtGOQkrZNaRQ3QT0Jc9uYFYW7xBQtwI+wSvqBv2TV+owX5f58Z8FMvJO40vn5i1 4HXyYcMJccsZgL5Jmfhn9R2+/ez0YSX0Z5moQfDYgjWVgBNV5vdDNENKRXGmHCqMOD1+ 2c65MK3i9Pi2EdUsMFSQ3qSROssDGf0/vWU2Zag0IONGd29m9FH0rtYRXAC1Q6epDrGS EnbP7ibzRhZ7jX3OUrpDxw+TlhwFOqMY95RtWHlL5Yjm13Lwz9OGLSNXJ10MSdJYZdrK /+b9QsAHZ+FYIqbR9DELHHGOjQN4wOLvJdJyF6Wdk1mpil0FJr+MhVqIqhzlhIXkPgwF 5tBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:x-gm-message-state:from:to :cc:subject:date; bh=W2MsBDkHm4U561OaJvANeeC9kk6FHubd1inZB5J9C7U=; b=UMb3aaiTPFsyKQUqUTH0fg9F5aVOmqv0jOh/XzfqQirKzkBX/Wt8aXUTNYCbid+2Cy FfJOjVyNnsm8u0Kpl2sNUqdD78mKTAPBb15LcgySlphT7WqjJnCny36GeqAdgYVxUPlq LHDzy3nJbmGpBmcqDtLoVyphadHBal7XF5+FOBOjHLL8ZUhhXtppKcc4nl0blafo37+K 0cGJImzPoUcrwXklgLGPGDhgkzsi4IezCHBmvBsGabXR7o4FDlEjb5+0qfOm/eLbwupY odS1Ki8+ad9CKGWefHTcDjggYFJP+j3DWuSAReb6wBCZ4w1Iolioj7K8KT3l3zMGMjXy DHXA== X-Gm-Message-State: ACgBeo3KEOCCyOjebZ3lsbZf1fSGcIJe82PFfCX+LkY6Eh/+S6i3u7Aj YFMmBY+r6GHq5gOQiDLHbVwVClr1GZ9CvvFwDZ0= X-Google-Smtp-Source: AA6agR6U1XUO0LYhImFYMSI4KvgwdWX1/RpBZeDu6fNAWbgOLlGcdMrDVxKx76neSaLpTy6ktQEUMZ00pvUCp0Xy2F4= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:a4e4:e6ec:9fdd:1bdd]) (user=samitolvanen job=sendgmr) by 2002:a5b:2cb:0:b0:688:ecfc:5865 with SMTP id h11-20020a5b02cb000000b00688ecfc5865mr9264476ybp.642.1662674164906; Thu, 08 Sep 2022 14:56:04 -0700 (PDT) Date: Thu, 8 Sep 2022 14:55:04 -0700 In-Reply-To: <20220908215504.3686827-1-samitolvanen@google.com> Message-Id: <20220908215504.3686827-23-samitolvanen@google.com> Mime-Version: 1.0 References: <20220908215504.3686827-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=9724; i=samitolvanen@google.com; h=from:subject; bh=m/WdSbI78zPz3ataKUXTH/8qbSA/YezOv/f4N85aMjs=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjGmS3qJXMJjuk6qsUOyPJn4+sNRqxZsSu1hPxTZmT yYQBNBuJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYxpktwAKCRBMtfaEi7xW7ocpC/ 4j6iqKHQy3/NWDgxIcdlQhjO19ee94gDZK+Sqdum7IGwdIbzmo1rUQXUyoP0BM2dWCPUgjwHJTvBiJ r62RrPidnXoLobh9YMuFMXmFbgyLMbjnGgwzfg4m+5Q12hDTk2C9+IZjXOczGbohKDO/q5XHDhbYwP D67sQeylK/fnFozOsJQFLzQyB79VWQfbFiR5Fek4brb9HTJeKx0PCvTpCrvIkjjmbhnibhVlNrxv4u 17l6z7Aa3ptcdf6/eu+msNMNrzRslbeOvX8p4LIaSCnpQgiQU/gVTrKQ6Q7Eo7b5StEr3H14jpfIYQ iZfBoa5NgrzO858ElVmNIaphy08AMQ8ZsCmWYXSqIZBeb3qrDxRGAdhbVZ8W2bLyuFQnykbTNStchE Na5lp3PZCY6cvwr5wqJ5sZyyJ18efeGriY91w/yA4xO27VEIG80AcloyCg0YvShJRCP6tiaGV9VoKd crOzwcMZvW1fMTQctFSmWPcF6W0CnqVBdO0nhvnQc4OnY= X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Subject: [PATCH v5 22/22] x86: Add support for CONFIG_CFI_CLANG From: Sami Tolvanen To: linux-kernel@vger.kernel.org Cc: Kees Cook , Josh Poimboeuf , Peter Zijlstra , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev, Sami Tolvanen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220908_145606_382032_FCF3D71F X-CRM114-Status: GOOD ( 27.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With CONFIG_CFI_CLANG, the compiler injects a type preamble immediately before each function and a check to validate the target function type before indirect calls: ; type preamble __cfi_function: mov , %eax function: ... ; indirect call check mov -,%r10d add -0x4(%r11),%r10d je .Ltmp1 ud2 .Ltmp1: call __x86_indirect_thunk_r11 Add error handling code for the ud2 traps emitted for the checks, and allow CONFIG_CFI_CLANG to be selected on x86_64. This produces the following oops on CFI failure (generated using lkdtm): [ 21.441706] CFI failure at lkdtm_indirect_call+0x16/0x20 [lkdtm] (target: lkdtm_increment_int+0x0/0x10 [lkdtm]; expected type: 0x7e0c52a) [ 21.444579] invalid opcode: 0000 [#1] PREEMPT SMP NOPTI [ 21.445296] CPU: 0 PID: 132 Comm: sh Not tainted 5.19.0-rc8-00020-g9f27360e674c #1 [ 21.445296] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [ 21.445296] RIP: 0010:lkdtm_indirect_call+0x16/0x20 [lkdtm] [ 21.445296] Code: 52 1c c0 48 c7 c1 c5 50 1c c0 e9 25 48 2a cc 0f 1f 44 00 00 49 89 fb 48 c7 c7 50 b4 1c c0 41 ba 5b ad f3 81 45 03 53 f8 [ 21.445296] RSP: 0018:ffffa9f9c02ffdc0 EFLAGS: 00000292 [ 21.445296] RAX: 0000000000000027 RBX: ffffffffc01cb300 RCX: 385cbbd2e070a700 [ 21.445296] RDX: 0000000000000000 RSI: c0000000ffffdfff RDI: ffffffffc01cb450 [ 21.445296] RBP: 0000000000000006 R08: 0000000000000000 R09: ffffffff8d081610 [ 21.445296] R10: 00000000bcc90825 R11: ffffffffc01c2fc0 R12: 0000000000000000 [ 21.445296] R13: ffffa31b827a6000 R14: 0000000000000000 R15: 0000000000000002 [ 21.445296] FS: 00007f08b42216a0(0000) GS:ffffa31b9f400000(0000) knlGS:0000000000000000 [ 21.445296] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.445296] CR2: 0000000000c76678 CR3: 0000000001940000 CR4: 00000000000006f0 [ 21.445296] Call Trace: [ 21.445296] [ 21.445296] lkdtm_CFI_FORWARD_PROTO+0x30/0x50 [lkdtm] [ 21.445296] direct_entry+0x12d/0x140 [lkdtm] [ 21.445296] full_proxy_write+0x5d/0xb0 [ 21.445296] vfs_write+0x144/0x460 [ 21.445296] ? __x64_sys_wait4+0x5a/0xc0 [ 21.445296] ksys_write+0x69/0xd0 [ 21.445296] do_syscall_64+0x51/0xa0 [ 21.445296] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 21.445296] RIP: 0033:0x7f08b41a6fe1 [ 21.445296] Code: be 07 00 00 00 41 89 c0 e8 7e ff ff ff 44 89 c7 89 04 24 e8 91 c6 02 00 8b 04 24 48 83 c4 68 c3 48 63 ff b8 01 00 00 03 [ 21.445296] RSP: 002b:00007ffcdf65c2e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 [ 21.445296] RAX: ffffffffffffffda RBX: 00007f08b4221690 RCX: 00007f08b41a6fe1 [ 21.445296] RDX: 0000000000000012 RSI: 0000000000c738f0 RDI: 0000000000000001 [ 21.445296] RBP: 0000000000000001 R08: fefefefefefefeff R09: fefefefeffc5ff4e [ 21.445296] R10: 00007f08b42222b0 R11: 0000000000000246 R12: 0000000000c738f0 [ 21.445296] R13: 0000000000000012 R14: 00007ffcdf65c401 R15: 0000000000c70450 [ 21.445296] [ 21.445296] Modules linked in: lkdtm [ 21.445296] Dumping ftrace buffer: [ 21.445296] (ftrace buffer empty) [ 21.471442] ---[ end trace 0000000000000000 ]--- [ 21.471811] RIP: 0010:lkdtm_indirect_call+0x16/0x20 [lkdtm] [ 21.472467] Code: 52 1c c0 48 c7 c1 c5 50 1c c0 e9 25 48 2a cc 0f 1f 44 00 00 49 89 fb 48 c7 c7 50 b4 1c c0 41 ba 5b ad f3 81 45 03 53 f8 [ 21.474400] RSP: 0018:ffffa9f9c02ffdc0 EFLAGS: 00000292 [ 21.474735] RAX: 0000000000000027 RBX: ffffffffc01cb300 RCX: 385cbbd2e070a700 [ 21.475664] RDX: 0000000000000000 RSI: c0000000ffffdfff RDI: ffffffffc01cb450 [ 21.476471] RBP: 0000000000000006 R08: 0000000000000000 R09: ffffffff8d081610 [ 21.477127] R10: 00000000bcc90825 R11: ffffffffc01c2fc0 R12: 0000000000000000 [ 21.477959] R13: ffffa31b827a6000 R14: 0000000000000000 R15: 0000000000000002 [ 21.478657] FS: 00007f08b42216a0(0000) GS:ffffa31b9f400000(0000) knlGS:0000000000000000 [ 21.479577] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 21.480307] CR2: 0000000000c76678 CR3: 0000000001940000 CR4: 00000000000006f0 [ 21.481460] Kernel panic - not syncing: Fatal exception Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook Tested-by: Kees Cook Tested-by: Nathan Chancellor --- arch/x86/Kconfig | 2 + arch/x86/include/asm/cfi.h | 22 ++++++++++ arch/x86/kernel/Makefile | 2 + arch/x86/kernel/cfi.c | 86 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/traps.c | 4 +- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 arch/x86/include/asm/cfi.h create mode 100644 arch/x86/kernel/cfi.c diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index f9920f1341c8..1fe6a83dac05 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -107,6 +107,8 @@ config X86 select ARCH_SUPPORTS_PAGE_TABLE_CHECK if X86_64 select ARCH_SUPPORTS_NUMA_BALANCING if X86_64 select ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP if NR_CPUS <= 4096 + select ARCH_SUPPORTS_CFI_CLANG if X86_64 + select ARCH_USES_CFI_TRAPS if X86_64 && CFI_CLANG select ARCH_SUPPORTS_LTO_CLANG select ARCH_SUPPORTS_LTO_CLANG_THIN select ARCH_USE_BUILTIN_BSWAP diff --git a/arch/x86/include/asm/cfi.h b/arch/x86/include/asm/cfi.h new file mode 100644 index 000000000000..58dacd90daef --- /dev/null +++ b/arch/x86/include/asm/cfi.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_CFI_H +#define _ASM_X86_CFI_H + +/* + * Clang Control Flow Integrity (CFI) support. + * + * Copyright (C) 2022 Google LLC + */ + +#include + +#ifdef CONFIG_CFI_CLANG +enum bug_trap_type handle_cfi_failure(struct pt_regs *regs); +#else +static inline enum bug_trap_type handle_cfi_failure(struct pt_regs *regs) +{ + return BUG_TRAP_TYPE_NONE; +} +#endif /* CONFIG_CFI_CLANG */ + +#endif /* _ASM_X86_CFI_H */ diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index a20a5ebfacd7..1286a73ebdbc 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile @@ -139,6 +139,8 @@ obj-$(CONFIG_UNWINDER_GUESS) += unwind_guess.o obj-$(CONFIG_AMD_MEM_ENCRYPT) += sev.o +obj-$(CONFIG_CFI_CLANG) += cfi.o + ### # 64 bit specific files ifeq ($(CONFIG_X86_64),y) diff --git a/arch/x86/kernel/cfi.c b/arch/x86/kernel/cfi.c new file mode 100644 index 000000000000..8674a5c0c031 --- /dev/null +++ b/arch/x86/kernel/cfi.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Clang Control Flow Integrity (CFI) support. + * + * Copyright (C) 2022 Google LLC + */ +#include +#include +#include +#include + +/* + * Returns the target address and the expected type when regs->ip points + * to a compiler-generated CFI trap. + */ +static bool decode_cfi_insn(struct pt_regs *regs, unsigned long *target, + u32 *type) +{ + char buffer[MAX_INSN_SIZE]; + struct insn insn; + int offset = 0; + + *target = *type = 0; + + /* + * The compiler generates the following instruction sequence + * for indirect call checks: + * + *   movl -, %r10d ; 6 bytes + * addl -4(%reg), %r10d ; 4 bytes + * je .Ltmp1 ; 2 bytes + * ud2 ; <- regs->ip + * .Ltmp1: + * + * We can decode the expected type and the target address from the + * movl/addl instructions. + */ + if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 12, MAX_INSN_SIZE)) + return false; + if (insn_decode_kernel(&insn, &buffer[offset])) + return false; + if (insn.opcode.value != 0xBA) + return false; + + *type = -(u32)insn.immediate.value; + + if (copy_from_kernel_nofault(buffer, (void *)regs->ip - 6, MAX_INSN_SIZE)) + return false; + if (insn_decode_kernel(&insn, &buffer[offset])) + return false; + if (insn.opcode.value != 0x3) + return false; + + /* Read the target address from the register. */ + offset = insn_get_modrm_rm_off(&insn, regs); + if (offset < 0) + return false; + + *target = *(unsigned long *)((void *)regs + offset); + + return true; +} + +/* + * Checks if a ud2 trap is because of a CFI failure, and handles the trap + * if needed. Returns a bug_trap_type value similarly to report_bug. + */ +enum bug_trap_type handle_cfi_failure(struct pt_regs *regs) +{ + unsigned long target; + u32 type; + + if (!is_cfi_trap(regs->ip)) + return BUG_TRAP_TYPE_NONE; + + if (!decode_cfi_insn(regs, &target, &type)) + return report_cfi_failure_noaddr(regs, regs->ip); + + return report_cfi_failure(regs, regs->ip, &target, type); +} + +/* + * Ensure that __kcfi_typeid_ symbols are emitted for functions that may + * not be indirectly called with all configurations. + */ +__ADDRESSABLE(__memcpy) diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index d62b2cb85cea..178015a820f0 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -63,6 +63,7 @@ #include #include #include +#include #ifdef CONFIG_X86_64 #include @@ -313,7 +314,8 @@ static noinstr bool handle_bug(struct pt_regs *regs) */ if (regs->flags & X86_EFLAGS_IF) raw_local_irq_enable(); - if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN) { + if (report_bug(regs->ip, regs) == BUG_TRAP_TYPE_WARN || + handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) { regs->ip += LEN_UD2; handled = true; }