Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp951401rdf; Wed, 22 Nov 2023 01:06:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzKNIKU8B2tpbxo5hIKPfpvoYxvp1+OHTHAxudZv5KRztnqfahk/hFO9WJtNoi+GSyjf9b X-Received: by 2002:a05:6808:1a09:b0:3b8:412a:e75b with SMTP id bk9-20020a0568081a0900b003b8412ae75bmr550606oib.10.1700643976495; Wed, 22 Nov 2023 01:06:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700643976; cv=none; d=google.com; s=arc-20160816; b=OasOslG/CQkMNYhduj4X0cxtInt0emBygDHhv4kQTn8yV2sYP+GRytqAJwn8SUWvvo ZAe8UsrasGMDn9bVcuocW7bv2q+K3FHsnBFFepKU1PLZpSD9QsAIUAsQUjc9BHJbA91c fk4ZTkCjYfpMXURVY2YOmf8wnUkhJ+aMhpUJvDy1m0TCymyG3As4fk2hTi47xc0UGmfB SBVO7xOwcTECVccJC2HzcpUkFSzh4C+XN8xBrUVA18ocRXlUCIO/cmSGl+xRYJszwsQh sxdJihwp5fRrG4rPm9mirHD455vk5T2yts2TkmcrZGjDSPrORp1wMBLiJCs4BmoqwvUp LD2A== 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=YuLtRutP4ZhL0dgS+qPATojnlHp5IpnnbiiEbe3O1lQ=; fh=sHo8oDwe+4NHLXehdlywLkCgMxpHE/R8p1xH1E6GvBc=; b=Fzo45Q6ZS7xFNccusKFkcN3AlgNt8ddVlloZy3nOm7wpcJ94ZU0w+1SiSmqdJkAnSV 9CZsG4isYH03XLZpku6L5fFui4KtZPDIJjLZUJPZR59MVh1L3N9YPmRipbE4HBN+Lad6 Zgqi6rYYveSiwSHcZ8TSsjDEB4Se76duekxv0ZSUWsz1UaAc1GG0+ggOvgQyWM/PpoIl VLo9LpP9K0LgHQFxAIn3Bird/HXHMbHBoeURCB8dmV8Q4mLQaNUFAABJJYXS83/AM7cm ewFnNQOacipn/Jbg9IVJzoUIkHcRaYYXg/4It4f7Uf218Ufcg/MusE99vAYyiulu+/O5 /Hgw== 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:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ck17-20020a056a02091100b005be31178051si12900067pgb.281.2023.11.22.01.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 01:06:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 7E09480941E2; Wed, 22 Nov 2023 01:01:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235066AbjKVJAv (ORCPT + 99 others); Wed, 22 Nov 2023 04:00:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235008AbjKVJAt (ORCPT ); Wed, 22 Nov 2023 04:00:49 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D1F0BC for ; Wed, 22 Nov 2023 01:00:43 -0800 (PST) X-UUID: 0f1fd2d019e44d1bad0c33f66457bf12-20231122 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:41be7148-6f9a-4034-96b3-d81abd902688,IP:10, URL:0,TC:0,Content:-5,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,AC TION:release,TS:15 X-CID-INFO: VERSION:1.1.32,REQID:41be7148-6f9a-4034-96b3-d81abd902688,IP:10,UR L:0,TC:0,Content:-5,EDM:25,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:15 X-CID-META: VersionHash:5f78ec9,CLOUDID:6bbdae95-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:23112217003121VE4392,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:5,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_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI,TF_CID_SPAM_SNR X-UUID: 0f1fd2d019e44d1bad0c33f66457bf12-20231122 X-User: chentao@kylinos.cn Received: from vt.. [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1086186215; Wed, 22 Nov 2023 17:00:29 +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] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add Date: Wed, 22 Nov 2023 17:00:26 +0800 Message-Id: <20231122090026.11728-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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 22 Nov 2023 01:01:06 -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. Signed-off-by: Kunwu Chan --- 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..0884fc601c46 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) + return; 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