Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp926498rdb; Fri, 1 Dec 2023 02:17:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IEndlj9yEv6Tm/J1lde488bVQ4k6D0ajY5dFG1HxehlFn3Q/3lMHLyB2e5ipUdeRrB87Hbl X-Received: by 2002:a05:6a20:86b0:b0:18b:251d:d6f8 with SMTP id k48-20020a056a2086b000b0018b251dd6f8mr17779681pze.55.1701425860271; Fri, 01 Dec 2023 02:17:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701425860; cv=none; d=google.com; s=arc-20160816; b=GrRaKmMTtC/ORmG4NvKtOdktyce8d+AFrw8YhciavExNgqTznbvaFmimn/8oun96dh r5FJ++oJty6tjWWriEymEVx8Iqa0i+aAVcezXTMttOZUKYlR/4QHw7XdNl0m7faoyO96 bP1sv007I1cbW/Sa745TquoG70pFmqUIEKbsvbRrE/+/0235sa21+WYCQGszmyiCWM1d si0O2chdVMCifEOH7gLezuQodxl2pK4ZdYbU+/62nUEoMpspNrwZrO10hIYrXbmsvKjc ziaD88BM1/V3qoZr67ik/qVQpmWponc+Odb8sprHG2/fC20IqbYUwCTePAss10sEcvYf wV1w== 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:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=YDM8Y22Uw3soCEiLjFGP0Xjxg56+a/qHQ3QYMLfaxoE=; fh=JsQIO8C9w0CcSUbydmvXsKDU9UZGlVPSxILs9NoGFLM=; b=NYkgWDiV4zOHDbEXykwkbL6OUmN96cF4iOXBU2OvoGeHJG/gRtY+r4HAeh+e7WEBWR q+Y1d24jjK6d1G9IL48XqdOX1mdob1tkoHKY+nfuH2qOGD5TpKNQ6IPX6yPCtTuEV81P fOzsuu5awISrSEbonaBqhC8IHYExwMYn8vZyAWcz3/oknEI6zkTXJPPESI6MkAh3qZ3R MjNiS4kHbFJbgzA7lel630c627LNYPRG9orAMdwj0OH2IMen8u3dXT4AanvWqWO8V3Xj kmOT4ioqJmkn0WKz2/Zggq2Z/4ml9Nbg0hpON9W8jXErrbd+9IsDAzeGpD7tKiTnMOL0 cFSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=mKl4ghrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a10-20020a170902b58a00b001c9c83947d1si2844028pls.645.2023.12.01.02.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 02:17:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=mKl4ghrw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 E19F280FD8B4; Fri, 1 Dec 2023 02:17:37 -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 S1378214AbjLAKRZ (ORCPT + 99 others); Fri, 1 Dec 2023 05:17:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378203AbjLAKRY (ORCPT ); Fri, 1 Dec 2023 05:17:24 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BF1F84 for ; Fri, 1 Dec 2023 02:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1701425849; bh=YDM8Y22Uw3soCEiLjFGP0Xjxg56+a/qHQ3QYMLfaxoE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=mKl4ghrwdTD6YFAkhXpZeZdIY2tCvyKxhBS6fo49iNZ4/yKioR44Z+o5TfeX1/Dsv usslLBDHOt6xZVpfmF8cmIAlKMQUO4V++8Ss0t57au0Vw1PQ2Zq/EBt2weHaAPjqgy xUSirzcFpSWd7CisXNd+/ZoNtcn1VWPAsh/fYE6pjvdpTRDQKe5b0Ev7gCcp3v6FB1 BopG7o9YpZRvFKlriWcDZO8S+qd2Dft8vxs8rm4eHm21ZL14vEKt+qcW/NBRYJF2gd G28DH3F1jjhsYIylMA+kTlNn6AjtePeS5lnvLzwLGNICWyYxgyLQfNFXvfU/AlnJKX GknLhUEvHBVsQ== 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 4ShTWs2kLFz4wx5; Fri, 1 Dec 2023 21:17:29 +1100 (AEDT) From: Michael Ellerman To: Kunwu Chan , 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: Re: [PATCH v2] powerpc/mm: Fix null-pointer dereference in pgtable_cache_add In-Reply-To: <20231130090953.2322490-1-chentao@kylinos.cn> References: <20231130090953.2322490-1-chentao@kylinos.cn> Date: Fri, 01 Dec 2023 21:17:28 +1100 Message-ID: <87cyvq1b2f.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain 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]); Fri, 01 Dec 2023 02:17:38 -0800 (PST) Kunwu Chan writes: > 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); It would be nice to avoid two calls to panic. Can you reorganise the logic so that there's only one? Initialising new to NULL might help. cheers