Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3656187rwd; Fri, 16 Jun 2023 23:15:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6s5QP+NvLV78ZaCVr5V9kXFHaboWSj3bQup0OGV6dFmTctlLYjKhDI6SJKP9njiyK5TQdZ X-Received: by 2002:a05:6808:1490:b0:398:a09:3cb with SMTP id e16-20020a056808149000b003980a0903cbmr5357183oiw.36.1686982536661; Fri, 16 Jun 2023 23:15:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686982536; cv=none; d=google.com; s=arc-20160816; b=OJknREWvg8yOkctu6gPnAbXXadFmCaYc0zCEptcDLy3jH2UmzqXrMVRkT9/2BPCE6X SflHo/6MVELW+H+bDKXm1lYxjJlB+Lpx76IFbxNDxqZ5c1/unaYXSptC4+/O9d7tzTHu ic5SL56S4mKelm4XMjsl4iPT18qaeK+qOhDJUj/GFSY7hGJtAC3zv79WGpuJid/M9Ny3 Gtk1+BiscQ1QOpFx3Et8PTCgDrSFPkVeHGbyXJgc+w41LMEomo9X/PXrhIzYNOmrzuWn vMBWlHjOkYF8/2bdW3YrTLWoFMQKDp6ilIx0R0xNVu2rH3IfTuGxzF9O3m8tvmkLx1TE m1LA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=s1ZWWb1jqTztM8JGZ/v2eUer1XkK99+Zc9TpgbWNWVY=; b=Gujo/8+lualYaAoPiSE0LNziW+nMs4ps+MIEYdwd3THYOTqRClMCbOn+1o+KaGznER eOCF6IYPZE6WdTmqhY0KhMRk+aLwUeBzyNYWYWOmURedDKgHGIF/hTYN/4pOhpm25N+n P9hAR8899VwCAdB31f8sh8GbHsyA06EpzMdt8ImJLTTPg9DD5q2Q0eIyblyK7xPnJVxr aw9FpsaZXwf/RmnRNBanZA3pTzkY3wnFE2PgdZpzPGmNUo3izqH4aKtc0BDNA1Gkp3Gf KCnUZ8jrtalRCvT0hhd+HPRO0LBMiBXI3u3smonnDsWBvmZR2AWS80bSSgdN9HUjoMof HP2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EQjtHBOf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a170903411200b001b52759fcb4si3465442pld.264.2023.06.16.23.15.23; Fri, 16 Jun 2023 23:15:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EQjtHBOf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229686AbjFQFoL (ORCPT + 99 others); Sat, 17 Jun 2023 01:44:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjFQFoK (ORCPT ); Sat, 17 Jun 2023 01:44:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F1A51FDD for ; Fri, 16 Jun 2023 22:44:09 -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 194C0608CC for ; Sat, 17 Jun 2023 05:44:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB18DC433C8; Sat, 17 Jun 2023 05:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1686980648; bh=BVMmEiv915B72MWDh+k4N5DRLAHb8wLn4DnfeaejgGg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EQjtHBOfTgfTDp/m2Uzyztq4D5TIdXayeQK9pmNbeTCSDfAw4gYr3nAviXfOhDcbQ lLRRHXUNKxVyx2w2mbYludCh2mmtiPBSyMxgoAOVYnW8AjZJhp1d36jTJYhHEXeHyS 6SnMfoXOswvJPZmseK6puk9Zc7QnVB1efFPICqJM= Date: Fri, 16 Jun 2023 22:44:07 -0700 From: Andrew Morton To: Liam Ni Cc: 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, rppt@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm/sparse:avoid null pointer access in memory_present() Message-Id: <20230616224407.863c74a3dc9d4f1427802f91@linux-foundation.org> In-Reply-To: <20230617044036.3985524-1-zhiguangni01@gmail.com> References: <20230617044036.3985524-1-zhiguangni01@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 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?