From mboxrd@z Thu Jan 1 00:00:00 1970 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 E9EFCEB64D9 for ; Sat, 17 Jun 2023 07:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234337AbjFQHBj (ORCPT ); Sat, 17 Jun 2023 03:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229686AbjFQHBc (ORCPT ); Sat, 17 Jun 2023 03:01:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567611FD3 for ; Sat, 17 Jun 2023 00:01:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E7EB7610A0 for ; Sat, 17 Jun 2023 07:01:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A65BC433C0; Sat, 17 Jun 2023 07:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686985290; bh=LCWiIYok7wPa8JmladBwxsU8b4TpZw2gc2yopJupTA0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=O80ds2n0w2Y27jQlNNmCw6o7nzBwcd9UpC4nb8KEUyV/0smDBfB8arZKAbk5uMHZ+ X4xEDAai66NbKfnyfwNibfI9I909mpdZY57Qt58iCT0auKiQEf+mZu1+dzdCcUw464 wVopteNc442cg3A8r+f0O7J9KMhAfX/KjC8GNwTGll+4y8ykPFHrGAAQf7Hdjyj3Ad /I6ZFYk6sW2FyN33DW36WSgFdQ6zLgr/CGdysRJJmEKw0YPUeDpSuG0tsaYXUCjvi6 5c1dhYMrPgHmLzPjV+2IdEhf/zGofo+y0FIRemQlLcefviGqX7jIyniUmHw7SbhKoH Rqm2ff7Gd9iFw== Date: Sat, 17 Jun 2023 10:00:51 +0300 From: Mike Rapoport To: Liam Ni Cc: Andrew Morton , dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/sparse:avoid null pointer access in memory_present() Message-ID: <20230617070051.GU52412@kernel.org> References: <20230617044036.3985524-1-zhiguangni01@gmail.com> <20230616224407.863c74a3dc9d4f1427802f91@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 17, 2023 at 02:17:58PM +0800, Liam Ni wrote: > On Sat, 17 Jun 2023 at 13:44, Andrew Morton wrote: > > > > On Sat, 17 Jun 2023 14:40:36 +1000 Liam Ni wrote: > > > > > __nr_to_section() may return a null pointer, > > > before accessing the member variable section_mem_map, > > > we should first determine whether it is a null pointer. > > > > > > ... > > > > > > --- a/mm/sparse.c > > > +++ b/mm/sparse.c > > > @@ -258,7 +258,7 @@ static void __init memory_present(int nid, unsigned long start, unsigned long en > > > set_section_nid(section, nid); > > > > > > ms = __nr_to_section(section); > > > - if (!ms->section_mem_map) { > > > + if (ms && !ms->section_mem_map) { > > > ms->section_mem_map = sparse_encode_early_nid(nid) | > > > SECTION_IS_ONLINE; > > > __section_mark_present(ms, section); > > > > I'm suspecting that if __nr_to_section() returns NULL here, we should > > just panic. But a null-deref gives the same information, so why change > > things? > > Do you mean if ms is a null pointer,ms->section_mem_map will cause > system panic,so we needn't change? Yes, if __nr_to_section ever returns NULL the system will crash anyway. -- Sincerely yours, Mike.