Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3674272rwd; Fri, 16 Jun 2023 23:39:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CGYJ6Y77OTh99ouaXaYNzuCVFDLf6ahl10+d5xOBOXSI1OLrnsV5MK1XsJKJR5gvMXEr7 X-Received: by 2002:a05:6870:3895:b0:192:5cba:4c10 with SMTP id y21-20020a056870389500b001925cba4c10mr1366549oan.40.1686983994123; Fri, 16 Jun 2023 23:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686983994; cv=none; d=google.com; s=arc-20160816; b=DY7DD2pTyXqG0MIcmCVBJTSQD0/vyrtq5vRHetmwFDJ6L9epnc+3eEKlwOp9t+Z4Gx XUvYFU8TpAxNNsr/FrHDv+sVXBaCna6fgOSGNoeEbt1rP5x2jaHFQevKrRNwaXbT/AKg E0App7XVuVxsDVkByV+JBQMGJ2h1miKDGlevodjJNu98HuWdHkKp3PoibkO/VUY5CYp7 woVTIH8RIXHMrj/tSeMk0VhviPkFAOZElOR+NaGxUJwBM+FZDbjZxONMNyIp0J1qoQfe KFe4+CU8cjuYzUQDSRWZlsrMwo9RTvwWZzjGXxxeXRIFldEC7NrIjB3ieIRnNwRPFxnf 4rPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OM1SbdFY48xnS90YPMKPt/WpbhAPZNcjijkfIfyg0oY=; b=VltT+ZdYmBbpOPFu53akNDEDX1Y9cWT6WK5mNL4pRCoYvMZOH515eYGP4KVHDHJep+ cFruHRgE6zD7NQ30loeStswK4La+04sOrxUZR70dRw09qx1XXZkU2o9+hPwdoZvJqCy+ OGVnMYQNmk6705PVCe4TUNNyCQRVj/lvSAom0MNFWNaiA6pafAzEwQZEf9OzBoPjK7jj /H5WkhM2wfmSevVNOU8xM1zdNqPhcOD0qFOD0LybhmYXpB2qZPBakX7bPdE8iPdaEdRx S2x+nCfkojxBrZIWmdpYZAJD2/gSgvX/wCD1Etp2YT7h3wR6QA89echSz54Of/b0EjzV uDPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=M54PqSnH; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n127-20020a632785000000b0053592294fc0si14913001pgn.256.2023.06.16.23.39.37; Fri, 16 Jun 2023 23:39:54 -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=@gmail.com header.s=20221208 header.b=M54PqSnH; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbjFQGSL (ORCPT + 99 others); Sat, 17 Jun 2023 02:18:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjFQGSK (ORCPT ); Sat, 17 Jun 2023 02:18:10 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7890C1 for ; Fri, 16 Jun 2023 23:18:09 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-57001c0baddso17124057b3.2 for ; Fri, 16 Jun 2023 23:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686982689; x=1689574689; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OM1SbdFY48xnS90YPMKPt/WpbhAPZNcjijkfIfyg0oY=; b=M54PqSnHl7F5+elaNhaomKWQ0HF3/Jic7ectrTo5YE5JWEme1GfptibwBMa6YSXvf3 h0/+BXM7yq9NCA1HjuuVMW3pcJEWmJRinfgH/Qlf8nC3jBiDZHrVEod12cAjE4VUUA1M ffdSEXqiI8uFLC0fsKVcmcDUSWNEqpKBC6Rqevzr65PieFQDrAQXNo2XaaYoL/rSuU5j /gW+/nA9sMlbca9XEYSlwBSPhtwKOUm9qnw4yffz7pZVVSYIMAtSGyfZCe4VrPT1WqJd SfJlSfTab+3aDDGueDhMTLHLI3cs+euBuKVynDHL41uzLmr1zecuWpPjEAnG88mmKLIe Kjvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686982689; x=1689574689; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OM1SbdFY48xnS90YPMKPt/WpbhAPZNcjijkfIfyg0oY=; b=DoPg76jdgzYfwKfhWJ1Oo74ziOCPkXaaDaj1Zd+Chb5S8PGjkXtSR6IZdZHC2tpChC KX0Cl6F7Q7XE7vA/hJB+Qi+oc/TlDiLf7jCoMqilmFfoRwyD+pqX/qsvpxDnau9ocdkT C8EN0vQqCmAGCch+kyoCSHTg6v+neEQwSoczbaf8U2HB8cBIPU0XvDoUVuS3B3iHigQg OvFuqe1M7UZ/bFjRUg3EVd7GqWfd1EUwpCe5eLk0yiydhNZAKTWyf4PWRwT+cscpc+BU lxlVQK2exnp95JAQZ1J4LZFvbUuohzXrxc010jTT/M71b0c4+yXSLfWyfyyYLbAURO08 QUkA== X-Gm-Message-State: AC+VfDz6T3hOVH7ZlYKEGb7AoD1RotAIo9kHBGgiPMge6HcpkIIZSCZn E8nF9jLftXKnpLvm+sU2tgGxfxyAqijjyqKyiOonPLBQDVLJqHGB X-Received: by 2002:a25:2e0c:0:b0:bc3:843a:953a with SMTP id u12-20020a252e0c000000b00bc3843a953amr1110079ybu.18.1686982689027; Fri, 16 Jun 2023 23:18:09 -0700 (PDT) MIME-Version: 1.0 References: <20230617044036.3985524-1-zhiguangni01@gmail.com> <20230616224407.863c74a3dc9d4f1427802f91@linux-foundation.org> In-Reply-To: <20230616224407.863c74a3dc9d4f1427802f91@linux-foundation.org> From: Liam Ni Date: Sat, 17 Jun 2023 14:17:58 +0800 Message-ID: Subject: Re: [PATCH] mm/sparse:avoid null pointer access in memory_present() To: Andrew Morton 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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, 17 Jun 2023 at 13:44, Andrew Morton wro= te: > > 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 =3D __nr_to_section(section); > > - if (!ms->section_mem_map) { > > + if (ms && !ms->section_mem_map) { > > ms->section_mem_map =3D sparse_encode_early_nid(n= id) | > > 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=EF=BC=8Cms->section_mem_map will cause system panic,so we needn't change? >