Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3771235rdh; Tue, 28 Nov 2023 03:32:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2nEbnXDOEd2yXmdMpRPjmAzHkUc8d7OMxGR0KDyhmgiH7ghA/1TtWOemzqBq8on+jAqHn X-Received: by 2002:a05:6a20:12cb:b0:18a:e121:9df4 with SMTP id v11-20020a056a2012cb00b0018ae1219df4mr13235142pzg.44.1701171172002; Tue, 28 Nov 2023 03:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701171171; cv=none; d=google.com; s=arc-20160816; b=uA5hGAXlq7xY14jnq4br8OXEkXq7QwgGbtxSDkl6y8q0P2cJx45uIZQau3ZuIA2uz7 GPe/R4t+u/QdKDUNw4dOARjEHv8epKpAefLvemTWF6Db/p9JtJVk9TGVHeGv41WdPowS YwbNfJL2XTxSgK6khvHzsb8NNJQuT5vSNhvlek/NNDUma3NfnnJyJI3QCg345lrSXclo RaWIj1XMnTNOz9TrOLgqkNbnH8Q9FZuIbqTCLa0dYp8e7oBt2tHleSjxU9Iqe5oAP17o 78eHvme54k9n+AhLuVpMG6t0vnQV63i1QIwPvdAT2SPSixenzJhZK2fhYrRWHlyxdfgH EkUg== 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:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=RFVMPhKHsjpTRlZPbuzuBAOCwyfifnJ1d4FpP1154EU=; fh=4c4k8XsjJmp3NLQHUhfJcuHHJpwgdISPUuHsOOs+OD8=; b=rv+iHosWpXg64ttYYgJs1OFsGZLUNmmzdBZp6R4ShLp8dk64zVzU1/AaJzP7A/XsFo 5+iGqxgl6X3K9/XKnjRXNzrtDYwtXH9BGQ0bUKlhZnUSlFAJUM0hmA2oPyIGaQoPiHUI 7q01tCC1yRmCB3mwncwpfcv18tFDJ6nu9gu+YNgQiqjyp1C/RRkPTWZ0d9DiWv7fekmw PbBHX4xbZXHBlJvRrG/++Mg88rw2pRQ73REgfRV9tStpnj4KqVMJCcOCx2Zf1r2+tFIP pJxjpihBj4uZ/YEz1HFsqItitzfnAE1KpM5nYEJ95AL3Q54fZLHrrPZsDwCi2ieDlk5y jdEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="CLwe1/YF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y17-20020a17090322d100b001cfbd271f2esi6839566plg.7.2023.11.28.03.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 03:32:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="CLwe1/YF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id D184480A6BE6; Tue, 28 Nov 2023 03:32:48 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343839AbjK1Lcc (ORCPT + 99 others); Tue, 28 Nov 2023 06:32:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234719AbjK1Lca (ORCPT ); Tue, 28 Nov 2023 06:32:30 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 772E11B5 for ; Tue, 28 Nov 2023 03:32:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1701171151; bh=RFVMPhKHsjpTRlZPbuzuBAOCwyfifnJ1d4FpP1154EU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=CLwe1/YFm/WM2lLbErcJ0vg+CwuXyTOZ1dyLO5bqOccWwXk6z7qsWumdTUgfZJVzi iV/Sli4I9lVw5hTRj4MtaxdEY3yHp+HXyD4ixXc+Tbg9RMt37o/0sv4BcJtjQrn11C R1IpkGO9x3bg8TWiUdDMwxlC+GW89babr5GoYxGdo/ohsWema+poMKJy0OVtevr1TN kfFeZ2plssFkQGxqmVSFDw7KHKLkJHbaApFPPYMkst5KqeUOkfMioI9209N9Xe1gm6 rbbZmxcouJ2QDChMrK7IyCYFmTrKszsBAbknbNzUf/a7W2lMfeACUyR6cpLeeSCTGv q/b0uEUQQJ3EA== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4SfgKp0PBMz4xPL; Tue, 28 Nov 2023 22:32:28 +1100 (AEDT) From: Michael Ellerman To: Kunwu Chan , Christophe Leroy , "npiggin@gmail.com" Cc: "kunwu.chan@hotmail.com" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add In-Reply-To: <9d871364-7baa-4daf-8b0c-3fbfbede6fdb@kylinos.cn> References: <20231122090026.11728-1-chentao@kylinos.cn> <32077b74-7335-4f4d-8858-c53c820150d0@csgroup.eu> <9d871364-7baa-4daf-8b0c-3fbfbede6fdb@kylinos.cn> Date: Tue, 28 Nov 2023 22:32:21 +1100 Message-ID: <87y1ei2jwa.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 28 Nov 2023 03:32:49 -0800 (PST) Kunwu Chan writes: > Hi Christophe, > > Thanks for your reply. > It's my bad. According your reply, i read the code in=20 > sysfs_do_create_link_sd.There is a null pointer check indeed. > > My intention was to check null pointer after memory allocation. > Whether we can add a comment here for someone like me, the null pointer=20 > check is no need here? I don't mind there being a NULL check for name. But the code shouldn't silently return if name can't be allocated. Notice that if we can't create the cache we *panic*. A failure to allocate name, which causes us to skip the cache creation, needs to also panic. cheers > On 2023/11/24 23:17, Christophe Leroy wrote: >>=20 >>=20 >> Le 22/11/2023 =C3=A0 10:00, Kunwu Chan a =C3=A9crit=C2=A0: >>> [Vous ne recevez pas souvent de courriers de chentao@kylinos.cn. D=C3= =A9couvrez pourquoi ceci est important =C3=A0 https://aka.ms/LearnAboutSend= erIdentification ] >>> >>> kasprintf() returns a pointer to dynamically allocated memory >>> which can be NULL upon failure. Ensure the allocation was successful >>> by checking the pointer validity. >>=20 >> Are you sure this is needed ? Did you check what happens what name is NU= LL ? >>=20 >> If I followed stuff correctly, I end up in function >> sysfs_do_create_link_sd() which already handles the NULL name case which >> a big hammer warning. >>=20 >>> >>> 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-commo= n.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 =3D max_t(unsigned long, align, minalign); >>> name =3D kasprintf(GFP_KERNEL, "pgtable-2^%d", shift); >>> + if (!name) >>> + return; >>> new =3D kmem_cache_create(name, table_size, align, 0, ctor(sh= ift)); >>> if (!new) >>> panic("Could not allocate pgtable cache for order %d"= , shift); >>> -- >>> 2.34.1 >>>