From patchwork Tue Aug 30 23:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960134 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 64C52ECAAA1 for ; Tue, 30 Aug 2022 23:32:55 +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=/VuywIKuUHhTW55NXq85jjKzBCyNZ5//ePmgdjrK+JA=; b=16y3lO5U1SrEMpIZGov+MK7sXz 7M0WjJ9V7I7bhkmO/am3EgilEjV8gAqYv3q8FU2y7ALx+4uoSImvRYqVE5OTL1f+riqpiSaU6ODu6 oMAbb6JBpdOzvPBAIQgp4UR1q/XyxKHLRLHVZkUfQJbkgdsCTFNVTn94rVFkBzaeWdrv16uCFDk1R auPifq4+7wnHOYK3KgPBSE7hx73nELsSvoSuNfT+UPPCVSAVndun5CnoER4COUGaWWkCtNR0+5hj+ wrwzH6yqSqYRajgTEW915L8AfTHBbZ+GL/ur+vq+CIyRIyvS8kQKH+Vq8bciYYfbhjjWdthPN2YXL AfF+PBog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAhv-002Sg6-QH; Tue, 30 Aug 2022 23:31:47 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAhl-002Sa2-Cw for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:38 +0000 Received: by mail-pl1-x649.google.com with SMTP id k3-20020a170902c40300b001743aafd6c6so8894209plk.20 for ; Tue, 30 Aug 2022 16:31: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=L25uLgv5hznFOW8C65x6whtc7Tn9BJysM2Vvz8HWyDE=; b=GlyX/udszzm3ETI6dGBsinPgbb2zH2Sx7UXYz/1vjC/nGY+/X7ZLW46uqN3etLOPT0 gV1SaWu+mT9dOl7PKHrdCe9i+XWpddw8gn1LLlyKiAiZDyL18nKBWphU62pG+hJKxRmM u+uoRGf2SWIvXTlojSYkQR+2T7yMZdfaE77HWRA76cmFOBZRkZN023sEPCVRGdvc5u7V WBxTSYiDyS+PUfPxQvu0l+seugBhnhEOip5lzg5qUgw3A6gDkzqA0gqRlSgn+YUgNTBq ekG0EJpcTzqD+Y4jhU0JnnShqvo1JQRejynQVVRjwAZ9ll4kYjRhz7z/Zm+n5si+aKge f35w== 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=L25uLgv5hznFOW8C65x6whtc7Tn9BJysM2Vvz8HWyDE=; b=Rjl436zNI0FvN3Ec2KoxQ9daoxDVDOlVALSlr1r/GF0fo6JuJa0NFchnCuYl0Av36w AhmvJu2P1xeq3MAEJHhePAgeLJfsQkh2w06MYDAN4mkYFiaUFbOAAkVtw7cAqDMms527 NxQV1II7BLiBAMd7uRQJJ++2RvJPnRJKk72Lp8NRJE2HrVZ5WiQUo9mK16O9xny8CmdX Q2bmXC/iMd+0meuW33SutUhmHtonYZOJ0ruXe3lGtR5KaArgYW6CI+EpDWuzGYJFU3V1 0SYB8SqFRq5wmKYJKqtrOSvwMXtP5y2aHeLnwgnXpPpEOXUCOFlxCas0eI4n4GC87Ay4 hFzw== X-Gm-Message-State: ACgBeo3HHYHS4rKqKFAUZTkZNyb60B/aLWFEm6OHmJ8avLotZSnEz0T1 WBPwOph2IZi6SIJPU0LAje5Ahp9+PL/SjThRthE= X-Google-Smtp-Source: AA6agR6t6+RmUgXGfCDMkXtgpmsLFiEpc19Ih8//1Ts8Vdoix/62fuolHALxDz5NswEPkfsF2/qhJD8nw7h8pAHo2gs= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a17:90a:249:b0:1e0:a8a3:3c6c with SMTP id t9-20020a17090a024900b001e0a8a33c6cmr14044pje.0.1661902295271; Tue, 30 Aug 2022 16:31:35 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:09 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-2-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2946; i=samitolvanen@google.com; h=from:subject; bh=Y2KllNLLe5W3ojqZsH1L8RGIJ3+vQcqt1B34SGCIoIw=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3LFZnyR8Aq9IX9f3NCTQfZ9PLKXxM9T7+t9pe6 XCRRtGeJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dywAKCRBMtfaEi7xW7vF8C/ 0Q2tFR9IU/s09oK/aPYzy2OnR4Fl7grWpQwG8dbDwI9bQFdE58qu5aKvOkH1n5LoPMnx1oiPeKAua8 Xbr93KRYEltkTaD58AlXyUTQVb8W/+WK4z5r0qhm6P2JWbCqvDwg4StkJRSB7vDn+lmR/PA0lfUQob tOp1QJGiNuDLFc0TbTSfqkK/xMXR6a0+FdfMXg20QKWShLiYE7bYKvgl6pguSour1sba5xcznBLxV3 M+9Ri4Nnvzd0QnR7bku4sNbS59EpdZ9c5D6eJjbsmZwIrBklT2i9BvcfHx4n6HCM+M0pWiFtQTUUXK ZDwfY8tjUVanTK7afJi3m5XLWkUlmJhaxk1YjwGK1wpbf+kcj9ykRivZnnU/eqNPtW/jP1Tk3ixLUv ceQHLD74GD+/xpPl9+6/1b0LWdDFc2ephQ2+kiVVS5zMGX+bRduupKomCFdvdHgAf1GrFAJb7iKA9R JE6m9yMp4f9no/FyLoJGQiPKz1klAidmbOixNOnCretWc= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 01/21] 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-20220830_163137_454846_C3702019 X-CRM114-Status: GOOD ( 11.19 ) 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 --- 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 d0537573501e..234fb2910622 100644 --- a/drivers/firmware/efi/libstub/Makefile +++ b/drivers/firmware/efi/libstub/Makefile @@ -39,6 +39,8 @@ KBUILD_CFLAGS := $(cflags-y) -Os -DDISABLE_BRANCH_PROFILING \ # 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 Tue Aug 30 23:31:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960135 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 407FCECAAA1 for ; Tue, 30 Aug 2022 23:33:09 +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=eayq2eWFGr3PeURaGm+AX9UOFuWCPY3p/2dLDfgB+7Y=; b=mpL8O0HPcDe5nG6ICiP8AbnrKV aUpmNG+VtzJGTcnj+sga+FtQaMZ8K1oI4zmysqZEZAQX5rQ0vKzgJXh0zLovjAJ0+5bKZpVREJWMn 1K/doyACN76K0c47m6LgMODys7f+Pk7wlWCGvW0haFF1U2atm2CcazvDMpJlm2e6OKP0AacNwA7Ih 2s1vzV3w13Q5hkdqcJ2oeJHytlL8cX04yxcqUxEyPpw5fLNx8iPrz/5A380xvMwKg3s0Z4/t12xwZ dgtezuXicZUSgwKkH+2gqr1fmEdHkal6TVvWk+/62abaxaA2WAfm7DvOfkFquR/Uc3sW9VAU7H417 hgU+KD+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAi5-002SjL-8Y; Tue, 30 Aug 2022 23:31: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 1oTAho-002SbQ-L8 for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:41 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-3328a211611so189171007b3.5 for ; Tue, 30 Aug 2022 16:31:39 -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=V3t6t7JIbAvSA8Tk+dwJ0EP+zKfoVcWxCLBhZzDbf1s=; b=BJZRO63b+6qTZ95mYkmggV5gs8KD4EmwXqxKHDYQCmIwLDm3YgniZ/250yz/gIN1o1 UDhgouP28HoSfLMlxUzyUrie3RqWCd1jAJOvkD9cnYfXcC653F8P+perCbezg0NqrJNk fMkszVMmG821mLizP9xbJci3/UVQzvsFSAjQusVLzxh/dfx2EtyYJL4EkRKZB8oJo5BX YIgzdRMqwTd/pdX/aPujuGXBfS+1cow9p06p/eOjzy5gj+RcIfTa6TkVDGBQaIaT8OMp TFBlAR0jRBgRhyDixp6R7SlS1vciR3OouPWVAX03TeXSLEtbzJZVJS5goMVzv3JfQDBu ZFqA== 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=V3t6t7JIbAvSA8Tk+dwJ0EP+zKfoVcWxCLBhZzDbf1s=; b=VJnLkHmpbgHT4+1OBLeH7spI7NH559Ym029xa5MvhevSPzBoFqc9DFLafXAJfDLkNX 8zpOR1RawjyYB/n5cJZgipQN7KcGx5YYsq7dcB4GPbwVuJ7hgBjt2ubnO2kzJ4TCjaNr /M3IuVKdr/OqI1RTn7xmtc+wSJFnjjIDQYcHG/7ohUAy9ILuCM03H9puuWmPdBywMhra 3x0rv6KEyRC3FcgOIJ1QQ+4b0EKDOviq0C4i1couniV/q86MwZKodQwIFpugb+sJ082C qgFPdcSyAGML/Irod+UvuR/xQarF4JKGxTzKhBLWQJsLHnUhgmobArtanSReVSbHE8gt 7hmg== X-Gm-Message-State: ACgBeo1mkF5xYKr/hqWVTAGUo53yxH62TYXvY023WcQc5YMD/uB7sPbX tXEzJUibYFWw5eug/spjITymuXBtlBzd9erQAAM= X-Google-Smtp-Source: AA6agR6LXRk/vsm3io9GudAaANlg3qlqmbPfZYO/5+9wavftY3qTlNqavlUs2mptfr8JHyP3G7J0i2tYgLtM61K8Nyw= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a5b:3ca:0:b0:676:e468:2879 with SMTP id t10-20020a5b03ca000000b00676e4682879mr14158623ybp.239.1661902298407; Tue, 30 Aug 2022 16:31:38 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:10 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-3-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=815; i=samitolvanen@google.com; h=from:subject; bh=ZsdbFV1rDPVMEEnz8gpkcJ4SEVi2nPPUZtGW8C9VlOE=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3LuiRNOIXF6iWJdViGqd3zv5mS4LojAiJ+2zw1 RBe4TiiJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dywAKCRBMtfaEi7xW7hbdC/ 9dH+eF9FLRfbAZmIKkZfKGLDEV4GpzyFt3DC0T+XPYawpv8d4hIHcmWOewSokNp8/RlQxEqhucG9Zn axIaqhwCi2QhLKvRZcwmhKgvB25LWwrp6pMh94YrnGXvlD4ZGovDQk7afANRYpvaJuBWvNDjJMfcM9 IMHPn/dIoby0cmKnGFT9OKty5s0M6RvrxxqzZZEVxwms885iZiHHnH1gSB2c5RlKNgSxrpvfzr6gB5 VgzIUn3LcrpQ9eYEcaYRquZJotPXSZwdymKNF+l7zsSqZZzMkyXcLEY8JSPcDyhYBdFlHyA9oq+hqf FOCm74Um/Gr8A1LV7ognHe7JEPGjOh7sx3AJcXUtyPCn7FtdZU2V/f+thDRCL7FfgnF9UDZs0DMpqq PT0C1GB58hHVS0/Y/twOGM7f//NBSc140Y0yOTXRWtQuwHvAzfA6mSE55KlboU2m6pMC8JKeSW7PsL +uWT5s6GcBEfGDclqFu6GC1EpRCfJ/6w0iOUYXTCADGSE= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 02/21] 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-20220830_163140_722485_5C2737EE X-CRM114-Status: GOOD ( 10.15 ) 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 --- 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 Tue Aug 30 23:31:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960136 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 1A615ECAAD4 for ; Tue, 30 Aug 2022 23:33: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=bNyLnnQ+SRNCwbfCdvSZGI6m6K6gj0ObyTCEh43Whak=; b=e0X/YUM1Kh3dbeycIfXBkS6z+D KceXnT0wW82bNoDOHqsJLqpDEZ8b1T1HlxTZWsM7wmr+R2i2jGakUDIZkkaAWfHhbe/Trizxh/RBm l1KFHk8jsgGRvW/r4S/DWVUC/vAfmCz9vdFNGdpVJqz5JSOsgky8lc0sauLGJfDEF/NiPi58zXWh7 +k+gb/SUCiZwIXLT94csUiZPqHYXaNKMNY6V85+d+yzPmzPT+3kHCdJ0aRzNHZQi43VEeuT6l68YO m1cYzHv+/fv2O0JQa9B3AMKAUbLPies+5c0NQcCN2JqBjzeBT01Nd/vw+sFRNE7uCH0ZiKwEX4qrZ NGA7E8iA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAiF-002Smd-Bu; Tue, 30 Aug 2022 23:32:07 +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 1oTAhq-002Scg-Lx for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:45 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33ef3e5faeeso184650727b3.0 for ; Tue, 30 Aug 2022 16:31:41 -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=lzRAvDnVAc4l3JfyKvLMWWQYMDwMtXvlESipxmm9IAc=; b=AOPTRjaS+K8en3ZLSWZakDYJmSjuKAyeKM3LFnvwpiivTYFZsuuJ/A3pBdSHlKYdb7 9vDVZYmudZo6RdYucXqNmohbw4FRhIu7KTrbgEgTm4Zq/U5ADnHLdD8+9UfXVd9KODIa H+y8OwRtbPLRTH0dhpKUzDEPHXiYiaIm3YYN2107zjfN8wWkZM2cwgs9wr9fipcpErk0 NOFg+Z0yCGyVypwrZ14H4rVt+0ykUjmOl9EcRNxpEK5yTAay0N/Kbq7c1/oSYIwaidbt 3mO0OESYViDx0+30EIzaejIr/V4JWPrphyS0iS8ziR7r6on829qnXrhmzyV7BgrBnvnT TA3g== 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=lzRAvDnVAc4l3JfyKvLMWWQYMDwMtXvlESipxmm9IAc=; b=RIPvbs9FxH5SPSSuwFK0dhB8v+DO3fpWJbrcJqJbwoA5TsXvjo2gOS7oeeZ35ZILat TnY6FxEwlpubWoI/J9sobt02fQ565Ym2kBv5bb49GPHsFBHq4bVnLh6+XqRt5zW9ScFm 6KXI4mY4fKN/w1x/OjwxFzMPz39WKevd6McRXFsrrIYEx1BkdMDtvEA6EXGayW4NAq2d aUcXAK4MyxvO9hSM78HvN5i3+uiSUl7IHTbv+X+HfIpMiHV2iIIPkVcSvnjGxL+wIfLe kdSWaHunl1JwOTZtwgFT042YGuuozPWuQkJsp48Rgouq+wIXKkaKXHY0hY7xKQPH9AuU KOzg== X-Gm-Message-State: ACgBeo0FMCQiNN31VbPn/gsQv1JuXDUwZPd20uf/24bq3462yHwIJcG9 7IGBmaCxtoij0P2P2/2OXXtl/+YUqPWKSNaWOwQ= X-Google-Smtp-Source: AA6agR6T/6kGWbp1B9hwvLzD1I7DyAJk9VuCDcmAA/RcFUTVUc/h3cSI7aXoalbc0Ir31o2ahWvLiq1ZfQvVY3drUGY= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:5986:0:b0:694:f850:223f with SMTP id n128-20020a255986000000b00694f850223fmr13656663ybb.491.1661902301117; Tue, 30 Aug 2022 16:31:41 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:11 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-4-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=10385; i=samitolvanen@google.com; h=from:subject; bh=siBrxi9qEY+bHfrdDLbSgqN76qbbdTlvUNSEbiqEl7E=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3MATW3VwEhVluICkF7vpOjQP1+tSli4MFo4T+X PTJsmySJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7pd7C/ 4ipjawGn1OkRVL5Ob5r10peEgVkvGylpgkc9pjaGMupRLdCHHy7/drjCLdklBNODdjAsd7PHatm6Fn AchDqGFTFCUm/XQdhltzt07yGXna3wqBpJS8pyljD5Z+6Jbyg2vEMRUjvVtKus8/DtCAjNAXyGtlPj Kx2hTRkK3+M2snu6VndLme0sAzl4UY8ds65a4ct+PRyrLemdbRCZUrJw/o8clsF3YSbseXAoRdOgph upgwpLT0oVD9WDxAqLunw+1d7mvwcbVx3iNndwwBZJ2sAPJ2hubTuZofsTtMgzQDUMX4e6ptSzJoDD sn7GB3CGY8CoOYjqLy3VvjJeZdXmfoahyKw6+afKgn/dYU+RlW19hgXM+jxcKJLYa9FFZ62BmhfJp5 pptKaV8gnDtzbebRAgD+6sberrvdYdMO9k8H1CIRhFv2fJP18G8TEE8MYNH4vxvxGnS9+ItZLnxO8t i/qFwlWouRxTF+hvspZswPM+C6BdI1hbKKkKuW1i0NCnU= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 03/21] 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-20220830_163142_758453_38C43D80 X-CRM114-Status: GOOD ( 27.45 ) 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 --- 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 Tue Aug 30 23:31:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960137 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 55243ECAAA1 for ; Tue, 30 Aug 2022 23:33:27 +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=DxJAfM1OYMIOmBUqrC+tTTuD6rNsTPwyiYAjAkYH5h4=; b=Lkh8cs3Elkc0jw+Xeccws6rfVE R8GqO6y0tAKiNjjDcPvVvQFNd0LJxSCY5U95Ih0YsZYb5pl64BIyb1bcA9SMp+NGYMc65w7Ebox/r LTgYNUJPspA+hRaVCtpZQuA1tXV86yXgraYvnoqtTw81Y1pjrg5qMmlsMcv3BIlfl3/5wx/n+uIfv RqBt1xoQvtUtowWVBIlVlJwUwPPbqWVYSrb/k67AitsM61gXGLel9oCvP3pEbUOgwio0Rn2Bam3Zk MG93Fc3F+nOmPZHm8CSmzk9sNMj8L0N/7jINt9B5JPhE3mNDGhoDiOUkJcvalQXgmuAOCzn5bSMB5 vQFz7+JQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAiT-002SuU-Lh; Tue, 30 Aug 2022 23:32:21 +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 1oTAht-002SeM-Af for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:46 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 184-20020a2507c1000000b00696056767cfso880785ybh.22 for ; Tue, 30 Aug 2022 16:31: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=/z26CVzacxgEbflnpwOBeepGVQn0w/gPmhmQRvMvTvE=; b=knXPOMHFktRNITAj1a01OM3CJ8e080e27LpFBRrOUFH3xJW3DsuXf6xNsydCnmB7ss AOh27n5brdxOhb6MZN2qlgFyihfVdcbNjyg5emybKIIcdNOuntMurwAcuaFfXbR3L9bv 9DwrEdiR0CiGt84G4ctQarxm0QKj1TN2/3DZsZ1dvaMGufwXfijsnUsyuePYsuDfuSdr nWR2GylNKGrU4/i/3+h+g4lPtcFh4/V24KBOlUBEvUEh6MUjaU9jMf5RzsEbmTiMF792 G5IJn04mXeVvZ3RB9AxIdg/lWK0lQfcwanF2WvHCF2W2txXqma4tQkArIqQ+WAnOSJnF k8uw== 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=/z26CVzacxgEbflnpwOBeepGVQn0w/gPmhmQRvMvTvE=; b=5Bn3GBJStC/FZOfxlExXxMTQ+hep8UmfrU1AJhSRYJhaXNsAT473askRWuZlQGsrJF 1Zyizcc2hDK/51G+dm9O8kxEYQ0DyqbtSVjYmQdUoe2MVlDNFKdBgEJVkqrrkaWzVBpV J4GeQplr0qYdfTo9IfPHrleTObA4Km+gicjxAYtwsV0LktgOoHT9o9TdIsxbN6qS7AkQ U8qXp4C9psrmGvaLsx32+tFG4QephfMgdyePviXN86/GQGP4U+bveUgmFojNdnLaex1r FWI4kzpPZlXVPjck2ilrNXx+TThTlGgHrmnBDRDrzLwNIFjb+n2Sg3GvDJFJ3vYaOUor Bd0A== X-Gm-Message-State: ACgBeo3h1LNcW7Qjaay+hkA86ihwqv99tOFhor4u28RSCVZbU0i0xml5 C8J1aIaVZKMDD1U9ZXkY0EJDH15T3c1kyuRL6WI= X-Google-Smtp-Source: AA6agR5u73nBkZGLCCJrxKVIxsdPurnsP+Dh6NdNvLDKDTDc+Wb6ui93/5J5kTR2k/07hiqeUqnIxXfN67ICpkbgGmQ= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:2f4c:0:b0:695:883c:a21 with SMTP id v73-20020a252f4c000000b00695883c0a21mr12959138ybv.182.1661902303887; Tue, 30 Aug 2022 16:31:43 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:12 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-5-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3262; i=samitolvanen@google.com; h=from:subject; bh=VjK0Sj77LlbGadkKbzH2JR2bzhTohKLFixpVfbAKe08=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3Mb+sUdWdFlgchvPUHgAyRneqSjmCj25aHmsBM jScZ3peJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7mDLC/ 0UATdRz/gMs/ofqpTV6ZzQe61nJSI8tXBsohzK+rQh17bBxgZpm+JdkGThkxMQapEabJvzCh3aiusP Zc7GPY61BxhGWQUB/TiSG+tUInkEMWJ/Z1gwO9oNMZpi+jJowEOHdgoOCj/EBf9L+ULovJmAJ6OZ6X 1TDy6idxAVdZKenhUg8JRONtj7YZBxAL+9jJjPhiKTyXYUctKZDb2aXPRGp710z/QD3KxUYKF9PhYK yjTUv+cKDm+pUf/V0KqsF8Jm7/ZirqdOWyFGqd/4SemaULIAdFSMw9yXrNfolk5Cbhg3KxMwLPDn9E yKSMXSgdd1+oaSgoexRHZGcRtqxTrQDmxaaL4LgapATU6El8k9CJaRdPGff4ELA2nLMkKANGOtj2hQ ++Bhomzi3O3fRj7FgRfkhQ+ed61qFLbgROUC0hC781JKdmGCCIhwBHs32PHLVjigICiiKp0vHzHBEz R4RV29cc8a0ne1G6NRKlw8CfwQM+oeXsaxESL6fGfIHVg= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 04/21] 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-20220830_163145_391558_B53CA5EA X-CRM114-Status: GOOD ( 15.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The __CFI_ADDRESSABLE macro is used for init_module and cleanup_module to ensure we have the address of the CFI jump table, and with CONFIG_X86_KERNEL_IBT to ensure LTO won't optimize away the symbols. As __CFI_ADDRESSABLE is no longer necessary with -fsanitize=kcfi, add a more flexible version of the __ADDRESSABLE macro and always ensure these symbols won't be dropped. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- include/linux/cfi.h | 20 -------------------- include/linux/compiler.h | 6 ++++-- include/linux/module.h | 4 ++-- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/include/linux/cfi.h b/include/linux/cfi.h index 4ab51c067007..2cdbc0fbd0ab 100644 --- a/include/linux/cfi.h +++ b/include/linux/cfi.h @@ -13,26 +13,6 @@ typedef void (*cfi_check_fn)(uint64_t id, void *ptr, void *diag); /* Compiler-generated function in each module, and the kernel */ extern void __cfi_check(uint64_t id, void *ptr, void *diag); -/* - * Force the compiler to generate a CFI jump table entry for a function - * and store the jump table address to __cfi_jt_. - */ -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#else /* !CONFIG_CFI_CLANG */ - -#ifdef CONFIG_X86_KERNEL_IBT - -#define __CFI_ADDRESSABLE(fn, __attr) \ - const void *__cfi_jt_ ## fn __visible __attr = (void *)&fn - -#endif /* CONFIG_X86_KERNEL_IBT */ - #endif /* CONFIG_CFI_CLANG */ -#ifndef __CFI_ADDRESSABLE -#define __CFI_ADDRESSABLE(fn, __attr) -#endif - #endif /* _LINUX_CFI_H */ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 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 Tue Aug 30 23:31:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960173 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 2DE74ECAAD4 for ; Wed, 31 Aug 2022 00:09:25 +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=o67hieBAJuauP/YSwhP6rz3Fv341aRIIuYz0aF2iRQA=; b=nZWPcw45lFaxdFY59tGL2FKlnW O/MnZbQr3D90DweynJK2vRzhuHw91FedpbA6N62dIVF3FSafQ74YNB6BQwwFvc4ySeOH7htbjeHwf 2YdWhS248lzFPhJ9n72HTaY6MibmOroMR5IRjOkBn3tNnnPUExQkfmH61lAxul6eFHlo3WM7KlSqO tMVFTaMnqwDMc049/Vc788q/Vamd20/ZXnpIPpOwgBpfmfgKPPmZX5wOF3XuqxrZWiAnLyc72MAw9 QI/0L/B6+KI4TcGhR6afZfbmbAOri2lSGPzXZnpu0SfMdeh0hFp2Tau87A+RSy0kYM6Zm9/4ibESV hHwBhjzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBGx-002dkr-2r; Wed, 31 Aug 2022 00:07:59 +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 1oTBCe-002bel-Tg for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :Cc:To:From:Subject:References:Mime-Version:Message-Id:In-Reply-To:Date: Sender:Reply-To:Content-ID:Content-Description; bh=W+Rg4QRmmdA0/Hc4QXoXxn9OQCFXsXPrsC4ccUXv4Tc=; b=OvsCbmSCQR3/vD41zCFU/bru8B 0qDWVphWtksyDaZEVTYwFhzydLWhgs7jqH5dJYcojiniYRX1Ahd5Kvvut5H2eUDBo5lwU6lxXTFp/ yUANbXHFHnVH5GAFWRI/Pjs2eQo5tmDQ+KyF1qGR8P9pbxRYjBjft2FCZX+s5QxaJkxMAu8kAotS0 ZP8fNMzCLWdGlyQR5wt9lo+BV69x5hjYueWXec1du02biNK0nALvVgCCqJP9oSfZFrLhxqIStWKW4 9GdE7WCOw8Buy7XItXa2PhtxMs89ZLs5H1B4QPSeQ269lZbQ+7EfCE3fbORn4I+HSdoffO9+1GrV1 vfhI0nZg==; 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 1oTAhx-007zd7-DB for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:52 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso190096837b3.14 for ; Tue, 30 Aug 2022 16:31:47 -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=W+Rg4QRmmdA0/Hc4QXoXxn9OQCFXsXPrsC4ccUXv4Tc=; b=rDhka3uRx1PU8f2EDWnEpOrnvrdx5qN9dYpFwRrqfzvRKXUIANFLrLRCziHCAUNIcr CDtIm8N/+ogxY9VUQGAhXL4yzuoL15fnpZhVbIULb4mqm1gzo3J5h0IgBdZJB1FScttP dfn/+F6ctlxMLIlzO/fbsOGHAe3OskYsCiUpm0ZOEPIh1mbC2+Nf+cftVRGfEimFQ9v3 lq9WAVd+Yi6VG3jdMVQFOevSl8vktq6shSnecjO0a+yZtTwUnoBkKtLj9k73QDySItSu V/Zj1fBtLnPbgXm4xEdqL+jO0WetgEoojDcSvgLB67zDo6rClf1tbpMtES9fUxtGbwVU xKSQ== 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=W+Rg4QRmmdA0/Hc4QXoXxn9OQCFXsXPrsC4ccUXv4Tc=; b=OgQpNTHfwTRURU/47lx3NUMDBxOZIyDXTFkhNGdZMiHLe/CvNeSWFjfhkKCqewu83M Spxl1FO2iWb9YKy9KwD+AGzhFIGLMzZBri0K+RDUKChB5nObM52GmrbZfraiWsfXPVHH b8NvQJw+F5nE4Dree9hMF0nd22uEuayGbUA15T/kqoT3E+2FEccwLduNMl+MclPlz4xH lh2MplTNgvc28EEjRBKbVverdBgHfA90nqlPDc06odBVQa5xknTs68rT9UFAMSvo4EhV R6q3ma6HUfsFvzwflLOU8uUzyS68t1HYucLTHCQibGhkZq/+3dTa8RLmaTf/bvEt2NoU IQfg== X-Gm-Message-State: ACgBeo3EdtRmbdx8m7NUJX0TXR4zjaeZB0eJcTyyGh+1QhoUu6c6lhdV ZOzHxx8NTxrswRwdL/esROyYkPp8stT1R2YsriQ= X-Google-Smtp-Source: AA6agR5MF3H8wULga6oaTI4IDTrFITlveKsApTUGMpZ8bebnrHcV+zPFGJHOnWGe87MvszIlybHltVZfU/snDGUEcQA= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:6f8a:0:b0:695:8d02:89ed with SMTP id k132-20020a256f8a000000b006958d0289edmr13982166ybc.434.1661902306650; Tue, 30 Aug 2022 16:31:46 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:13 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-6-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=15753; i=samitolvanen@google.com; h=from:subject; bh=kCPCwrWfKfR+47zuMRd+7NjMRv71MY29I1bZCtxLbxI=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3MrdViWUem/XBnu30YaMAfZydcXlgcbTrgLa+e jBt4PdWJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7umoC/ 49UVQV86/AuVPkPWkdVrVkEyDS/X6YCJh7gGxvdJkHW9pGZOxawDYIWlV42qbIKWbW/FO1ZEOXmtEv +6024VtQSVK+D75MltkNDV7Q68PJaWGvjSBCOZPdXupe76AUtLrNF2fDvUrcKhNbHIqQVI3gNYNmnb 61VrmRipFhfZZP36JbCxFSIQ8fSZz/o6wdm1WJNmCG7Am+vZEpPwhsbyI5YzO8stpkpyN5KCp02rxa oW7SmnGkROBEOVPKYFGgvuA9jqu7XmBISbEZeoaVehPFeAMa+9bR8XoNz85TD+4BGoTEuYjG4PL9Qm S5QfrWEKKhvdfW3A3/qZ9sDRMaFeGuNQP1a65S2iDzXwyCBXyHbkc1JMbrecqfU1UmyoCBECD1SLDe F2TJotemis8EYU4f/N1t70u/OJQi7ah3MSuSzdS865T8L8jIYWNHnMR8q3fQimrL6A4WN4/UvcMxqr MuCBFpmLi6jwn7Ht/KNck9FqME0wqqRetzAPUnaLFKfVA= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 05/21] 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-20220831_003149_667495_46B0E2B6 X-CRM114-Status: GOOD ( 24.71 ) 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 --- 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 952d354069a4..eec147f5572c 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 Tue Aug 30 23:31:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960138 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 0CD22ECAAD5 for ; Tue, 30 Aug 2022 23:33:55 +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=puImj6GxeXaVsMpStuZ6Lzsa1rYarvaBInnMUkW1UmI=; b=eNAEl24YfSSejRnqcsRbMBk4i0 UjUnURttDgFy42each0tdyXRZyKMm0oS31qFfwl9LLCm4kbosCNhkTUZD4tCA+rFmbHlHG/DitE5P E8M5gGJ6UGyHtQRsITQ8hAMC7aIbkISvtI0zb/qAPw9yfInYlNGaCWMzRGTn+J2prBnZ9g+vLChjT aQB4NKdbhfUJSAAq/mk+9QWH3YitKSRvwLt+dqwnOwegkMQwFlWkNWn0VZlh63JR5PxzANNpIVVv4 byi7slXA9WVIXktUXVSGHvo9N2aclOEOUlxSzWt1V015YgCflPPDmhGyR5cKNTxptRnqwaRXBotVW ztZuto/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAit-002TAL-CJ; Tue, 30 Aug 2022 23:32:47 +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 1oTAhy-002Scg-Ck for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:51 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33ef3e5faeeso184652707b3.0 for ; Tue, 30 Aug 2022 16:31: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=0HP0uvA43ZQ58UUEba95S/Hbn9bJWLpeKEcRZB7IkXA=; b=ghb+rAa5ndgfqqr1NGpj3Hx6OHHlYOvrZzYCRI/I0/miJPOMqpLi/jhEUs2NH2NsEc /Ie0pR/+KK0EpPSfo2+MSyuwv9kXWCPQgPpE/IQyplk/uPBLsy0O2n7981PKrvD2qwU/ /XqQ2YnPcfjDwmCTI/O7ouDWr8I3Z23ZapI5UL1g+VUEUYsYJMoysuPXY0l1ifZp7v71 kNmzxgiEgj3F/lwbmST95w1f1EQLii1VabTMGgwHmxeB2fmw4s7/zdmFKJmeH3rqia8I vAkK8Z3YrqGIBToXA+hfumAn+ch2w6F+Q77YzLz9AqoPncgKoQO8nzqIN12e54mn8fXP HJ2w== 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=0HP0uvA43ZQ58UUEba95S/Hbn9bJWLpeKEcRZB7IkXA=; b=U/LZXh5lJBazRoA2wx3QDZYMKWqJnlFEMJ/KPvaQ0P5ogxXdTrMDZYue37Otd4mU9z OSXQDYW2BoZLlIxP7wOQTV3KlNms1MX4kZ63fA23V2u4EtsOyn2w9zfxke2GCcGBfGrO RfiGT+wavybiz4pVVAUgDfIFEhFGiRuboD/9oixsq1r9z4EjlZe/kRVbYbW1/rtLws4w O/LV/gYVf3K0r6ESdWeetJOg/T/n3bVuLlBTkHLWxu00aKpyW56Feac2ivWwJXt6rWCe aCVjcl/3syAxs87nW8CmlcjN1Uk3T6eq2XGa7Gx8HGdh9MvYeOgJ+m2E24PHjtt7YxPs 4BDw== X-Gm-Message-State: ACgBeo1d5g4Mmop2QOWYbcXrr9x74Y8N+5q+hj1nlj4M6YUZ2B+QFsRU jNjhaWYJgDXHanMIvtmiGnK4KnKdlMwj/XSp4HM= X-Google-Smtp-Source: AA6agR7E6sFZT9PUzkGGP3q3+LDqH6QwHWXnwCTK8ZHH2q+uNYehXvHgWXx3+rlvntWf3vAkts/Bo0e9KvQON7ecMBI= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:ba51:0:b0:683:c:f71 with SMTP id z17-20020a25ba51000000b00683000c0f71mr13158853ybj.51.1661902309437; Tue, 30 Aug 2022 16:31:49 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:14 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-7-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3855; i=samitolvanen@google.com; h=from:subject; bh=GpNP7VSNWEHryZQIbE63CWLGUtZrRNNHgFNGIsCcLD4=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3M+D27Vh42dz5Wv1D7BtVLA+c02bXPeMllsUQG nbALH5eJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7oO6C/ 94PkporT0a7ea4yN99Y0UVpECqA2sx1W3i2E3Ta36aou4DLUlkkK11bJAHilB90A47YnMhOyD+xQgt qKKB3pKeDH8pGEOLtNrtnEcXa8Crfg92HjaovTQVUu0/EZPE04ME54eNDEPYc3a+V4i5acQbwfayOD B0FHeJLg7YmKTXdSQw1OCZqJmfO723qcQ/XI/eRxbqrZQyEVq3N662FBhRI1BZwJyxJGUKVFjALx7E W60FTV25BYf9dy7O8xvh++ELkTTfrKeFtMnwnAfkOl9A6vmx9T8d7OAI7sBn0/8K3nzWRQuWYrqV66 mjnnzUqYPDcgxJBn9EC2aNqti/tAGgC6PtM1uERqT1VdgPrWwYG246O0IZM1z5wznrj1DnlrMmT0+a mBAL9oB8jrEBtQ/SRxdAZbh+LkXmAx2XKKBltPHK3GvAUGxPGlOLjFBMbKvbSO3jtAV3m2OqXpjGF0 td+Ah0KUqN8vnfBbB9WQZO9fsTb6Obx8Mpa2GsG77Z11w= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 06/21] 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-20220830_163150_463739_973A58DC X-CRM114-Status: GOOD ( 17.50 ) 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 typed versions of SYM_FUNC_START and SYM_FUNC_START_ALIAS, which emit 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 121794: ffffffffef478db5 0 NOTYPE WEAK DEFAULT ABS __kcfi_typeid_blowfish_dec_blk And SYM_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 ... 00000000000003f7 <__cfi_blowfish_dec_blk>: 3f7: cc int3 3f8: cc int3 3f9: 8b 04 25 00 00 00 00 mov 0x0,%eax 3fc: R_X86_64_32S __kcfi_typeid_blowfish_dec_blk 400: cc int3 401: cc int3 0000000000000402 : ... Note that the address of all assembly functions annotated with SYM_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 --- include/linux/cfi_types.h | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 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..dd16e755a197 --- /dev/null +++ b/include/linux/cfi_types.h @@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Clang Control Flow Integrity (CFI) type definitions. + */ +#ifndef _LINUX_CFI_TYPES_H +#define _LINUX_CFI_TYPES_H + +#ifdef CONFIG_CFI_CLANG +#include + +#ifdef __ASSEMBLY__ +/* + * 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, fname, linkage, align...) \ + linkage(name) ASM_NL \ + align ASM_NL \ + __CFI_TYPE(fname) ASM_NL \ + name: + +#define __SYM_TYPED_FUNC_START_ALIAS(name, fname) \ + SYM_TYPED_ENTRY(name, fname, SYM_L_GLOBAL, SYM_A_ALIGN) + +#define __SYM_TYPED_FUNC_START(name, fname) \ + SYM_TYPED_ENTRY(name, fname, SYM_L_GLOBAL, SYM_A_ALIGN) + +#endif /* __ASSEMBLY__ */ + +#else /* CONFIG_CFI_CLANG */ + +#ifdef __ASSEMBLY__ +#define __SYM_TYPED_FUNC_START_ALIAS(name, fname) \ + SYM_FUNC_START_ALIAS(name) + +#define __SYM_TYPED_FUNC_START(name, fname) \ + SYM_FUNC_START(name) +#endif /* __ASSEMBLY__ */ + +#endif /* CONFIG_CFI_CLANG */ + +#ifdef __ASSEMBLY__ +#define SYM_TYPED_FUNC_START_ALIAS(name) \ + __SYM_TYPED_FUNC_START_ALIAS(name, name) + +#define SYM_TYPED_FUNC_START(name) \ + __SYM_TYPED_FUNC_START(name, name) +#endif /* __ASSEMBLY__ */ + +#endif /* _LINUX_CFI_TYPES_H */ From patchwork Tue Aug 30 23:31:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960172 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 9065FECAAA1 for ; Wed, 31 Aug 2022 00:08:31 +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=EG6XAOqbgvVS6rWkVAcGudLzbcyiMn6BYL3BSnO1eYE=; b=HSXNoIJL73ek9ZU6ae9xziq9U+ L+NTsepLRzkdi72pD2sZo25jA/tx5BQn8hjWY9F2HpOypVeWzPMGI4zlbDu0MvuZmkoTamGAamTFm rT73khsoyXBdM1iseIXW+q1PwmJ0BCB9uYLHfiA4+h6uQ0s7YNrbyOxZYoKsqC3SWBWuqs6HLRkZF t87oSLEvsctObvtH3s8NjpGkuO1zu3acNL7HvSlAsJlldZ1VmAY+rbWT3/hUlhjIMsgq7JHOA1Wk6 I8PYLO+fHaTvKa9B7tH3ECaXr8CqB6R1GBI1/dUXQ0/FGWENdFINzrvItKhd6Nxw1Y6dIBKsQulcc iyPwRAKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBGJ-002dQu-Gi; Wed, 31 Aug 2022 00:07:21 +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 1oTBCc-002bel-64 for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:30 +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=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=hWWeW9dvJ6l5KcDFAvijK/ItMP jXPXOxrSkPfTdiuKIMPXmg6kLJpcPvm0ZcpF0NI2u88AAl+/AU2izb97NbksSrwkV1Iq7MrWJdSni dX03mKhngAWDkPun6Zr9Z54+F1lOam/HilhpdhYNh/h18NpijVJ67WkAvtm/w0gMcNihrpn8yVbpb evZ1SQW/PNtKvKw+jJBSTqrwux1vLMvYQlnNmOd3V77zLmm2j3uoOavgjfAfC9rdKHS7q+GPLoLd8 KRcl2fCc0LlJ+UpzUwmVZSsADgKUbFQAE+M+iHFgcnclZ+znbfiiV7dHcY64odcBjJeM3gRiPlCm4 oy/7nGFg==; 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 1oTAi2-007zdO-1i for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:55 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-32a115757b6so192004777b3.13 for ; Tue, 30 Aug 2022 16:31:53 -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=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=XT3FqCUj0oWltSKyz0DMYCdz3zG/R+ch6PgREyusoybVfYnjSIIp1QEVmgkw27BMRj 1bwaWQRauXjRVmhR+FXatY3cAFgTFdHOwv4MeNRe9viWmXCdGh3ZqgTqK/bonGIUbUm2 nzVQrEYCIwgQuRvzHL9weunLc+sqBtMBzhAT8qbEtdumA2TqedCJySqMrqa0Xf9T3VwZ xs9JxjNj3lR1umlvKCUf9SNYAvbTD4J4ebt11ivYnN3e4XZbiJ9Vkff0l7aHJfuG01re yOHwdfZzJCRQzCio9+FrwTtHBU/fAgGor0fUpdX6v+iYm5fuK07woR5EljmpbadzEdVA zmtA== 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=stIJrjMqwQ0zAOFApEyjbwm3OExfLqdVzHQ/Ti/K+RQ=; b=CvjMNAXGrVUwueHCJqfTlIUEUkoJnjjpdB8LhOq4k1QwvljkafyIFz4fkooNlO3frG ftqvkmX5XqUusu9DOYM8k5aitIhwFys8MUV8tENlE59Yftzu2aF6BV1+bGM4OlIdiLRm kUq8BosSKil2nKtEdFLpdcEUn/sXPJMjFnKRQsxnEGBOeiiBEqZIaFTy9McO5ZqKjIvV XkFqFq6fFx7LZ8HMZ+ChffNLytX1iwPFv0LmaJRqrvhHcqBFPl2gCLXPQQqEZIJFYYzv T0z8iEAJAMKC8DxeG+ocmr+fXTHrWIs1Mnqz5C3tTuplU0e+r/wBbCL0Il3I3yj+gqik pyKg== X-Gm-Message-State: ACgBeo2m+peW094Sm4yohb71XpOm0g/fESVolmz2V8iyPBSSY9lDjum+ BB7JlRRRm24KkMfA3QmLT9fFYL6fwKa7EUJ9TY4= X-Google-Smtp-Source: AA6agR5cGTdetFCiErxtdp82eH3P66qCr5xSoNGpsQG/NljG1Kaq9Ijanf8vSqY++9XIfhHa37mVG0A5SaW5IY9d2eE= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:8803:0:b0:341:6235:8cbe with SMTP id y3-20020a818803000000b0034162358cbemr7018693ywf.146.1661902312128; Tue, 30 Aug 2022 16:31:52 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:15 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-8-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1674; i=samitolvanen@google.com; h=from:subject; bh=qxVnlSZocW9/1UypXlLGEHXfm4CDzclNhcl/lJ18fGo=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3M7+6Z3E3yWx3lSnRphzF4/3RQHI2psdANcTX1 DniQSb2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzAAKCRBMtfaEi7xW7vYpC/ wJyHxmthaRukbl+m+7vClm87xKX81E51zW8v/dmnTAiBQ7oT1Ek1XR7SJo/50PfceCBcZ366Psr6wx L7143nIwKv3bXT4p97cRjwxu4M0m8HvXeZYxX2Xqsc6uerduxtDTzFjDPWA8VsVsVXpIN5BluFq//1 Jx120TP9+6zYwQsOBpMcJCq2cr+LMVUG0pX2qqLSJGAE1+2yoL2kBisWcIdDxS1jJ5266S/HoYqktz JO/BzYSjJqxWmTxt2M4SzxDHm1EgNjsm5ntVO+KRW+klcvF2/1A+hyopJ1c+SrByL7fc/WNq8q15Gu rS6sXoG21TAT7q0EBWR2GYae6G6d/o1Sn1DTQpzi+TfRj8zYXkDPGgdxdflelIoodZ3g3q/vf2hzCC Y6S35Cpa4ek9uS8PsTuYFkYecoZCw/xrq+x1R6KPGpwl3/NAuYPWxv8goJ10UY0hjOxJby0LDXRouv cp8+PZmKAqFAjGeoHcRcLyUkHJSTY52q00bcKiCKHOdz8= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 07/21] 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-20220831_003154_244319_771D627F X-CRM114-Status: GOOD ( 12.88 ) 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 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 Tue Aug 30 23:31:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960139 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 922ADECAAA1 for ; Tue, 30 Aug 2022 23:34: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=e0KUMQ3HztD8hRoa5t/n3Q/4d4stZEnN7NKCMZHENqo=; b=2dmzAxEIfZi7+Zi7YJdmJuBI6m eeU26SYqU/lWN375UtMfQgSxvyE6T1HeMF1a+OFDXQQiwgC1SOIlmObRdYrziWbQ6XDmZIZw94swt 0BXBOCzig3i+XNOICgxVWIcmnW3XZ7EG+s70sVMmRP/5GOxFGC1zWnR9mIfNfsA2fKBLkMdVTUxVE CpPOXF3akWAn9DPzsc1TgiZ9ckFjwX8oRHzIQ5Qm3pvTGCLj0UTHyw8pabZrBCJMqxa+eXsqxTDwf e3QbRC6NtFPiLXJSauwgsHM7DDAA29eeUwwcgbk7jN7CS8xP0c2z+PddJ7kLiuU5P5GNVFyriBh7l fI0GEcKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAjK-002TRV-3I; Tue, 30 Aug 2022 23:33:14 +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 1oTAi4-002Sid-4J for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:31:57 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33f8988daecso182272337b3.12 for ; Tue, 30 Aug 2022 16:31:55 -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=9LSUCUqEmRpIK5FTeLqrINe//PWWlcjxscTw9SglyBU=; b=Su8/MiPy6GrNyCZfLWSzM0QU1dzSiDI0SliUWOKUODrw/Zg/7o59CaOtL6G5L0jYgM X/nIqegMyA+Kh3i5o6gz/yFE72IRB/oYvcAo8B4Ou65zdTIZjxFkikPuDGdBb1bm5xv/ MkQSCWKHffAiHPaPg2AGsKSnliAJQUm2xtplYZb0b6I/YUiwy4GlqRa2GenrNFTV1dfC ORdhrBnHz00KdnQtOJmuoxpAMGLAy6YF4CuwKBafGYerSmoW9wEz5roZcGDBWthhjt0r Wut1FEVu2171ad+NOt4gzsl/aDqaQaEmAQ4TMKeMKbdDJYkJo1/+ghW7G8iMx/Murjyy wsBQ== 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=9LSUCUqEmRpIK5FTeLqrINe//PWWlcjxscTw9SglyBU=; b=Uegx7C+Z8dKT76j+Ux06moogs5eM/o2zaFRL/9BzlGfEhmAQWBfGT1K6tRHrYAiAqH 0GWufx4ZItTuLOLcUiLoSGZNJRI7Q9rWCLTfgvyPjHnyLPKqhldm+NDtEVH9r+grc1GZ g/uktWrrN0qAZiIvcVAMRif5NtZ2Fj7+QtNAEkz7+ZuNWrk48pk6gQluJZ506Sh3VkMH Wop+PlbxRdqe/l0Gd5pLZUm5dhm/GHxR7Gb9GHi0hPNiSE9wT/PUbWVrJdUlTG9gwMJE BT7qXw35jh7OBKNRv32uYS/B8CepI1l1wK1dA8HF2c5xIcgvlSq7dLUQpSB9ytXr4qZl YBjg== X-Gm-Message-State: ACgBeo3vR2+jE3yxWZ6jBdzoWh49Ys6BJ9w5ipMLAEklyl3A6XVuXPoi n0rhkoWitM5EuJQUyamBkUl2jWqzRnZ9PfZrmZs= X-Google-Smtp-Source: AA6agR68BGQFfoXet7uT17W5HOi349FKHJvCytSwwlUunuycgf/3w6VheODjwTRdH054IFoEZZevvqkxZQsPtf/8osU= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:1c4b:0:b0:340:972f:abb0 with SMTP id c72-20020a811c4b000000b00340972fabb0mr16059486ywc.489.1661902314803; Tue, 30 Aug 2022 16:31:54 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:16 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-9-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1663; i=samitolvanen@google.com; h=from:subject; bh=dCgTAVpHmh6ue+qIjFQmdwGO+wJHDxTFzsMUhw9fLMU=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3NvhTqxF6HKWPsUGSSA+N2dkmpL8jOb0ZK7Jx1 pV8vgQyJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzQAKCRBMtfaEi7xW7kFoC/ 9rUzKXMDXQKoSguu/A2Rv2ATA5t4yfg6zrdjYpiicpnCS+TbGGK2lUdzlcslHdS1IDP2ecHOWcdDcl Fe0QHSu2ujICLA210WhZwuUleMLIwtCzQDdoDj1VPjBfrJ3m8Bvw8UoVtabPRz2Up91t3EszVWpke7 cOKRhf1TZUreP9c5HzmehuN6xPi6PfCsXekOiqqKS5bveLFNH1izxbSyDg4MB/Nf67NMlQonGdnxzl vhT5ncb1Xb0rn50pB1LcJRz/YZ8D3+Y3Vc5j3XBWHUj6N3RIJOxyEXC5ypoF774b2i+O7fvWy20CPQ hFIEux/rXEdv28MYbGssuPw+fLT/IhlbUoI1f+MxSCobNzG5kQcxThpkupoA9NFbFWxmBatG+FcPc8 WTSgP0bNGyxHqO6BkyENMKnpUsvQbWes5XHGgvDop67nvldrkisGMHpuaEXqz3dQ99BgFp035sdyOc zEqaAajdW2W/J6ScBKCLnWsAcMP9axCky8DTM7nWY/lBE= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 08/21] 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-20220830_163156_211151_50D29159 X-CRM114-Status: GOOD ( 12.80 ) 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 --- 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 Tue Aug 30 23:31:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960171 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 1DE4DECAAD4 for ; Wed, 31 Aug 2022 00:07:50 +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=TSchS0CdXFVzlmXNx0a13CMU+hOq370A7Lroa1p6Ja8=; b=s9N9+IyQkm41e9NkeCKQd+OnBt VANxzc754rSeB0fu+3j9QTEfRQkPRiZbYhSYMQsKvAEKRxF48Fwn7nAwZ5AJi7YxjX0iOghVNwN2E NumdQjO7NRZc9TLast8PTbR5uvbDOiBBnksrlRMq1QTh95TT1zvSIvt+WW1f43HEU2WvGNhJXhZz+ l9aIJiIwcoHlXUCsYNFyptYQeUNppQ9plfl6zYGfzT5BcwEIgZpwVCmHBXuvnWpZ4Mb6/FxsImG01 6e2x8vHhFN+u2XxmpMTFx2oFPp6jh8FLVPRvO1aU9JQlw0PWtPakV3aNnqGUU095IL0C1jTXxAWLj v11r7Mxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBFT-002d23-Rp; Wed, 31 Aug 2022 00:06:29 +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 1oTBCW-002bel-SI for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:25 +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=xCc9uuNccPEaVQMS2s0Cmbndoz8x1OikM8TQU2p/PE0=; b=LP5OVm+SNDa8RARysg8k6K85lD KtKYQjM640hhDVn1Rls6gg3IPAwxv55HITER7US4CtzHzlVB4BF32tDY5f1L7T7yv9Bag2GivnUK2 ZA6OuyZl/8VgpkdTpBN9C0FyEffEinESBoSMY7U/08YCUmXrsCS9z5VbcpRt+jfL326cGyNM3MjQm 1xxLD+PZBsJy+UcAsIKvLorXHHfI2+UgrBX64700SLD7A9Svgf/+B12fM/LM5pQk7gKaKLttjQajt h150q5RLUJ8zSVIgwAJBorEKp/T19eCd6sT3N3wIMffWhMso1Upl+xnkA8S84X+FdXec46ny3YoXR vMmGHxKw==; 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 1oTAi6-007zd7-6G for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:00 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-31f5960500bso190099557b3.14 for ; Tue, 30 Aug 2022 16:31: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=xCc9uuNccPEaVQMS2s0Cmbndoz8x1OikM8TQU2p/PE0=; b=nH7CGzt09tUbSHSP0XWszujyNVus7iperihjwd1dE9u2mZgMby5GfquRmubKg8Jqh8 giH2SAX8fzeDcvNNz4xRUeZED/AHEVSe2EuhAXtDiOj5uIzKeAgGoYzaeSxMgiYqZ8Y6 e5An5TYrB/CCB6bEetpcdvhjpVhY4hetnDH50VSlL/qTGk1tfCxq+4wWVmzRP7d363br saZlLKBl6H8+rycwlczCKRIRy5Ez5SdxuII0+LmIki2ADeaKSrK8wfYtKKTD4db0TRm+ iqF5GLv96WzvtzQB9u9LQq/3707Ah68f6nHHdv/h+P6bf3qs5RIL3Y1RfiFs2Oijy+ye A5gw== 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=xCc9uuNccPEaVQMS2s0Cmbndoz8x1OikM8TQU2p/PE0=; b=Y/DbS5v5ArmAyy7JfkcQ6RBMNIw6MYirmU+92EzXoPI/cLdQiBY+rqoQq/eSqPw6UR /8Bq9MfXcL3ciafsobqSz30kim6nS/aSITvO28RDf5DTTOfF6vkfP7km6/qlR8fyBcj0 fs97iADBkL3caTjiX8cUu6pPX7Muhn47IyKkeTZyjKYDz5ZOgJoL2fHBUnKIPhmfsfyv /Z6wFu4lzZ5LGuIgvz2W2hx6ynnaKVBvToA6M5idY45BEyRYVaT1IyUdoX6zGnaWql+o HvPdw/H+0jB8uk6i/bB4kxyEAQdOmZ9nvSM+j/Ja6ipTt4ndOqtHFg83drjzRIVwRvGn WVvw== X-Gm-Message-State: ACgBeo3Hz09BPaVjrkgCIEVCdWel91AlV9Sb4j6LaOqWB+vpSoMEcOQ/ FpbbB5X0R0++Cftkg3AF+/mOSqXWwCtSL+hhdQs= X-Google-Smtp-Source: AA6agR4qaYQdZ4xvx/SG0GN0jLKs7LULbyIZkGlZFdXi8C/5fvuRyPds0byQ/MlelLkLHjrgf8nulFq9Wd6cj3msxGQ= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:48d4:0:b0:340:a478:49a9 with SMTP id v203-20020a8148d4000000b00340a47849a9mr16297855ywa.364.1661902317205; Tue, 30 Aug 2022 16:31:57 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:17 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-10-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=3867; i=samitolvanen@google.com; h=from:subject; bh=dZ0t0cN28M7OF6REwBdzrNBq4nPUpgahVwqpYuj4zJQ=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3N8zN8blzdSyUyIYRgvgdWIMjZGYVU6Rzg0w+j C4X8UWOJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzQAKCRBMtfaEi7xW7kZhDA CdKnZfEgEG2Ozl80ackvyrbUgIGmvki88WIUyUV1b+eFTKVywz4GJGjVq5KFqlV7wN6B1XEM9Qznmf Wq411slEydLsFb2LHdN929yVuI0DRA0Kiy6ESYz6H2tlVzk9t7tQOAU7Qkqe1is80gZ9cZvZLrq8xz HtZzat9tSPYaeKlsMXW7X+i8BcrzfTK7B9pkfKrVh6JDDIrsrzVOZRtvg9LHm2F4vD1y3SGvVR/+iP CzyoOEugc1Qs6t+OWaZtk6rnMv2rcLujNWCREToQKojHp/U4P4m765JgfpVHMxc8p1xlx1M9tJzrGh MgpVa7Re97mLd69cuGFw2TKSrI+UVdaLtzWpEPYEzsMxhaxwTDx3ZoJvEOX/ueYSWhFx9nluHvBQFx kIGHij+QrreHgYm9TrS++3Y0dA2uNUPktM58KP7vLxj9ixHU0ofEwhqPAuXo5RfLFSceSTJn8jrATA 2Tp4RpbLiuIWL92fo6kRn6MgJAK33J8UKuiO+qUpzYMRI= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 09/21] 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-20220831_003158_437711_EA1AF0FF X-CRM114-Status: GOOD ( 13.64 ) 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. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- arch/arm64/crypto/ghash-ce-core.S | 5 +++-- arch/arm64/crypto/sm3-ce-core.S | 3 ++- arch/arm64/kernel/cpu-reset.S | 5 +++-- arch/arm64/mm/proc.S | 5 +++-- 4 files changed, 11 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/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 Tue Aug 30 23:31:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960170 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 602ACECAAD4 for ; Wed, 31 Aug 2022 00:07:11 +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=14FHPBSy2ux7I7r5RwoT0HY/xNyJXajD9eA4eGMNuwE=; b=TzMexAuRxJDgP+LA7CaonMNdTA sykfooep8aSEJ92/ToFGYlOq5G7PpeqPk+6bybZtqf149X2j+ocv/c6t5vLmA76LnKpzt6zaVqbsw LnP71oUy3U+L+0ikMNaaYa+JYdmCco0VW/AsE1v399oQzx/XeSw8v9S5cP8K5Zw/hl88D9r/d7zBe gpuM6GahIS0vtiGBOEgJLnn75Cbf+GL5UHDrtD5HrgM/Uvq9cCmKgeb7Epv5emBSdSBPR3kZo/piS 4PQuj02iXiiV033Q74XXPi/PuAWr5HuaamWx7qMd1b+Ey8po7dfa4rpSoveXwbsUtI0stzPLqYz0b 8rAjkZyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBEw-002cmU-56; Wed, 31 Aug 2022 00:05: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 1oTBCV-002bel-2V for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00: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=uOrNiSaejaAx5qzRVyZqVhgDN11YWeACFj1vc5KtsMM=; b=Ijd1hNlC+vzNFpZ23rWaOKiLQw XWgPLSkZx7k6xc1FNt5b62JfgtiqFWF0J9s1lbBuGlivYJeA0aGSsnl9EMbb4iaBqpMKxqml6zEI8 XoHtuQiOM2QXTfyIxbX6voHmUt6qc5jWz05UuffD98IMpwp4H3DOpVXVXkaLC3N+wTiNEHBZDaBti ZsuzgJulCXF2mj5IAvQvJxAuh0QYbUEc0oEeV2utzc4YfBebZRosO5FX82tlRPPIx/oG8IVdlGYl+ q2LdTyzbM535KSM1tNWXgiDE11v1FMunRXcaXmgAl1j03m9hPnq70p6HWQqO5ApWmxBIs08VvG9qt ztvcN4+w==; Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAiB-007zfE-GA for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:05 +0000 Received: by mail-pj1-x1049.google.com with SMTP id 36-20020a17090a0fa700b001fd64c962afso5399510pjz.5 for ; Tue, 30 Aug 2022 16:32: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=uOrNiSaejaAx5qzRVyZqVhgDN11YWeACFj1vc5KtsMM=; b=YXVYf02f1px4URqdoH8nvqICJVlUXR58i4S4EWdE/hO0LlZchKboqu1WNljPY1heGh A3rHjpNxpwcgDEHBC/OUuYajkuVymRwDCfpYvLFoYSPFvj2/YGkYFTgC4H8mvjAZDtVE P8WqIcQ2yDCxfwFg2TSMjm4RiLWOk4Sw/aBfpZAjhRBT8sd3Q165e8iwoCCefsDLOxcL EhIIwcSHCQZn6Aeo4Vsn1Ko1Sr3KOiRidG62d8LMpPC4dwRZW4Qy1epFU9BE+hxZ6DOW B87xr/unhn5oZBF+SBf795Ugzr16QlxHjdJCSpUo0t3+PsfHLFr1gnEyyc7QX2j1CDGN TSCw== 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=uOrNiSaejaAx5qzRVyZqVhgDN11YWeACFj1vc5KtsMM=; b=EvuEROLbNTjn7ZykztsziWCbjPgzHImGhrjCqdtIZAkw6nvHugZF8rNEchnxm619P/ he10j+li9BfhPaPMuZHGsCKd64fMHHkQyUMvvMEPD5PrP4ShMLNBVlkMJxMbMzAAGR/g pjhNuUV6BMlkigkJ9B39PynvvymE+KqQBZaTgArDt3/ZZ438mCe4ER4upP1K0WulT23q 1Nq2N8OsAydbWMLwZ7iQzJQQLsyqwNp0gjy/LtEpQfB/wo/fyHg6WDeEOVzQ3DQ6K33M Fl3pujvrlmwIbXfpbjX3eUY3+ZPNC5ECe2RsfXunTIwY7qNp6AXXQReGFKprOa1Z9o1s RXzQ== X-Gm-Message-State: ACgBeo0xujxIOPDX5ebtCwh62ntOfVB0zXEbeTDqejHcIbJ0CWs5QAmj YO0J4JBH7/XcyRKhicuL1KY0F7KIx3NwPxiei04= X-Google-Smtp-Source: AA6agR4y5BrK6d8x+Ox8ZJFf7ghiZkw8sll3zq6f27EjB9bHHyNZxn3pbmX72/UaMjFQ28GlKHsmZfspYrVTkTwGn0s= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a05:6a00:1a14:b0:52d:3e35:5b38 with SMTP id g20-20020a056a001a1400b0052d3e355b38mr23603216pfv.11.1661902320611; Tue, 30 Aug 2022 16:32:00 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:18 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-11-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=6529; i=samitolvanen@google.com; h=from:subject; bh=nax/A443rh70RgFtHDBePJR2kdPLcGN3ANa3NK4sLi8=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3NK1Z21u8OhRuM2jehM3T+7tCoihG4K4pRyvz7 OkhRsH6JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzQAKCRBMtfaEi7xW7i94C/ 97cAZRVEO58C0yxsqxcjc52SnV0Q3pdCtoAixUtA2bkV68T2uBNfNz5YWatziNJlUDvsL6JgHGx1fo 9RuZHIvtx3o9OGO6wTG7Vnrm2yRlwBYD1H7GxD9XFn8onBGGA9Wn/u+btijUxyPaDKRqm7kiiZMUBV JgtHzTVCp1ORfJxxfbnrzxkN33JefyJwz+V9rnSx4w/Zko0s1CovjwzoWhYYQyx9smbXsW704bRnWE j2mI/qzGiHQTarDyRtR+gfjXFPLIFLmxiLLMNPQgZCBuNcmbHMnuN5cPrfEsZ8gOqB9V/uoQmseQev nXx6hwxdy4nWzyKYl0ylTpJBC0IbzUUnFQJqsepJS8sVdpmoplvPgX+FeyCbld30TJSm7IDOSwMYPM QsjftdSaOo6CRXP2ezJh6Ndzgx+FF9sZoEO0DeWuLVanjx+InxI7QCBiPUJb94OxRsRgYRwhkLL3KE 9+hIOnieKNzQKrAzNHaNN/jbkXiz7/4y6Mu2RzMMPJrNw= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 10/21] 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-20220831_003203_678165_E837D3CC X-CRM114-Status: GOOD ( 20.47 ) 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 --- 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 Tue Aug 30 23:31:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960168 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 568D0ECAAD5 for ; Wed, 31 Aug 2022 00:06:31 +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=LB01Cl7+iwvJ3xztDPDAeK/amK1FTL9eSI4Gbqe3++E=; b=ZbZLAurtOEsH/Hq/5MVcmY9btM J2b/yc0ocjwP+uahItUv2xxpNvUBmCTkmwweok+vytsRxguKpJ+JjFPkZbACbak9A5LXFP/60+2TY xJE29da5IIHvwitbeWgxpQdl11eEDDmRrAPuHXbZwT+j1FIHtziCfpymdoVjTYEvQquTYD1eGwij7 3C/LrCOOiiAUMZY6lpjAGmZkyCJY9yB4RHX8+FnyYAd/s5GZg+38Yo2VxpcetTzSfOntk/9JitIZw cQxH2s7pmESKRULRsJKgL5hTVFxmFsHNKmunIGyPm0fQsyeXTF5O0VRWOeiHlZJOJBgGzGhqi+pMA 1D00Tosw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBES-002cb2-4u; Wed, 31 Aug 2022 00:05:24 +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 1oTBCT-002bel-Gq for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:21 +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=iSKFadVRGufrYpwT+lMSnNGa80NvrDGJYFfJh0K053o=; b=lfRbLIoUP/RwmAahFkxGC174k0 PvfEdHpai9EjO09tju4UM1H+KubihYdWsZDF6A4es+MdlOPYUnbePFGeuSSLQ3TmxiEHYCB/NhC5I 66G/JIZCcz4DrQcPnFR+IrP6MVFlWvKazyNLC8EGyApuUCM4UuWTXRIX2g/eBSi5RH+zTnlobfwPm c6+e8hL4faFzjAQ5HSMpcoIw0gTWGHRsvzYvMFHmBH/PvtRQwcqOR4XLhJaqXogNCEYi8ODXkwXe0 ANOC+5IzZFq9aeI6o4qY5sAg/EhEmqHFr1PyVcjQIYWkt2qCUbzN6A7Y6ya6ODjEDekRjq8+M7Ujn pQE7YwUw==; 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 1oTAiD-007zfr-1I for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:09 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-340e618b145so122408757b3.2 for ; Tue, 30 Aug 2022 16:32:04 -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=iSKFadVRGufrYpwT+lMSnNGa80NvrDGJYFfJh0K053o=; b=aea7f+jGGqYBZvgs3orCadjUsDfEDwReuGVw99oeGDGf7HEC9SsWjsfrc4GKNaD6hP nrq5xjB9KkSqASgIkUlxMnTp8Km6owmHFu3fTgFOv6KvP4eM+abfzLH+8I6bLicq5smv eDG6ttbs273TD7DuasPZT7cximHiEM3CmgjyhDFTYjOlX3lg0O71IK8vGJeisE537v0G /84LNcC/b5N5SGDtXczpJ448nRkwvexxbTXvAda6YuVil3v0IrjmkMJ6/bHjXAJTWE+9 ykzvYVbqr9U6P1Z3KvlXY+4NvSLMXaotZL4KkDq1MWLWxgRs+Hlhts6BqiiWRh+Dvfl0 7e/g== 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=iSKFadVRGufrYpwT+lMSnNGa80NvrDGJYFfJh0K053o=; b=3aGQfg2uZY8fDQyrf6wsSpEV7EFLG8tX+aSSo0q4SErHpzV53v7Fz1B2x6hBUB8k69 YJzscFo61CdlrO+893HL5ahJKkMpnu1R27cdODfequBR8HvDuy5eyPAQghS0cTHjWnSS PLv3DM+7AlYy2DcfP5G8fnqt079EnF4tzJp0JcQ9e6X4czxSM8Jfb1QoTTGqfWzDA0gF 2x4UalhDIHQsRKZbW5cXgFxev6nPVRuIQIrDR7AwLJewj6/4mPVDKTQnWLkuol/JAMvs 8gfBcF0EMBeEksizsFWnDc0t+KkkYrwgirkg7WyY23hsnZ4FPhjMo8JdQEGhkQYmDpJq ptqQ== X-Gm-Message-State: ACgBeo0FVqRPNE/CpJbz4lfmusIpCXz6HzEpIUvndkeSei6cdpJ6JgEq fZBV4+FlR0dkzRqJyBStRYDJVWvgZ39DGnZbS5s= X-Google-Smtp-Source: AA6agR4dNWfY0j6qePqn3prvgFjGMASrL7MLejp/isbrgaHY+xJaMD5dtv41AGsWWLDIY+wLuApFeyxpr9oELA8nW+s= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:3746:0:b0:69b:a100:521f with SMTP id e67-20020a253746000000b0069ba100521fmr9841652yba.135.1661902323439; Tue, 30 Aug 2022 16:32:03 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:19 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-12-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2392; i=samitolvanen@google.com; h=from:subject; bh=4fEwVbMTS4PhblTx3hjYUyv158cFLGoiHZdYncXlyvM=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3NGeTaUnU1q2XxWRmRjYKzsHzN1uiEteQxzaGl 2CA0UxGJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzQAKCRBMtfaEi7xW7rJdC/ 9UcVy/DfbAoLGh8Ex43l9s3e1xNLlcP/xWCoYq8CUdwrGkU622rRNiEdF+X0NOBHDwK8i7DyRAn0PK 38Hsd+b1qOoUJlPBVMxl/ymJ3j7zbkQsbJMr5XWRG0N5HmxXjghCylDMKfdDFZ9e3gew1xx1sj24MA jxEVQYBIMYZVDIpYDmZgOv1biQKojcsDFIE3lFclQtcPwQLPWap3PVAPVd2oqDMfKGQXNbOaa2Qgio doXCrE0dslkp2/yG4QHSM2E2j0fNAKDllqfR6xQcjCU2kr6anScnJ8rolEApP2tMueaLsLoxMwJKbD +pf+ycZPrG8GCHpntkBi4jULpc66b3D+JN9ZdgIl7RTqNX2/9XMbns0EOfrhy9gNgoPYd9bhIJpm2k 1M2frsyMoG+u+4rCsSKGqYfnQJvjamiR5Y6yncD9JRQDvdhecxlWWD/aVLEBel1hFOkANsQfHEESXp x6U6Lko1f4miNMWO/ymnQfmQ+cJiFgtDuMnEUqvhkTYsM= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 11/21] 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-20220831_003205_395251_47B4360F X-CRM114-Status: GOOD ( 12.98 ) 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 --- 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 Tue Aug 30 23:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960167 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 88E7BECAAD4 for ; Wed, 31 Aug 2022 00:06: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=wBoym7Fvcs+K7N+JuE5h4bwqzU/par03dMBzcb429gk=; b=2ItYIyYZxPwsc8KefSqMhnBkvY U+yQpuNFCFnUG12HW+DdQ9UeGkKPAE9UXhAi2QSB+QZdJ7ARF4X1i3a8K+vsaqb+mnc3KPLmWjwiQ VTfRUn+vj1ZgMmECcWVRNH6exnHCmVcHude+Jw+WeuKMlk0wSR4+49ybeyiRWLsiPEQI3EwQG6UbI p616MvkTtpZyUADyNDIGwR3lq84+zsGq8eaaKCfqHXzv09PL6OR6OAWI3SIeOlmwEG4VupztltlWX CW2VbTE0+cZWpZREh/xmIM965mxDCwcU4zZO0GocymteebwWngxjEnNi8/6mjE09OLQWHmXGNaoTx byjSeU1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBE7-002cQE-SN; Wed, 31 Aug 2022 00:05:04 +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 1oTBCS-002bel-UT for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:21 +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=Y90TqhxNMQ3gAHq7V3hOpDRusm/1brSg9ZJSv3Zo0sc=; b=QnMMHRV1CILavqgXbKQEi+XsHh 1zK+knVQHplVhzPM6cA9b2MainbeiUbEoG/O6mzOB3UNvqmESp2DQnHid1KR0Pdp8vZRU0QiROWlV 7dR9W7DzqQKBaK68ohAVjQxJyNwOjb6fZ5l1pOlCzOMcXEyNL9/JEMGVfxqOQn/c3HplamDRGZPtw 1N9e9kbQf6QJFZa/o3MrbTsYg2xNCndFH529iszZAN57cdIMc79TInfkyli/1zi3WNprUXrMh6Bqw 2OSmGW26Fks9Q1ZvsDM+wzaEmuhoiV8FiLmU1nuZbK4PRQwZ1gfI6kN60s1xHZ+H6wVS6wkgd7PCo KC52WuMg==; 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 1oTAiG-007zgu-Ls for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:10 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id n18-20020a25d612000000b0069661a1dc48so886818ybg.20 for ; Tue, 30 Aug 2022 16:32:07 -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=Y90TqhxNMQ3gAHq7V3hOpDRusm/1brSg9ZJSv3Zo0sc=; b=Blk28reIZWBLJmUJEULQ6cuj0seeXr4Ly6Sjc4PdA9VqIS72GbhwKOIthbX7BP3K3N tl4uHkaui0bFxUYD4FxnerwhmSOCRt/3a5W1nVSjTlFE5S9qQOnfSjeD+biC1n8T6oWx CbxEnNYofTItTkZMU/h5o8yWHwX6NcU2n8rdEECLrsQyc3xbtJG9RGHbiTbkD697AH8p 0p/VCT7qeOFCYjRLbLS2or7mI2M+S72Ny0hSJDqI1Jl/Ry3Vw2Yi8g5rHuOMRQOIZqJZ nOcvTxSxdnqYA5nfuy9wwQ1/vdS+DuiGOCwB1maldh3NXrXpJxv/SHt8HLHfTqiMuZE9 kaBA== 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=Y90TqhxNMQ3gAHq7V3hOpDRusm/1brSg9ZJSv3Zo0sc=; b=xejI0tVlcLrH63Ql8PNCm4kZHbHmP3wbvfMk3oC+HpyKacp3APnaRN1/Pno2FeLfdO Q66XDprzanUXYSWiZXYI4UhBlrH9CH4fEWpRkf5esjbQkgOs8h0E7LykDgAYVoCQzfeu ougOya6wYURmcpNfs1Iu57ZpYkBJ/lyjcROdoq4W+bYYMWciHLKXVcfab4Y1gthTbP4O 9wradIlvX3PBHVDS652qTxEwkeNUdS2u8rb1uDftAE5GN2XMYQFdeFmfwX2eAewJTSj0 WC9npxvjxFPni57RoSAvThUHIhpOxmauGIC4YIICpiuTHgoEo+3QIOUPKI7icqFjYWkD 8qrQ== X-Gm-Message-State: ACgBeo0TiuzLu0ct8+Po5fsRcBgZjv1X3V54b2CA7iIoVN0HHvEpzZWp h00eMbYdTNXP+arML36qt9HAA1u9hBcKMXqyEE8= X-Google-Smtp-Source: AA6agR5tejixecrSXUwJgJfZQ1DGEkGMKK6rEqZH62aOV2J11oU/lyLTxrPa7Zxga3qsoA54O8Tc5Rriwx7flr+ROlg= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a0d:ea90:0:b0:33d:faad:db54 with SMTP id t138-20020a0dea90000000b0033dfaaddb54mr15764471ywe.116.1661902325870; Tue, 30 Aug 2022 16:32:05 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:20 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-13-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=933; i=samitolvanen@google.com; h=from:subject; bh=gYeKGrEmE8r8WUfed/9NfQZCcqJiKdZ5mJNzlRspFgQ=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3NYIHeCmDy6N75o9wbFM1SaM7q6xMhl1ek5nmf tKwFtwSJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzQAKCRBMtfaEi7xW7mfMDA CCrJQjwANsScQKI2BY9zkAwahvmB7CoktFhlZo5wdeIVcUhYVU37TOPEGsDCHGkMEcnh3utamgs/Y/ T6ipy6/m+pUxo/fJ2ZNU2wTtK7Gjm1EirsF7INven2B4n24G9e/aUw/L/0mAyY0pTXMAZXUuWM5XTI EDoGM/Jc8rxyuDuxxSvM1eX9ScZu2/qTH3Pre8WBN80Qwoq2pdOGgSlZYiGpe+OrKSjWFrO8rXwKIG fnEAva4AWwQlzR0bfLWO+yuUpVyA8T1YoPNa1ZWYIMmSvyi4ntpMkBcCloJvnE8hUo6vmXmhYad4+v S9SWJgQX5wn8D1h6+3oniyHgD9AZe19ip2/ywyg/UiOGm086JGI0e/uTS21tWyJNyrUP6Tx//6lmV8 enTLqz1/8araIWIF9mbmw+PUv21yPZ7DZQf0/LGoaJSmORa06SCfBeADR7lea9HyT4TCOWkdvGiGi/ N53Qy4QGRFuv2zZNiAmohrX8NP0ScQePKcN06eX01dGBs= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 12/21] 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-20220831_003208_865492_47A8A901 X-CRM114-Status: GOOD ( 11.94 ) 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 --- 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 Tue Aug 30 23:31:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960166 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 0F2E1ECAAA1 for ; Wed, 31 Aug 2022 00:05:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject: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=JnquCzqJXWuWDmQEE2AbkbooPyJ6dxgi5CXYGvTkhhA=; b=0zr0UhBnSa6YiwS5HdCOwqSCkn xDAqL7toRI5XQvq6Q3/k/DPOLplXyuI36xYLokNZLOsgq3FwbswmfciqwZScIQsoy6ayVTaU1/dwJ Nfs+u/DwlLYobqM08mconSOWAP+o0Dvm3czMnnEhGA6bNUP/uKcQLFsbZ6wuE9B2Rs28Q6aodh121 XPSme5ROeQm3C/1DqHGz93QTY2Bl0odwjjK1/Qph+dZyxl2EoTH6MSTv+bSRFgD2gS9KFSIvoB8Xe cHXLkyo2OLeqvvt3GdIUdN7vHBxkY1DzdEt3mZn28PP0JaRuZDDWPQO+GD/PDO1rTLsAIJ7Ju1A0K hFZUTSZw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBDp-002cG7-EL; Wed, 31 Aug 2022 00:04:45 +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 1oTBCR-002bel-4r for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:19 +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=2RJzzt50GfkBkKzSKhsY7PPvK5P139xVWWGbb18iAUo=; b=mm5ZYeNuZBCHESh8aQDaqPg2A5 ciLpdYWfsv3yMToFGy9RVdkeS+frS7uAHfDUj38qRVQO8z9744Z5N3OeQnoFAyOvDmqlmJXaCv780 3Y8/rO/pj4xGY/FGNOJSSN+M3Vg+BXpQHl4D9qZnKFQ1Rx7FwYH4aYX+fk0zgIIhnGcvbFOmk3Xu6 9VoHSW47f+jlBaWS7R2RT7cSBanJ+5br7izYwU0mLJAJLQO0nUSbyXO+O5eZQEokrfDk6vAEMowMF 0tWPrpIDMVwVjlxUyJE1cuFFzWPm6v1HOvJylQf+FSJmS3RO4djowinqxAzsitMHAKQ0I3qMmML7+ lHgDP0/A==; 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 1oTAiI-007zhx-DX for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:12 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33dbfb6d2a3so190477377b3.11 for ; Tue, 30 Aug 2022 16:32:09 -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=2RJzzt50GfkBkKzSKhsY7PPvK5P139xVWWGbb18iAUo=; b=R6GPGEjJY+7YK8cDpLcBb1w6hkR8Hf2a4SNGCWP0ycCg1936jaA5LdXrBTGi6TYwqI VYnU32jZjYr2Rsf1yaw9FDmYSSGFRc5sk4a/80vO6Zw8MLk1+lgBM+xxajL+9vkFNolR 0ZwoBMKZTckPcbSdwQxsP3DfqCwXr3OSwWVUdAx1UOZIQoTHvOsczZ87984vIGCYePpW 8880MDiA5vB2ae/5MOnnp56ZWQa4zBIvDwlVcQYxxCSe0Kyf9KTyg0vRukSlM+7nMflk J6hGrbVvb8mTYTv4OOvF7KVmXzPpU+iBwFq6k+qJ+W5vNgq1lECDFzmbB1/9+pv3x0Ia pkkg== 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=2RJzzt50GfkBkKzSKhsY7PPvK5P139xVWWGbb18iAUo=; b=R8lzBDlPUFKQ2mrUUw+LsiLCIcVl0L3hJcsbsYcX4XmFtVV4bnrbNriOmb+R1tBA/s YjKMQ9RC2cwsUdO91TpkdRBvyYaEyz3t5idCBus1Tbh8k5hC7Vp5LK7nLUviOmIrAUX5 nRrVyMCmHuV5xI6Bnd3pnfkIN9x3+vfPyHLrT43Km2GYsgfTUMS8gOJLd6jjmDl+DS17 SsO7/HLvitTU2ODfB9YjPlgmAHqpgIAbI2Qk7uQXfOi4RVB9w6GbDJ1+k97n+7GKnD22 ZlJRYiv7N5Q6/Va7+cXt1bgwLAytjpiYdYqE/w5uWFswR2x1OvInQnae4b+MSHzaaZ66 Ur7Q== X-Gm-Message-State: ACgBeo0AwDuLRRH8dc5dS+GpMJ6D6GrIxLja4NnU5xUtYWhXMsUwHoH5 TrqzraMv4YhMDmXzLEpmSGp+h85zyL5jj3/fWWI= X-Google-Smtp-Source: AA6agR5rGizshBcwMwz1jDhnWdK+sDCYhkjmu8jqwm6aD1IsHdoSUqus3vT6CXj+rKCeZg+XW4kTJbbY+RskvcNWaKk= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a5b:7d1:0:b0:68c:c23a:6c08 with SMTP id t17-20020a5b07d1000000b0068cc23a6c08mr13358515ybq.327.1661902328531; Tue, 30 Aug 2022 16:32:08 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:21 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-14-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=7480; i=samitolvanen@google.com; h=from:subject; bh=pydGyiCp6+TYUef/iIF5ioe5+KZhG3vYC8bwhJPrUzE=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3OQmmoavox/3xbE3Q+Eb2RMNEZIGgQzvAz4Y4T 7ZjaP5iJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7llEC/ 4yCsRkIF8EFINpwkz205dfDNgQgzmCDBj1Xo5yqaYKV0UW6QBMDp1wHY8qWC9lFzDT+MaCIcLMmT43 Qa8LryJemUfbaExnfHW2nN9RW1qGyBOaf+3ZW7Rb/h5cYhz/h5liX0wsrgjJZ5de5Q2hRhspEkfyDg zix1Cj/CPwvy1nwp7gfmWSG2yYeyjby6eCG+Xmgqx+TwtgyNgbt9nZPf5drBZtlX2cLqQk2EDi4eVs tQMVQpXtqirV/2CV7HKCr/Gcj6bLzGv4GIo7Xisd1hUDWV9AZF7P7VhTEzsQNTiKJN+5epxbmJH6QC VP+08pYrNzzJI690cb9Yob5x0Od4uzujqZUCrEz34osS3v0//3f4BZFK1uTjv3Ip5E92ZI5p64pWQE qeZYFVb16bbMz+pef5zXKfka5IBm70IfFaUQwdivcq8FM1V/p4oNjSCiTrCyvqEjOCrqTfZgGH1zLB tIRvJzt6oGkVmfiX6xekfyBorjUfDGjuXJHJswTNh3IpE= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 13/21] 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-20220831_003210_580559_0861D812 X-CRM114-Status: GOOD ( 18.39 ) 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 --- 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 Tue Aug 30 23:31:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960140 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 D752DECAAA1 for ; Tue, 30 Aug 2022 23:34: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=URl17BgFCYhrChtlAoiLbZPwRtLxYLcmT2sAVggjWuM=; b=Ll6UyrAgTTjGPejZU5Qyy6iiE3 ghHdOSpG2y0vGQ2xCnYrZ6Mx48rjrN0HMEECvyTcViHKK9iDYUk0XtQlGNXJP7spCKQCzGXcRby1/ jegUZ72ibEiV9kCGC4upX+f7ZvQbcFdM66ZutZSbW3yGFBeG48TcvyElQnePgmQp0w9HYeOejvi1+ 3Z7aCD5NHui3qUi78/fpahgOMmlifxYfjKmpUx/dm5eVetHAlK/M5LWhgUFoOpBgcXMkM3aOfGvU1 IJMGvkvJruVs1PZIrVtkwaMwkj5y/jkoFve/6CTfrKlR+fRdICCEyvv9goDoeCwt/v85WHLC7yGCI piZpvqnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAje-002TeW-I0; Tue, 30 Aug 2022 23:33:34 +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 1oTAiK-002Sog-Lq for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-33dd097f993so192415647b3.10 for ; Tue, 30 Aug 2022 16:32:11 -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=saKNbXZ+fTVa0JCRlEDSkii0PaJZv4EakgrTZQbxYqs=; b=XD92pfvmT5UHG/QrlG3x9hvk0uRfqb5LlQMcyxwpxG4Wvm3LMrD9fBN4uRw0cmd3JZ rQk27V3ud6PA9klM89vVveRJNcYRNPoK7Smg/GRjHzNs/qpH/lsfOue6qoG0E0W5XAbS LCVsvBBxhKptrcXE6zTxH2Kf84TnwhrfYIDVjUuW6MFXkh+8IGAFDG7Lv0amG9+3O5u9 NVHPeZM5EZcwXMZOdETU513PilVsaSsHeHh1ncLczWvvfxqefmwikXbsa0jLUPtuklss vGdKBOFJndYV593TOqZikma2MqAvRxnESnGVJQPpfozUl9huam1HsjXgxZyh3MRsMjBe UxEw== 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=saKNbXZ+fTVa0JCRlEDSkii0PaJZv4EakgrTZQbxYqs=; b=0ORxJty5ctWrAaxO0BVkx5GUpnrXIo0isTcooEtaAGA3ehCCxpe3PjdRHN1PNCfYyb AMUDEDOLmI2CqIAsIfSYbw4rAO284nFkGwhu/N6ksawPE1Fuyx6r84/9jw774Lkrr3m3 DPPkNKN4kSxfq78lAdfOx2Gwt/usHiC07J9SBZ0IgDhK1OOrvGnkEvxNjpEehV+aL9+W WEuLDAz6MZyIp9pp4Yhbg9vsQ/mBYT+T8lVi/MbbvAKehNzOfkirHhpiucbm4DYC7en1 HgMH9o7xGfetekvfa15Aw0zc9mE8K/PqQ+M21UwZrqMm+kqxr1//aonGhfOaFX51Tv46 /o4Q== X-Gm-Message-State: ACgBeo1wHmyhvMi9EcylTSPfUsH37XGpv6DeWINFSN4htTsxQijyKFI8 efqYc8thX6xolYYp42p6pkOMNbISz5jKpQpzyM4= X-Google-Smtp-Source: AA6agR6xEQ5EyMbo66xRDA8vDW84e9YQyrHtWQROUp4QlR4E9NAmiWv98pKaF1InZnqVuSE2D/OjJElxp+jjP0RZeUM= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a0d:cb0a:0:b0:337:1dbc:4c21 with SMTP id n10-20020a0dcb0a000000b003371dbc4c21mr16082798ywd.297.1661902331345; Tue, 30 Aug 2022 16:32:11 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:22 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-15-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2540; i=samitolvanen@google.com; h=from:subject; bh=47sy+JmGHjJvxG1HdOlerjFJI0LNv5ITm57Sshi6/KQ=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3OJuw0Lbmu9DwQiB41MJWv7pYFcmThxoyhKmDF NnpHdLuJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7jjTC/ 9XfHgdD1uKnJRuMbjXkORu2FVPpFXBG9howb+XjW5cmmpsWsNswLD9oHgViYcRhjWfDHHYgZP4EiGe exmmrQD/bheC7yEI76RUsyoKy7XIrIslXoDfK0tk3+pAJfxHy9yH+PXmqpiRgcW9CkutyukbhRqjZe aSLk9lpH0fEfgJjVQdmyjRS5YchkeuDU7qX8EMlwEVLIJxw/x+T8iSHWSIAISM/oG9zZMiYY7i9hCb bR0reU9bLkR69p4txll9OqqyyUyiGiLVdosVn48XtYoIEz7TZD6BN19C9xs4Y0CLFNGm5v0SxdH2wj oLjogYcicWo3Z9EuIianekHBQKoGpsBcsb6vbar2WcSCxG6wYSI/cXWhiGp9G/ryiIUDMtdP6pl1rS Y0NjFq7PgfDgWWNCzrREiqHzewWSIkMozSXjAoVf21npOgOLsXp6YtqNGh3XdNOpi52ZGaNR/+VTIZ xGyGb1/j/VcMvuAloU0xVvqPRyjHv8kDkr7ydi/mDSyDo= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 14/21] 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-20220830_163212_750331_EC87DC75 X-CRM114-Status: GOOD ( 15.01 ) 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 --- 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 Tue Aug 30 23:31:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960141 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 4A1EFECAAD4 for ; Tue, 30 Aug 2022 23:35:25 +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=fOpVI8q6qe1d4jFPVrCSN/dIVqSkky0FngyHQnk6hy8=; b=Px+YIf8eJW0x1BjiOsf9Cr7vPJ 04ugDpXgGHDker0joAKiBpRK6/reNa0DcDr12hebHoUMReAyuMwpGgQvRmcjGgrLThqUNsG9oQ4Ph rgPqU+OBREGEnOd3/QtW/6YHV1OG/kbZn7Hp5cRMJyn5j4aKCZivJSLIsRNYU/4ERluKygXlnWNs+ z3pKA9W3m84kIj8X5izKgW9wH7PX4qAX/0M0Ubj9PSmsYkUsV+sDjB9BkfDfAl7IoWV0ZqkEeXVzj GfZHy/4FZ3Jcyfk+567JfAu4VprIrcJUhBGuZ4FdhkB6p53hbjoq7CWP2itRHIFnf98Okc3x5eEAV g1CgETsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAkE-002U2i-KB; Tue, 30 Aug 2022 23:34:10 +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 1oTAiM-002Scg-T5 for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:17 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-33ef3e5faeeso184658557b3.0 for ; Tue, 30 Aug 2022 16:32:14 -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=n40/u3GLqmsxu4IE85pNJcP9++K4Useg8HbhXBojdL4=; b=Ejy4dcy+n+UiG1ME3stkb7GVIWkvAfPkX7yICgdYp6uo4aZPhzpruBJmaLzw+Ih5mH ORZm19of0JsfD2WIvephfVDHAeQDrCvPsHIsIorJXIkkhxLw8ljqYzZGMEBJNQpWCUIj nmtn2QwPeE+4USK26c7e4Pk6NUrAh2dhoZ8UFwiOhK6nfzDHl7fBy1gEROY8XU6835BX 5A7cmK9l0/4/F/E1lc+PYknPzcn6UL6+uFnjEU48ins4A/f0FqKFYOifqDjykTdi7DpO RIyIJwe5rSpqMAO8DvB9PYljp6BwnsBCu/2a3CMDtzd8CYhGo3Fu8DE2G1mB7kSkvh5O RSDw== 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=n40/u3GLqmsxu4IE85pNJcP9++K4Useg8HbhXBojdL4=; b=1agPtceMXg6mNmbpYinw2aF2rGR90xkV8IivbfeWz7TQvpDYTKRy3GCgQsKws97uno +dG8TqpMZUZSZQ3bNw4rpzfFyw7fbxVPI8vWWENFbQtlwJjwh07SRyI83ijVByvlSPSj 4DlbDbhQ9HScMlp9Hc+Q7IfKvhUshl7IMvDOrsQtLvt8JiOfEMWXuuCIo3XquoMfhxa3 6LOzouu3S2HwKb6B7GtZmBmVW1158OAW0bybslKVvlp1WwRNCjEzRHbE025uiu5cHfPH mPBFSooJDs9TL2ie1dSELgssdU+gvwCUsN2lDHVMcdxw+3+E69WdZLIU9YWng4YmZxVL Sv+A== X-Gm-Message-State: ACgBeo16jtappGZHY5Ubw4f5thI7w2TQ885VDuGbNKOMHGpl1WMf8OHq nG1/0OS7rLg6EaQZsinQRZ5Rb3bTdEyuyL8Gxvk= X-Google-Smtp-Source: AA6agR4camlluRPyZn2mYh6ojH4Kd762rIUBn8UhUxj55dLf86lAaZW81nPVpp2G3nwrBRNBrndWfDsPVUijetdSaSM= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:4e85:0:b0:33d:bff0:61d5 with SMTP id c127-20020a814e85000000b0033dbff061d5mr16016322ywb.111.1661902334023; Tue, 30 Aug 2022 16:32:14 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:23 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-16-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=2195; i=samitolvanen@google.com; h=from:subject; bh=le96GTO4ksz7OY+3iMudMCU1VtGoneioq6LRMofQQsk=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3O0oITmtI7+jpJD3uvEuxE/Vb20bnTEv995FKo 30paGN+JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7vNlC/ 94mSA0DBHq+0v4mw+5uuo0Y2ojxJ/zL+w9Rh5alJcipeHeM4yHjFlM74aNV+de9n68C0gxd1RJmXtJ MSAtJ07toyQNsNCjTTUsoq+FoB8wmgYDpgXZanEKV8vvHFCzxBbGR5NJO6v9SeMx7pB0K47C+x8TUO 8wHz4ISsl/GIHWwJCBXxr8QZYt7fgeRIyLsWXNmZnaoEdnegtolpq0oajuzrNqGIlMJZsd1pqd94Nj miHCDcFPYWWxFy4PzVkQkpSNKZiA2RvqzBFkB4ezsqNwDwpCU53ym2OKUBAcHODJs31eAN8zOQstM6 UjqOEOj6ELOVfHte/hH4ZDtdlsYQDyw1rMOaO/5AHb3GxATMEm/KUtGS9qp6URexOEVLOKkKV+yEcl cXgb11U3ipEfZc8vYbIL9CjdKTrpOrVBrBskDD4tdV5DeUuOuwtxF16X2eL/p3dXp2f+5lEmuOpy6Z Gz3Ro7Q2ufa4cH7EShPSDMhdZgvDixQ/g+XVwcph8lCnc= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 15/21] 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-20220830_163214_991537_1CB86AE0 X-CRM114-Status: GOOD ( 15.13 ) 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 --- 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 Tue Aug 30 23:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960165 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 0BAB8ECAAA1 for ; Wed, 31 Aug 2022 00:05: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=B6dTj8kXj7lk3zQPuQkPUx4oOWMXfIJpw87KNiGugiI=; b=2ZrXwK79kwZStkFKEqRifhata2 nMGqKTnnIxdjpSyfTPAvy7YE+LNkxPhGZvkP/9OMCFiCCcMr8lRnKV/JWTbex9skBpTLTh7bDS+Ay 2Ylpcd4bdoCVY0xoyDpCfvCSxRJ1qsM2L29k9E2Lk02wZmnBVrWpnrLKu8NSvUUMTVL0uioi8+K4T 3Qnqvia/CCIlhkH24Nszqi9t/wpRHNNBrPZAxbOEAmA5B/D4v8snW+8Ew0NxbZ/ScDJ64+pyIlVYu 39TLtExKPnxH6RuVpUTl3XCySmpIzN1FsAgPm5BsepbPldJcpLnRa1pCs8RkOxXSQ8cDUWFbvkCq+ GCquhgPQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBDR-002c4p-4v; Wed, 31 Aug 2022 00:04:21 +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 1oTBCQ-002bel-9x for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:18 +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=QaAhiBNrHu6GYkLFA3B7rG1GS8UtnkRvQfTpKHPiaFU=; b=O0V92aPEbUQeh8tpzWJtV5+G5/ 2cr90lZvTzHT74NN1zsiQPcdi2+ggEdUlvkO/6/M5Qk/3Vxo1bIx5kKn9HAA4ysXl6dO1+5+aUxis vxC0jcdBO4AYo1hPHDVJTMMOwcvusw+wtSDSRo/kXZBaAmT0VyfLw/GB5zLB+TYBt1/N5Wz+rq2Ke WJsdLOihdYp72fRlPJpBWeVuHgXsRfvqLtxftY1fsI4aCSti0xxjfEcxjJv0Z9CbSS6o5YHw9skwx EUQ1jF4XoLUMK1fykfn5a3cEdmeb+mLmhRKcUy2CRc0gvuqK1LptFJgoylsvBzpG50ntx8uUVLNow BPRX4A2w==; 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 1oTAiQ-007zjT-6A for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:20 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-335420c7bfeso190449767b3.16 for ; Tue, 30 Aug 2022 16:32: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=QaAhiBNrHu6GYkLFA3B7rG1GS8UtnkRvQfTpKHPiaFU=; b=Uzu0hS7fYpQn9SuqY6pJYAs0mwU+Cbcm7VfqttztC5Y7vvGMMQbw4wbd/rsgMajhX8 hCYkTHXcE5WgpL526ftRFAS1iaJreodEJpABN25rLzozJPt3fTcwLmVcYcs0vcC1nhlH yp59OC26/dM0xfLKycIeelmnMx/ctiemiWAngqrglcx45erw27Nl2sLJAj1c3kLUftM8 0iSFHBjA1GYjEC6cZmd4UeYpgAKFk2VTxcYmGZKFX6zgfodGL620Sb3emlMY85C3OcAo bE5fs06VNU0/03FLltVrwNWpMmfeDGopu8w2Crj1CckQW60JmF6IEikz1fcox97zq9e0 FlXA== 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=QaAhiBNrHu6GYkLFA3B7rG1GS8UtnkRvQfTpKHPiaFU=; b=7YTrCrodOC4weJr3GNHacJb+DhX+HnVLgvYTdu5mlTiDCZr7EMQmf40tv+CvnoIvT/ OoQOajLov/+7kVIC7Qz7coVfrS0CZE91omuHv0Jx7rJGYcyYuLUSgofTzXs6ZuGjA5DB bXQGY/aD37iOgYXswiWBByat3YYdaipGwGPSu2ElO6ZQ9WpbR7YVJ5GRix8HQoJknKAm s7zJnEOE0pMiVP2qXQ+sR8zEX6dklmZMI90EbcSAOmpth8k4qqcBu4p9gvJQEbLND8bF jG36P2gWrf/ldjyfGM+OgCI/OdwRB23Xd/prynYlFvEM332vKVbOJMrru5HvbGMayIZx dsXg== X-Gm-Message-State: ACgBeo1ihHmtJZ59ycv+g0DZULjR+uEtxJdnt8pFv+ipBaEO2FCZy/9U Sozp/YsI6RM7Mp64LqctLB4+7lHbx/AqIK3aXX4= X-Google-Smtp-Source: AA6agR4FDK+ca8ExoQOJuxzStWcPg0UmoHQzTdwmwi9npQMvWgOYplZw4nRfd6yLznTzYg9mNTUtUOCVf41ZKmBVqKc= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a0d:d850:0:b0:340:d2c0:b022 with SMTP id a77-20020a0dd850000000b00340d2c0b022mr13497429ywe.469.1661902336610; Tue, 30 Aug 2022 16:32:16 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:24 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-17-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1745; i=samitolvanen@google.com; h=from:subject; bh=jQm92I9xQfCJPH6jkHCDpzvvJGb/s+FwIZvLF3ZcxmA=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3OLXWXp4dv7z7QEAEH5wDVXEoy6vQwE4MAgTih TKcGqJ2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7uhuC/ 4mLD2OTFFRM6dzC+U3G8nSByx2EP7YNHOfYlhOKl0Gv/CfgBF/GmPU6h3gd2FYTdIVAmx+Jt5i7jod yHHS4gZDl8y9ik+cOIJfaq9PCplP1qzBI5UZveW67TQSOg6aWHjQltgyelJnFQOdFAyzVFhcjo1ZT4 RasjgLDZdDZaCQZXWXBTkwjmqg7yGU6nx6FTkZor6xheRDX2kEOcxc/tAIWc/F3tCwLKZO3b2OacxU kLhRFXfTjDHGI8CEMPaaAiF2HgUeJEAfx8o4vhL4zMeTDaKFmRQlmf7F9COJc6E7kag2I6rBVTMLaT FWl2SlSRnYF0zOFsCumLTWzpoCgAijPhDKp/uWc4Bl+x2WAveRz8IYR1rkvZSXXc/Y0/ys9658hItd QLTUDCSGboZ0fd2TFzIbCfImlNrGKDomVDfTKP6XcarqWEI1dc/zyJKjcz0KqduDH2E4Ieu9sxhkpl Xw4LrtrfDpSWz1SEU4GR+7wRiD1adQkP+R3N0lIVY4BnU= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 16/21] 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-20220831_003218_454247_458E52B6 X-CRM114-Status: GOOD ( 12.20 ) 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 Acked-by: Josh Poimboeuf Reviewed-by: Kees Cook --- 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 Tue Aug 30 23:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960164 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 4FBC7ECAAD4 for ; Wed, 31 Aug 2022 00:04:57 +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=4sfbPWlI6/U3dhotdSnLjj4W9iCKMRY44opbOCNjH9M=; b=hKDySV/5MYMEmjSArwC016udX0 8dfaTJ5CP1+3ahzE7Dnr59e763Ao0B1fx+ds5pY2L2pVY577XA7V8UC5MqCr0myjLAXtqIno9p0rq sYgHKXSTruDmtHmTk8cXuFQN1iUabm3G7LR6xYI03dCCX87UCJKUAWbn3i3S06RuyrnRbAfsy6QbW OqMHxSZYTi7ExfBpcRnXCP+Baq+EOaWiIFVYK9OW1fGn54HlIpxwm9N7f3MiweoZZ7f195ZPvALon gWN59uhFOqEoj3T0mMdXhqVmRE5WmtstmTnA14YPv9PKJs/cCJDR9IAbGaF1OQ6AzeAjxQ+2QwFmO KUP6AvDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBCu-002bpe-Gi; Wed, 31 Aug 2022 00:03:48 +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 1oTBCP-002bel-Jq for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:17 +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=nLLyHDlqzsc75HWG24SP3SGpvgxZ9V3UrO9VtB9+qSI=; b=Wxfp4DTczxk3T1/hS0l5CrD9mT 4AdkXfHSBJ01s2GEp368Ibroj4P8M1Ys/3witl+wGoC4sN8clwXqlGGvR7pg/AdidWxR++kP4LHaU jVrN1Q4lOvazLI3QzQYSkuWAPLOrnpjljM84/GEeScuqVdReumgXrW3Gd0QDrA3iWk1OZQBDDUnuh 0A92bfthSYLmPg0P3cVcPIxySJSKhULkvolUwUljiRlWwmTI1KfiCzYLBlJfTCJUuZ6sWxeMbiZd0 D45e75DxI8Wp+InQu+B2XeUU9eAcm+eukUGh1kA1iv4UJnQzV7A7tn9GHV8AMaiM/sP93rauk8RM/ MKtn3rpw==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAiT-007zkZ-61 for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:23 +0000 Received: by mail-yb1-xb49.google.com with SMTP id j11-20020a05690212cb00b006454988d225so884116ybu.10 for ; Tue, 30 Aug 2022 16:32:20 -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=nLLyHDlqzsc75HWG24SP3SGpvgxZ9V3UrO9VtB9+qSI=; b=en0MzguAxkGbIecpah/2+Xtucf1JeujXbvoM8sjRtirhhrivHvxhOjjc8XjIzzeau8 iqt1tYXFNwhoWt5JWeB4Qw2qlLDvMb/FnG5C3eS8G491X1vHXz0fHYMZX1mCaWmfqEYE agDpOC3DvDklQ/bhO9Poq/QtFeuzNG3cbZCXHMxiTbMs7SG2qxg6Kbqnwl9dno9zUMG2 5VzNwoxM8xnkUvu34R3iEDgv5EmULHaDWzsDMefk0MmRNFil+hz5Zq7BNEzV9pCGj39X e1LMfsrVWFIodkOV3rtExT4NeR8FXBpwSdqVScplR/PL2lzHJurkhJNRjTTB2IFcWpJ3 EKkQ== 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=nLLyHDlqzsc75HWG24SP3SGpvgxZ9V3UrO9VtB9+qSI=; b=TOsU+T5B8z5t6wSdAcESa6+UxWIwnSHLlmAWzh+7SHmkYitnj6GznVdjDMi2DxSfkQ YmIzf6gEZB34ISrrPZtecEmol0y9uDtvylaHZ6AzuoncyxhoxVrKskBOMNdki93R/ui5 hySZqntQmQhuoH109eZhRTigXVsEs33oct9YP4LnsIqvES1AGiPWwA1FwbJUpf3P4nL8 9yfQ//3lceO9lxO82z23t2om4j17QP9uyhVF8+TXIKAKVCkuwKS+9Brfk92Vxeo3eoxp 3r/JSQtnSLdmhUOZLBR0aVxizWDOHSgty7+pbifK094ERNYGbbAWIiWqMOHUZrO5awQW HKmA== X-Gm-Message-State: ACgBeo2ypU6cvbr1goTIgW2Vj3atbfstKiB7GQHQvhURsDtClYDU47UV FQAfFyR6l/ZMWYTBKNEjj8PVYE+zb+vKgj6Ss0Y= X-Google-Smtp-Source: AA6agR5h5efzqOVxmYbBIWgxJ1MECNbgPa7xGsG/CYzCNefyQ5w5lz2oa6+rUdM0FZqOdRsfe2EIRX/Bqx3hGl+nnMQ= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:be87:0:b0:67a:7054:c7bc with SMTP id i7-20020a25be87000000b0067a7054c7bcmr12511319ybk.601.1661902339549; Tue, 30 Aug 2022 16:32:19 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:25 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-18-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1274; i=samitolvanen@google.com; h=from:subject; bh=qCBEQ292K21rpauKv4Q9PKWzetqPm8IIUDXN8zVxiiU=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3OneDI8EsrD6700CYZ72DWnEF3yumMXVukuUYd 6cc6WzSJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7v1gDA CrSV1Wwh1iRkXrTLzRUVixDQymyEMNfAV5Asek7kdMhsjE05imH4BPAYNwaeaYeCR/FdZowXX2/dg9 uEvPso2aCMbdLJGMwK6HCPU0doxBN9bJ1Aghq8QSlLsvALuOYSHp204OxDb0UgUSCEoR6QxsQjww7p CkqIcDUIxxhgbZeB9GMuN90ATOpI5Tt/TjewRuGkDuiU2wX05LdVmyaR7uBC86YUkzrjzuNFycLxXE NjRh/eHVQPO6JRX5WHJFfMPJe3lTKuueweypQevFID/GR98VcRSjCttni916V11TYs8EbLYPoFNKYq jZtDfTIy1xRp4DhVWxfZub7EQi+dScfRbD+lUUzdGEqL/LUxdBDfS1TfIn69wnuD5X7wcDu4gLAcZw I2kDiw8qMGqDQd2spFj2dU2XCRZPX7T1HOjUU3U34FxzhEpjzO/hNzpNcB1ZBgTU8btt4TEoN7mMlK Y3FIWCZ7I5c0LXttu3a5FcrhHHCxcpdQKHjz89NVuaF0Q= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 17/21] 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-20220831_003221_693469_C31F57A3 X-CRM114-Status: GOOD ( 11.26 ) 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 --- 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 Tue Aug 30 23:31:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960161 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 50B6AECAAA1 for ; Wed, 31 Aug 2022 00:04:34 +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=9Z9sNTGo+ga7hbePfua9WSOc8LOnSWPOVYAnKVk/xwc=; b=Q70Uskfzl+Wnd6LOtVtqbcp1Pt QpKY1M9tXFo4GWxfzAUp/0CPC9ONvB9dja78XtW2kqBDWhLdqjOSllv43cdHHKjOfEpyk2je0Ej8E gAsy/Z+ydildgyiB6BLbwayDTZwOuObENx42cFgK4fqN9s4CwarkvmhrXdAa3GrP0ZOVZUpYgi/nw DoPSicKl4JExYazeTkfJ51vUBP1QrkAJHXxfA+ZeGo3WbEq+t2jKewNVRxIepMlkb+bzROlAafQf7 /ImQNMQb1hfXjQ7ei7DSE21CDiGk3rgv5Apfid5PZuCdyYuns/41oO0uDHETbOPRgBzkQrKyqRqh1 4noiwcgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBCO-002bfJ-Jh; Wed, 31 Aug 2022 00:03:16 +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 1oTBCN-002bel-4i for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00:03:15 +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=dj50MXIaDJBD96/1Gdf430/wXU4xb7a84h2xVZMa0Ew=; b=lRDQOVov76bbe+FVCLhyXQehlm fNCcf7RRfr1mJAXIka4ypGIcuvrDoEr52eUVaZc3+r7xfHzW+uacy6twdubkLxqGk+3sunqOleDN7 EG4Tpvcq/iGYd0ru9Ms2oYpbADQLMNx8K4V58LGkp4VQ0d4NYRwG3Dd/34ld1/R3DlHeMLFSfAVvz KWuhxup5hy9R0hsCh8eL9+SoaG6YB54sCkcC1Kd7oXyR8MGj5lnm+RfMB6C5dhqkKwt8fnPQ3b0Jy j/qeXGePBIwYVPYMGPBUudk0BunmgZFwKjDZg/J6O0teU0OjJByjlSSxZJ8xa2T6pN9xKfUWIkwXk tFnf6sNw==; 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 1oTAiW-007zky-6M for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:25 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-340862314d9so174971247b3.3 for ; Tue, 30 Aug 2022 16:32: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=dj50MXIaDJBD96/1Gdf430/wXU4xb7a84h2xVZMa0Ew=; b=Qy/xMjE+Z9tI/RI2eW9aQXEE+x9bgipZmkl1TRFX4nG3lQ2Cxw/MGc9YBEMVb79P8x K7ZB6jWVCCidlAiCQ0KHSLobGlEUBTBOYT+IN2cosr4rJjNKEzJDFeo0nWGSZgVhOFnN LnJtK+KQLFx71PgotB16ka4GRRJjpTFnPNLg7HhkuXjEppj+KAqhY9tM//ZHz2AfaJ4E ojP4CyQHCBUPqv0EbNTJy1R5yPCLjtX4xD1E5S+rzObYF7P/nQl/buKNJiO0O+4YpcJO KWS4peUjbZVcIeXOVLV02EwcnTADwVU+JJD9CdooT51s51cyuvBlc8byyEyM9/c9zYEC TUsw== 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=dj50MXIaDJBD96/1Gdf430/wXU4xb7a84h2xVZMa0Ew=; b=czD4OuCxNHZwNo7VS7NJi3Nkj2tgw8bIbZ6Klsh66aJJ9V+4LsWbEFHOcK0gl1d9He 8K2AUYiYmWRPBnsp2ubA1XN6lXI6ijnw0456J2IQ9FGcaM7Abxv49czj4foa/NKZjYf2 OSntSp7zDbT3ZiYscw/5Wc737pziE0PDS6byoIkb/sNkLFrwKvib49ZAzvTipcixU+mL xVkX/teuQOPeWKss9VUAVpt16zwi0QlPnAQmWoBApGSuVcJOaSUv5xQKq9NVZVwk2yWt 3UnWH8UIw+VKlK7DHHaDDHaAREzeMH1My+VOdo8n45188xDv2PrG+3wtBqFVLmLRm+k3 CcqA== X-Gm-Message-State: ACgBeo0fFsuAQvgJqfYA4i05IXBRO3Zv/rzOrUM4VtHrRWgvDykOsdtk 022koYMwJyvf4yeFVhXR7qkgRnymMwRD8WEMS48= X-Google-Smtp-Source: AA6agR5LroJ1DHbPpfH8aFh9/G1HMs3AO252ceiCeo1jPAZmf7JXzZYp5Fa4eHZtuGTExuaU7+SLdODaNccTaYcpsSo= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a05:6902:1206:b0:676:e465:24b1 with SMTP id s6-20020a056902120600b00676e46524b1mr13676826ybu.323.1661902342496; Tue, 30 Aug 2022 16:32:22 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:26 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-19-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=804; i=samitolvanen@google.com; h=from:subject; bh=PQGbduDYSHEunY6Nux9oR4b8gX3kqUUQ66z3bs0DO/k=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3OHJOh3MpkrcMboNL3mLB+U7xNHC0btjo7mME4 CgYIObyJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzgAKCRBMtfaEi7xW7ibxC/ 9u8tiBUAu11iMi2jQxB88ZoyRd3XcPtlmEJ49ZT4ibCRTKCQwU7x7cDMnDG2jMK91BvisB+yihmg9w N/xNoX9Du1hqgmpQ189vSRzZ8B3cTextiO0ei30mC5sYpY4O7ZzhfZ2RUhJ9GhDyhAqAEf/dyh6i7R slJI0p2V7MK2rO8Z0jyvl0g73TadyQ3IuIyhqfnc0JWw795W5qT0rTDncrsYsDg9bHqVA69umBLW/E JBpKqxPr5+1G3RypfC6VZNWayPrVcMVECCxIeWoI8JfgWyBD5zQ2Zeyjo3El1kUNH/J3pinc2ucgj0 nCmZucarH0zhjvQSUJC5X8OSCGQyDJClv+hqBEIWhQ0gvLN9UVnXd5Ql7r49YFrN1kk9AWrqjbQ3Sc AD5ZEd5SjOGYRv3rAgmv+XiFslu7d+xB6EyKfNX1+EmfFdYMhyVFQNijCiaFZSRvXJJ7dnhc8wF96j FE3UOfpxc1eA3nQd4sJS9gasOaTmoIocuonggQXaz5kqM= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 18/21] 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-20220831_003224_421887_4A24C804 X-CRM114-Status: GOOD ( 10.38 ) 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 --- 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 Tue Aug 30 23:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960163 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 9E6B3ECAAD4 for ; Wed, 31 Aug 2022 00:04:47 +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=Rzg0kDcs0osyvER3ON6Z+2wJ3od7t8csTricPEpa5Dw=; b=qqTzB7QR6bFEY9dHriJinQnI2X dI2eXt/8aai8sajJE12fT+h7DADib+KQOyrFxAEo2SNMZQeeDbpnciAjGBi9fhkH2xClvBlAlEgXO vLGIkrqNegaANT2DCcVlXU4XUQe6Q2rbnOCvz4Atd4jXB4eph+sjqqqPaHXeSvifSP4K5H6RrRbGD 7OHYkZL2cbdE16B/cAt1EdnBHlljVJZtBieqZBXOK3mN+kcHVF0fhOtlglTpcSa/b9c5V7cgc/7z/ KJWkgZ4qTDcw/vDfxYGvjtOv5eipwGezwn5+0Rz1Vp6rIjVaA1eRU/N4PTrzxX0oks3K3slzeYmZW rm+X5n1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBCi-002blE-6C; Wed, 31 Aug 2022 00:03:36 +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 1oTBCO-002bel-QZ for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00: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=lxwsXrI3Mz5fmQ5/zOX86abUuUXDGoEtutr5sfPTzdM=; b=bzrAtb5+YKkS1EiWmeMadhEDOb xB0JNikfnZE98+3BoWhLPdBQ5xeFrKo4HLgK+TIHpw7MW4rNorau/cURgK9gjhai4c5PkLF6bh9rX KZubcFQcxdEH9C8gj3ByAuRRuKIkJMaHVPTxJjJU8PAPWU7S4aOi4oSZIXTDMJn91DgumqkRztyko XyXHlPEPH+yQA8zi4egSSmb/r9Gm98rQW7aIai3W+Wn0BhioQiNa7RBJg8nEEfXZwhfkax7svdfDH JOrSWIgROQXw+4Qos5DoqqwEYHDtuEwQHJDSguSSVkVjPAarNRRCzkPli3VdmA0NXZvxV4eC+NM/j mWmMvpbw==; 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 1oTAiZ-007zlF-9N for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:29 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id k126-20020a253d84000000b0068bb342010dso872128yba.1 for ; Tue, 30 Aug 2022 16:32: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=lxwsXrI3Mz5fmQ5/zOX86abUuUXDGoEtutr5sfPTzdM=; b=ICOfaU59KFOn1u8tj+jNF7yA54b5eS6xOe+IMHATV8lUzWB/2X2Z7ndebW8SuDJbZp zZExhr0GX7vlb+myJsY4FJfR80s0uELf0QyRcIe5XQhj9GRlUZuBufvTnZ4HaOz+pmTg vdL2ZN5DasdfM+e3GGko29L8VL3IBBrhWSRT/JGEm5aRqwEo0EICXQTYqdYDldYAvxbY zspss2WPicINxssrlAuMaj3Ax9CPJPHBxNEmMh5eqte/8VwVdXlsUnYo+zxaeu9trZcF 4XfnE3V82BgHAMxrXG3UrzKWzoe8+mEiXwyVd+uAnUcEZPy39B6xZ9xV+vlP87uDR5ke kJIw== 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=lxwsXrI3Mz5fmQ5/zOX86abUuUXDGoEtutr5sfPTzdM=; b=rg6L9cbLiToKALByip2tha+oWwUTsHn94fhrse3WdJoO6wUTpwHQde3kzYTnPrnK07 Asgo09FZ00DSEiWQG1kJj7yb59Y7aQ99De6TLWRCJD38XyVTQloUXh78R+UaPdc85fT2 L/t41XjcPwH/bSNjjQJGvTN/V7Gj9ni14o1W3/hWzvTwJRy5iL5ImrPxgC5d4EN4NSl0 2CxQQOKgvF/TIsU313Jh4VNMDWKuDmMTK8r0S7tNJXeXAEeA3VKDrhxxCi0jVYqi2gy4 7Hl4MhHWiuW0YnLrTtDxaiezLSRP0uA2QjyP+jc4P0FtRuH0vR139ONtL5IwDMOwEu3g I6vQ== X-Gm-Message-State: ACgBeo3TwetZUqVby1UhwtYkC2/35eYFAkeE8VI8rw66yiQvom6Mvuvl A0hIGm0P7L9T+Y3WlJZMwtAjldtza7YkcqoGE0I= X-Google-Smtp-Source: AA6agR4fE6Gg8awQx2KS9WtJeU46JESb48vItR61XAln2KMXiSf46hjOiUeXjrEcWkyckSPoadljKPgTp5O6PLcizdU= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:5986:0:b0:694:f850:223f with SMTP id n128-20020a255986000000b00694f850223fmr13658199ybb.491.1661902345267; Tue, 30 Aug 2022 16:32:25 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:27 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-20-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=1934; i=samitolvanen@google.com; h=from:subject; bh=j+dRbdVg7Q78Lk00de2uzEaCRhsdMEDN+wU7yhAtB6I=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3PCTTAdV8Hk1XXJcZvSvg5+O6k1Ozq2feAV3JZ bXDWub2JAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzwAKCRBMtfaEi7xW7uJqC/ 9g0WEa/wq7GPSj/jsZkwP+eo20vbuIdBILQjyKx6g3zSYpJxIRdSTMe/Ft9rn+C6apdUFx310uNdbM 629LRshuNEW20b98k/SIj+1wQBpmaF3JtY0zXTo91YeKUtGNRxbQqIDLdHbnE8iyAM3byp4uwuIQXi 62aPeT8h8d1R6FQXR/WCSNJ6FoyOhql2RVeaYgoEmWccYItjnIVyldJJ3ahwyvu+RHqZzqz5Jm4uW3 Gq8MD/T/GZ5ZLuipErCj1iOaif8sJ1q2jjAQbsvNRcYvv6V600Vz9ABIcvr24nYx5sk2i/u7A6KU9/ gvrGM0vh9P1e1gyTjGQF2puMGcf1PHLlUosOGkL7cslheQRw6lVU5hdOW8NKEBpfjpYUSY+41+V6zZ 7ph644d9uMXOQS8kUtyAtiegxWqdCYYCY4EDa/ooM/v+1or9C+V8CFquTZnOFKmbfjbRYgc9b8iUp7 lfdI5ThNkCnogOoZJn6A5Br9rWg1myT1DLEMipq1Dxs4k= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 19/21] 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-20220831_003227_424135_F839355F X-CRM114-Status: GOOD ( 11.46 ) 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. Add types to indirectly called functions. Signed-off-by: Sami Tolvanen Reviewed-by: Kees Cook --- arch/x86/crypto/blowfish-x86_64-asm_64.S | 5 +++-- arch/x86/lib/memcpy_64.S | 3 ++- 2 files changed, 5 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/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S index d0d7b9bc6cad..e5d9b299577f 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, memcpy) ALTERNATIVE_2 "jmp memcpy_orig", "", X86_FEATURE_REP_GOOD, \ "jmp memcpy_erms", X86_FEATURE_ERMS From patchwork Tue Aug 30 23:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960162 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 C04FAECAAD5 for ; Wed, 31 Aug 2022 00:04:34 +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=WV8wwekA57Rxhdsk2z2muPkDCeSnoLWoRpm17oGTozU=; b=Ah+9gDjrZsjFU/amJ3LjwYaIYM lyhpoLudm1MsZdZUQxL4g4cn/Aa5BxQt1JCHEKU4iTqSB/u1xtTQ+Fvp9G2/PlHqPStD5Sga/hfNG SG98A8vNTzWGIaDYRzgZzSwJORUpoWZNx0HWfA3cndi0CvWqr1M1Mi2BMZigFW/xb0KFHXgAdqWhC pEd/+vqq37Q8aYmlje9++xTiyMzAqps8Bjqby6kB1xeeXTjTqyOv4cLrII8iR5Has3ovBnwpYJM4u dN0KTBv27dJ1cXqV3hHlk1QZpRovyQjieagpePmudXCppZmbVgP9iYEBYJn5f6JWBLfdR2MtOg5ar HfcnQa5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTBCX-002biA-VP; Wed, 31 Aug 2022 00: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 1oTBCN-002bel-US for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Aug 2022 00: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=JGJThSQrG14h993s8rjwM8jNb3CuBSnZl7zjhnevu+g=; b=CnV3lkBTUfdjHQsmtR26ds0aqE eXELVkutrroRvl/Ae2uup5u/37ZGMAJB9LVbSL06+aVxyINdb2VGovzFUCCnL3Xkzj6fi8STRdCES UpILhCAzV85PNDqNalZiRkMkhpE0Gl/t3sJ6qy4biz+2zn1hZQ3sbG2LnAteLuA0WlmPpVsm5+j+X cBO2l/veyRJmIklXqfbaHELsb5LpmvaL0d0pUVjwT8DflYwbjPlmPzIPAlnUCysYqZSPpsiGDIhFs sqtWxs4jD6irmzym5FZ1wnPt5PtktGVQzeIpvCLThjoQ8XNH+IPa2u5MPnPry8fkq8kOyX+oKXsOS ZxGgRYkQ==; 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 1oTAib-007zlY-Qe for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:31 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-340ae84fb7dso158362887b3.17 for ; Tue, 30 Aug 2022 16:32:29 -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=JGJThSQrG14h993s8rjwM8jNb3CuBSnZl7zjhnevu+g=; b=DOh9amPi8sdlIOf+BiQAcIL4C8dBW/B9BWrb3DDZwGjZRuBGPkwG8kg8wpUGEynqN4 HbwlJ211/vN250153b8eTEEz+hJGiHPIdyx8Zz5WSB/eRxv4x+R8c6xaiPurZnqHBUe3 7eUibXAR1rL0QJGQFURQEgHMRLr+JSZOLcNBOIXbJOXcNuGf4he8R/RcghJuPZwG87Gp L+pDTBkMbM7mIefPA4Unu/iXF4eeVd9tDHBc5q6aRSwecfYH2copC/6dCggsaXuVuvUw fzuv78FCYDYsach0a90W8IsCcCNCzrOKyw5GIQzwfi8hwWvxOfgq6EoJfTjPWYbOy/X8 OGkQ== 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=JGJThSQrG14h993s8rjwM8jNb3CuBSnZl7zjhnevu+g=; b=ZC3bJGswYExykiE7MbISiLPHPWKcfJf/CA3KCy7iF4Y9IdU4HFu9OrenIySQ4mVie7 mKrRZiVU/tdtARJbWRcgxkpA4JksmG+sxAEenSz7Du/EiJsc+eF/AV8cgCeJz33AGYY7 y2DdNUxreRFPAxaV7RqqQe0TfDW+6kJxxSYW3eSDKtFs7X905Iy5twrM0wBBQIlqmgol OvBfXbmyo0b6/lSOBYtVmJamGNYCtwyn95QtL0/ltGRUYASbgsDOThVBAFMidz4+wb9x pGtzDtwZrNT2pKhUsoKdBe6hbdD7Xd1QcRUkH9yzThgCuDXWwH2ulyo6kpBKTqPuFJ+R P4/Q== X-Gm-Message-State: ACgBeo0mGzqRxaSLhTqJK8PpSRvSqqhU6Vs1IRNnvIEFHeQjVXMXm4bO W80PGUDlwqFesusm0eB4ulMn8+puNWvGYm6E/6s= X-Google-Smtp-Source: AA6agR4PyO0IKBEZVO/AvffiR0akECN3URvghZTslxK3C371SGy+urp8y7XT0ytOb7JDjFdBCeYbfFF5vHW2XgdhiqQ= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a81:d34a:0:b0:31f:4467:4ae0 with SMTP id d10-20020a81d34a000000b0031f44674ae0mr15725365ywl.477.1661902348134; Tue, 30 Aug 2022 16:32:28 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:28 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-21-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=915; i=samitolvanen@google.com; h=from:subject; bh=m63Aw2OCZubNDlnS2Bm9+IxQqtHz35eVVBHmUgLi/wI=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3PBebzwTJ+52Sw6ogCU/KIG0JsWDvzXb2RlSP7 p3Tx7bKJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzwAKCRBMtfaEi7xW7gtjC/ 46Gj3n4xq2s5nOkzOlhRg6U2y6bfUnt9ieyOLUS5LwZTt+4P1YtZ1bAy7fXQjlY5N5Jru8Wxiou2NQ XkZHG3/eLGFq67shCldfkkdKJuw3zTrocl0l0U3bI95JISYisD70CC/v6rHsGqKjP/uSRXNRP30aAm 8suLZ5bim00kqnPRf6F4sy1mk6/W6hXGgUi6oz2niBNwvb3cYpY3LEd4WZl8pIbELZtdYdrW7jGWrG jGzA1gDMc6M1m0iQyrWFLfMS8Z/Ox52XdhaR+isbHp7AtJxqO0qbN9Fh/L6E3lJiJiGcQgwAhgGfYw OElKjGI/zYiSnKS1XqBhHYQ44Sy0ZrW3vzzzSSERj0TNDSVk87P9KWRlJ2zsEDrD4S3t8So/m9NEcP 4nl6pCyebjHvO7PMvnuJ5Ds/WxR8rqm5SuxbPGbmdyvl6F+LZ7o+EKzgevJrNFIW3c7+8RRcbkr+OL PaYZxJCu03C4/PK10hnG4Dww9r1ervjssX1vNaeEtQoUw= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 20/21] 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-20220831_003230_006417_E827648B X-CRM114-Status: UNSURE ( 9.57 ) 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 --- 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 Tue Aug 30 23:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sami Tolvanen X-Patchwork-Id: 12960142 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 47EFBECAAD4 for ; Tue, 30 Aug 2022 23:36:04 +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=1PXfcD+TyKWDAQqaMQRl0aF6Z7T/fVuQgDtYKoCoLZo=; b=cdq0IdSyiNN+8MuLuYUaolgu7M DPf0T1lPIFiONgbPkJgM/GaCD5r/L3lNN5rXkUozXFhJOIuGMr+QOpYj5BYW4S8kjS0mZpKqEdONw ZEnD+JoAflpcv2F0kb7LAPehFOX9VDMtvtAmAyaw84u5+8bnV/xq2Za7OyrB1buZFBOxBCbbyz23X g1dE4nJZB3RNa/LyjFU9WuVlG3ynl24bnB9ITgOJ2/z2VX0Y30cJ4qTwNHxYEZC2OXo8hMxJwLcfl 4Cr7bLsp1p7egziWn5KGJEI9X+mzqKSc8fg6gQ8vfjrGXIYEyZoFk7Gn9fzLSNhgIJujCGtQZXIQV 9322lb/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTAkm-002UPT-LZ; Tue, 30 Aug 2022 23:34: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 1oTAie-002T1U-HQ for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2022 23:32:34 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id f12-20020a25b6cc000000b0069a9e36de26so876564ybm.16 for ; Tue, 30 Aug 2022 16:32:31 -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=muitaXVvYj1YXYeJfyrYZvippOQN3ekQHC+LkfXxbLc=; b=qZpclqQ6MsBQZUyMbRHl5nEFHLKVNuncCaq+7Pxg2KT6XNS9xA08pBlGHG3JYut1v1 TRvpdM8IY5fuCJoqsdbv+sWXvtCe0pTC8mj6QL8JS54ZIaAga8BWb6ikSMZwyF8wo1Mp 1IzskPITy3h8+PbYnC19RDCtSEjS9+naLaqxPL38hvyOcW+Wjjnkp5Vu6l4DRpZa2MVw /qLkeHfR5fxAiGbQ3ASQz7tXDU/Ojm5437GZxvJMzZGw2uZgFS6bO7kXNuCOzB8SUj8u ve7L7kOPTIzBNV8TWMg8uLMQMD4aJ+E2OFqj7Rzu0cUj+dVwgYL7lld5b1V4BmU78331 S9yg== 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=muitaXVvYj1YXYeJfyrYZvippOQN3ekQHC+LkfXxbLc=; b=7FWjyDmivPFtZKaD9R9E8QmzYUWjN+mYHes5A4rWBlVzN/Y874Ix2bK8JOysaIDI9s b/cpkrd0UeTsANPoXbVZe+Xm+OS45O2MuClpjz9JCg8QiVaIslVpCPsuTqxvTaX9HDSb pQRuOWmMXmBsGZqyEQ06gpSlheRAokUQMaTrOpC2gA1KqJAqEA0OAaZUW8pKd2mYj1d4 hPj+7ypo8rdumZbarlq0P4X9aHHBhtFphCotibYwNQ0EGuu5mzfSRMqQjBd4eH/MRlm7 qBA74l2inWgpS+X9vYjbPPIhI66Dxu6cdl1tnyKtwrvrYDCe5FViompLbNweRZsFOtjO h+Uw== X-Gm-Message-State: ACgBeo0POC4LkMnbRe14D/CJ1lbzPM7qk+jLJaS7ILyPlgEpgVRkKzAd MCnbU+DS/JzFDTvOY7csNz5s0KiH6duxGZ8t4wA= X-Google-Smtp-Source: AA6agR5mmw1lyTMjEbXO+bj0XMfoKQXjrA7x+3+LfFFUJRrRakcxIdBjBJC8pQKjP8yP5Cacc+4B59TMcKFo3CTBMQ8= X-Received: from samitolvanen1.mtv.corp.google.com ([2620:15c:201:2:54d9:7143:6a7d:91d]) (user=samitolvanen job=sendgmr) by 2002:a25:2c8:0:b0:695:feaa:871f with SMTP id 191-20020a2502c8000000b00695feaa871fmr14222519ybc.471.1661902350818; Tue, 30 Aug 2022 16:32:30 -0700 (PDT) Date: Tue, 30 Aug 2022 16:31:29 -0700 In-Reply-To: <20220830233129.30610-1-samitolvanen@google.com> Message-Id: <20220830233129.30610-22-samitolvanen@google.com> Mime-Version: 1.0 References: <20220830233129.30610-1-samitolvanen@google.com> X-Developer-Key: i=samitolvanen@google.com; a=openpgp; fpr=35CCFB63B283D6D3AEB783944CB5F6848BBC56EE X-Developer-Signature: v=1; a=openpgp-sha256; l=10374; i=samitolvanen@google.com; h=from:subject; bh=xx8wjcYE8Du0racyo2HoO5M6w+PYgPKqDWnfLGl3DjU=; b=owEB7QES/pANAwAKAUy19oSLvFbuAcsmYgBjDp3PPFzSBxPnL1McANFd1sNHrlLrdWSxt2cbevI6 OTWO0UqJAbMEAAEKAB0WIQQ1zPtjsoPW0663g5RMtfaEi7xW7gUCYw6dzwAKCRBMtfaEi7xW7uukC/ 9uM+7HvXyQ67VflXgAsC/YncRdBoq4yhl8rYfT2i05OWqPjoWHJG8Ya/UI5iY6oAeiaG49tfhTVdrJ pUyR3viQo7OIVPeVuzfeHP0eguun9EReYSQcKQGYAV4XfwQ4hFEKT254SvMUfU/M/3EWaS7HN4mNz4 QJK4XkW4SPhA7RBnDLN3EQJPwljXDQ7+t5wNksrguQOfmbffYUJPcP/HC8oNr1lIRstWm3BrwbIJaD MAsUDvpax1bIHiYl6DHoiFijKWm88sHuPFQFFnxGE0U4g/pm+dzy+wirAFnCNNK/RGdmP3fdBqzLSI Ul3ndBsIwZACrYvIZ37KXR82etUCnuTGSvqwWPAnY4rizeCV8SEBvqmVV2EWIAClYLSj6ICZQJRyeX rzdvbADWzQdLSvLP7rGWgi5MQSYwwYbc15tpgtuhFe0HwpsWbo8jxfrJUVzM4T5CXHBy3OqY/UZZrp 0/EHk1+pMYKAO0vzlUhH3g28B4J9GI5syiuW13VGIgv/E= X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Subject: [PATCH v4 21/21] 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-20220830_163232_670272_E5A6790D X-CRM114-Status: GOOD ( 28.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 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 Define the __CFI_TYPE helper macro for manually annotating indirectly called assembly function with the identical premable, add error handling code for the ud2 traps emitted for indirect call 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 --- arch/x86/Kconfig | 2 + arch/x86/include/asm/cfi.h | 22 +++++++++ arch/x86/include/asm/linkage.h | 9 ++++ arch/x86/kernel/Makefile | 2 + arch/x86/kernel/cfi.c | 85 ++++++++++++++++++++++++++++++++++ arch/x86/kernel/traps.c | 4 +- 6 files changed, 123 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/include/asm/linkage.h b/arch/x86/include/asm/linkage.h index 73ca20049835..ebfa05973312 100644 --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -29,6 +29,15 @@ #endif #endif /* CONFIG_RETPOLINE */ +#ifdef CONFIG_CFI_CLANG +#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) +#endif + #else /* __ASSEMBLY__ */ #if defined(CONFIG_RETHUNK) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) 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..e642c1af2678 --- /dev/null +++ b/arch/x86/kernel/cfi.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Clang Control Flow Integrity (CFI) support. + * + * Copyright (C) 2022 Google LLC + */ +#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; }