Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp167333rdb; Thu, 30 Nov 2023 01:10:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IH16jlLOdBYK504F925arp5PCLfqwILTWgQ7IJuQlo/N2BX8Y1w98h2nLUAUrb4zsg9Toyh X-Received: by 2002:a17:902:b718:b0:1cc:7d96:3fe7 with SMTP id d24-20020a170902b71800b001cc7d963fe7mr17316085pls.28.1701335455694; Thu, 30 Nov 2023 01:10:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701335455; cv=none; d=google.com; s=arc-20160816; b=Ghn5st7PZ3PXzWxrMRS2YjLdUoLMotAMxMTmS7uBFFjikGiRp6AM0D/PcIlQiAo3um WT0JO6Yx135fd9KXoOgecEAHxz4sWfb49bLnaP2LQJ8mlGgFOZVBtLkTLGdMUlUtiPUp wFqplhhnWLFKkgSNhCYm5BoFatFEQrICYAMP+2HrCDkciuKfjApy9dXDIb4HfJ8ygS8m aNfQK8pzpkaKbVNRH8b+p05zpy8zkwGEfEteLtjIaNUyvgERUMppNe7dG+hMa0BW/uIg okhlFB5psNaP6f4va5ofOYUjCCh9XZk0TLKVPbW0ZKYOUBn9+STdUUtNExwMIbuzEUEB xSKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=27CBidLadJGfcDzk6h8QeajlUadZY1ivrcvZ+YoHFBU=; fh=sHo8oDwe+4NHLXehdlywLkCgMxpHE/R8p1xH1E6GvBc=; b=cNW0OWuLbC6m4ewD2EQ6jUlp+iul9o25Ah2B0Pja+k2mR+xcmrwepN7upA/iCMKc8H wzjCht7+irqQuQb4XmSyNZq7GyYK1FWR0jFjvUIAStPj6tP6nbcsvL4WTAArAscQQItm avBSpgXtXFkgSTsh0x/ujq7j/gJdUOPLuOE5eEuBKLoeL5Qtf+iTBKYPoSoC+FmUGeC9 e1VoHADRO1DMJqHATKqwT6H+2Ifvdy/rukZNgawsFNmGhN9SiUe80NjDN5n+4PjjWCt3 FExe7p6PKKQ2WDUHEy1Xz+tKuQ8+9rL+nJ92uJZglVrnsFHoOwT2sDTDcm2hCdbc9zT5 UxOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id q12-20020a170902dacc00b001cfee4c1281si854237plx.355.2023.11.30.01.10.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 01:10:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 45A0B822E544; Thu, 30 Nov 2023 01:10:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235005AbjK3JKE (ORCPT + 99 others); Thu, 30 Nov 2023 04:10:04 -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: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 30 Nov 2023 01:10:20 -0800 (PST) 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) align = max_t(unsigned long, align, minalign); name = kasprintf(GFP_KERNEL, "pgtable-2^%d", shift); + if (!name) + panic("Failed to allocate memory for order %d", shift); new = kmem_cache_create(name, table_size, align, 0, ctor(shift)); if (!new) panic("Could not allocate pgtable cache for order %d", shift); -- 2.34.1