Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1151187pxb; Fri, 21 Jan 2022 10:57:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0DniOhLSagIriZqeeebO+qp7x3WhQ18tcLovkf67G0yVC4GtfrzZSCBJa2aG1F0krlb1N X-Received: by 2002:a17:90a:fe05:: with SMTP id ck5mr2052840pjb.21.1642791439060; Fri, 21 Jan 2022 10:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642791439; cv=none; d=google.com; s=arc-20160816; b=xUo1gI1IUcQNlvWEsNrBaYPc8ma654seZtCjbHskH2YLLcWsKvVEH8+d+yQtVcNwoB sNXNUkfFeE4nxTHmL9o6gy5f9dwY0cno02YIFnCxFNFae9ucnwrU/B/ToT2FhdTcncGO 4ol8o8ffVmoSXCZMGuxSUntq/V1GDb77IO4Ca6CFfqs84p3I0Y6DZGj8lhkiw7+ayvPu S58G/O+FfNgSp52lPPuPephlxOzEdjyFFUSmLWnO/pJrEEgvwIs2XQFz6an52ZoQACa9 AG0dKoPIS20igoSDZGBXOxSOathnIWq9iL3cer26eaxNdLT+eWQx++2pC+ZSQPoRiezD O4IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=MT5dlCEvCn9wxDf6djimLnP8MG3ZcgBe2BiIL4kCQt0=; b=gzi6WvpWPatP/KPrcSgyZpv2nMnxCR+Nz48IB3/H8/Xfk2rS9Sq4RKhjcHL1q+FwjN izu5OW8JuVeD7xOPEasyx46JgfuJ6awm2xwitBAJOWAsWpO3Bn8cpn044IVQHXohm/MQ VPQstr7p8aBt1IagJ0nCvksmRS7cjP6XIMgevL16uCfNHEia7kKMiB1ggCDAUA/TmMIr O4W4cizN35NLNsbM4G065w9qUvbTbdPia1yVO/yYaHCGzlHsiy069ct6744zmxMH86Rh RYSCJSrh6UhphWBhJzzmxx2r2MYOCYcoBUdA/qvs7SR7Z53xVZ132bS0I5sa58vTd9jD lk+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si7853691plg.225.2022.01.21.10.57.07; Fri, 21 Jan 2022 10:57:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352287AbiASIYx (ORCPT + 99 others); Wed, 19 Jan 2022 03:24:53 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:40938 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1348529AbiASIYw (ORCPT ); Wed, 19 Jan 2022 03:24:52 -0500 X-UUID: 97f9c6ab74ca4abdbe273660cd85ffeb-20220119 X-UUID: 97f9c6ab74ca4abdbe273660cd85ffeb-20220119 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 645517797; Wed, 19 Jan 2022 16:24:48 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 19 Jan 2022 16:24:47 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 19 Jan 2022 16:24:47 +0800 From: To: Herbert Xu , "David S. Miller" , Matthias Brugger , "Jason A. Donenfeld" , Greg Kroah-Hartman , Ard Biesheuvel CC: Miles Chen , , , , Subject: [PATCH] lib/crypto: blake2s: fix a CFI failure Date: Wed, 19 Jan 2022 16:24:46 +0800 Message-ID: <20220119082447.1675-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miles Chen With CONFIG_CFI_CLANG=y, we observe a CFI failure of blake2s_compress_generic. Reverting commit 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in") is a solution for this problem. So I looked into the patch and I think it is caused by the weak symbols use by blake2s_compress(). To fix it, remove the weak symbol and use CRYPTO_ARCH_HAVE_LIB_BLAKE2S to select blake2s_compress_arch/blake2s_compress_generic. log: [ 0.000000][ T0] Kernel panic - not syncing: CFI failure (target: blake2s_compress_generic+0x0/0x1444) [ 0.000000][ T0] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.16.0-mainline-06981-g076c855b846e #1 [ 0.000000][ T0] Hardware name: MT6873 (DT) [ 0.000000][ T0] Call trace: [ 0.000000][ T0] dump_backtrace+0xfc/0x1dc [ 0.000000][ T0] dump_stack_lvl+0xa8/0x11c [ 0.000000][ T0] panic+0x194/0x464 [ 0.000000][ T0] __cfi_check_fail+0x54/0x58 [ 0.000000][ T0] __cfi_slowpath_diag+0x354/0x4b0 [ 0.000000][ T0] blake2s_update+0x14c/0x178 [ 0.000000][ T0] _extract_entropy+0xf4/0x29c [ 0.000000][ T0] crng_initialize_primary+0x24/0x94 [ 0.000000][ T0] rand_initialize+0x2c/0x6c [ 0.000000][ T0] start_kernel+0x2f8/0x65c [ 0.000000][ T0] __primary_switched+0xc4/0x7be4 [ 0.000000][ T0] Rebooting in 5 seconds.. Fixes: 6048fdcc5f26 ("lib/crypto: blake2s: include as built-in") Signed-off-by: Miles Chen --- lib/crypto/blake2s-generic.c | 3 +-- lib/crypto/blake2s.c | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/crypto/blake2s-generic.c b/lib/crypto/blake2s-generic.c index 75ccb3e633e6..22fa3ea1689e 100644 --- a/lib/crypto/blake2s-generic.c +++ b/lib/crypto/blake2s-generic.c @@ -38,8 +38,7 @@ static inline void blake2s_increment_counter(struct blake2s_state *state, } void blake2s_compress(struct blake2s_state *state, const u8 *block, - size_t nblocks, const u32 inc) - __weak __alias(blake2s_compress_generic); + size_t nblocks, const u32 inc); void blake2s_compress_generic(struct blake2s_state *state, const u8 *block, size_t nblocks, const u32 inc) diff --git a/lib/crypto/blake2s.c b/lib/crypto/blake2s.c index 93f2ae051370..4055aa593ec4 100644 --- a/lib/crypto/blake2s.c +++ b/lib/crypto/blake2s.c @@ -16,6 +16,12 @@ #include #include +#if IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_BLAKE2S) +# define blake2s_compress blake2s_compress_arch +#else +# define blake2s_compress blake2s_compress_generic +#endif + void blake2s_update(struct blake2s_state *state, const u8 *in, size_t inlen) { __blake2s_update(state, in, inlen, blake2s_compress); -- 2.18.0