From nobody Sat Sep 21 23:29:29 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 951E1C433EF for ; Thu, 30 Jun 2022 09:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234505AbiF3JrQ (ORCPT ); Thu, 30 Jun 2022 05:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234503AbiF3JrN (ORCPT ); Thu, 30 Jun 2022 05:47:13 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98E7942EE1 for ; Thu, 30 Jun 2022 02:47:11 -0700 (PDT) X-UUID: 63e02b56a5f448f2bc6664e7bc080df7-20220630 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.7,REQID:5aa947b7-da57-4ea7-b869-05581f124e91,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:87442a2,CLOUDID:73c53086-57f0-47ca-ba27-fe8c57fbf305,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: 63e02b56a5f448f2bc6664e7bc080df7-20220630 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1331765317; Thu, 30 Jun 2022 17:47:05 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Thu, 30 Jun 2022 17:47:03 +0800 Received: from mszsdtcf10.gcn.mediatek.inc (10.16.4.60) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Thu, 30 Jun 2022 17:47:03 +0800 From: Haibo Li To: Sami Tolvanen CC: , Kees Cook , "Nathan Chancellor" , Nick Desaulniers , Matthias Brugger , Peter Zijlstra , Masami Hiramatsu , "Christophe Leroy" , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Luis Chamberlain , Juergen Gross , Haibo Li , Tiezhu Yang , Aaron Tomlin , Dmitry Torokhov , , , , , Lecopzer Chen Subject: [PATCH 1/2] ANDROID: cfi: enable sanitize for cfi.c Date: Thu, 30 Jun 2022 17:46:45 +0800 Message-ID: <20220630094646.91837-2-haibo.li@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220630094646.91837-1-haibo.li@mediatek.com> References: <20220630094646.91837-1-haibo.li@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" currenly,cfi.c is excluded from cfi sanitize because of cfi handler. The side effect is that we can not transfer function pointer to other files which enable cfi sanitize. Enable cfi sanitize for cfi.c and bypass cfi check for __cfi_slowpath_diag Signed-off-by: Haibo Li Signed-off-by: Lecopzer Chen --- kernel/Makefile | 3 --- kernel/cfi.c | 8 +++++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index a7e1f49ab2b3..a997bef1a200 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -40,9 +40,6 @@ KCSAN_SANITIZE_kcov.o :=3D n UBSAN_SANITIZE_kcov.o :=3D n CFLAGS_kcov.o :=3D $(call cc-option, -fno-conserve-stack) -fno-stack-prote= ctor =20 -# Don't instrument error handlers -CFLAGS_REMOVE_cfi.o :=3D $(CC_FLAGS_CFI) - obj-y +=3D sched/ obj-y +=3D locking/ obj-y +=3D power/ diff --git a/kernel/cfi.c b/kernel/cfi.c index 08102d19ec15..456771c8e454 100644 --- a/kernel/cfi.c +++ b/kernel/cfi.c @@ -311,7 +311,7 @@ static inline cfi_check_fn find_check_fn(unsigned long = ptr) return fn; } =20 -void __cfi_slowpath_diag(uint64_t id, void *ptr, void *diag) +static inline void __nocfi _run_cfi_check(u64 id, void *ptr, void *diag) { cfi_check_fn fn =3D find_check_fn((unsigned long)ptr); =20 @@ -320,6 +320,12 @@ void __cfi_slowpath_diag(uint64_t id, void *ptr, void = *diag) else /* Don't allow unchecked modules */ handle_cfi_failure(ptr); } + +void __cfi_slowpath_diag(u64 id, void *ptr, void *diag) +{ + /*run cfi check without cfi sanitize to avoid calling cfi handler recursi= vely*/ + _run_cfi_check(id, ptr, diag); +} EXPORT_SYMBOL(__cfi_slowpath_diag); =20 #else /* !CONFIG_MODULES */ --=20 2.25.1