From nobody Tue Dec 16 16:42:52 2025 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 72D47C4167B for ; Thu, 30 Nov 2023 09:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235022AbjK3JKF (ORCPT ); Thu, 30 Nov 2023 04:10:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235021AbjK3JKA (ORCPT ); Thu, 30 Nov 2023 04:10:00 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FAA2CF for ; Thu, 30 Nov 2023 01:10:05 -0800 (PST) X-UUID: 2c41c7b4e5774b4c84f640875592c287-20231130 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.33,REQID:e373a74b-0303-4c22-9e09-85df47617312,IP:15, URL:0,TC:0,Content:-5,EDM:-30,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,A CTION:release,TS:-35 X-CID-INFO: VERSION:1.1.33,REQID:e373a74b-0303-4c22-9e09-85df47617312,IP:15,UR L:0,TC:0,Content:-5,EDM:-30,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-35 X-CID-META: VersionHash:364b77b,CLOUDID:7add3f73-1bd3-4f48-b671-ada88705968c,B ulkID:231130171000FC9RP4MN,BulkQuantity:0,Recheck:0,SF:44|66|38|24|17|19|1 02,TC:nil,Content:0,EDM:2,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL :0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: 2c41c7b4e5774b4c84f640875592c287-20231130 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.169)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 329326506; Thu, 30 Nov 2023 17:09:57 +0800 From: Kunwu Chan To: mpe@ellerman.id.au, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: kunwu.chan@hotmail.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH v2] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add Date: Thu, 30 Nov 2023 17:09:53 +0800 Message-Id: <20231130090953.2322490-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Suggested-by: Christophe Leroy Suggested-by: Michael Ellerman Signed-off-by: Kunwu Chan --- v2: Use "panic" instead of "return" --- arch/powerpc/mm/init-common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c index 119ef491f797..9788950b33f5 100644 --- a/arch/powerpc/mm/init-common.c +++ b/arch/powerpc/mm/init-common.c @@ -139,6 +139,8 @@ void pgtable_cache_add(unsigned int shift) =20 align =3D max_t(unsigned long, align, minalign); name =3D kasprintf(GFP_KERNEL, "pgtable-2^%d", shift); + if (!name) + panic("Failed to allocate memory for order %d", shift); new =3D kmem_cache_create(name, table_size, align, 0, ctor(shift)); if (!new) panic("Could not allocate pgtable cache for order %d", shift); --=20 2.34.1