Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3699854rwd; Sat, 17 Jun 2023 00:12:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55AlxhFkRvjP8Lztiq1+XItDF/OA3HCQSm6w9LaeLed6hRPYl9q2/Zfh6EJiQ55SKjnCVq X-Received: by 2002:a17:90a:550:b0:258:b651:4f80 with SMTP id h16-20020a17090a055000b00258b6514f80mr3775100pjf.36.1686985970448; Sat, 17 Jun 2023 00:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686985970; cv=none; d=google.com; s=arc-20160816; b=OxmQO64HtnYh2uJ9GA9Gtw+/Qj/IfnbppNiiI62zdMrwZNgTl33xmo76gYyvXRWrOA wGSvB4o/sBf/KEZWN9AJa/kbAEEBtoPcRQGMUoisfXOcPxavv6muDx2SSIRiE/cCo9ud eqHirp/zisqJYmVazem9NwqEOW7RwJFb8WonnpVKzFjLI19HiuquvUYZM13JlAEkkVvU t0hzbEYfYiEpVuIZN+zB0WEYgesEBrU42dqc8TJtGPgA5TJ/nIX34v3DnXiJ6dwjIzlF Qsl7Y/nhl1BibyWUoWxdWq1caKkeCSzXz5MXc681xjaEKpbCsuSY6EcSe2HoiMhk6zg6 XFFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PiU1NtyFPSEbvOhCZ5KnZ3BX35S9qmAab0SqyUZ6Ffg=; b=mZylxDPnnufldmNeuwQmeN/oTuOHGAUu9fmml5VazhMHR8LrERc9Fyi/sG6On3xowi GfUpij4NAQ9e3SMBGayYCtAQ24TCuSC+06s+oqCrSNlYQj1kvMoqKXCoUkcNXc5R+8uj nv06v3ORlN04BogNeJVSEwOrnLXVReFZkyTgcGYCA8MI0kQts6l/ZSK44SUklCw8aFan j72+F7E5c37kroNKembDrLfHMKT8leoXwBQLnjSEu5xclwkvFyJOEkOpOGJsBRmU1prD cGuNQVfk0nlCdxthVy4+VqBLQ4bC9+Dl7+rFtqvtneT88RhAYDco6mH0rfYUvBNBGbRp b/xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=O80ds2n0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bs5-20020a632805000000b0054f73ee92basi12264042pgb.8.2023.06.17.00.12.37; Sat, 17 Jun 2023 00:12:50 -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=@kernel.org header.s=k20201202 header.b=O80ds2n0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233528AbjFQHBg (ORCPT + 99 others); Sat, 17 Jun 2023 03:01:36 -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: X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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, 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.