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 X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CF91C10F14 for ; Tue, 8 Oct 2019 15:29:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0D823206C0 for ; Tue, 8 Oct 2019 15:29:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D823206C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AC5D08E0005; Tue, 8 Oct 2019 11:29:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4ED48E0003; Tue, 8 Oct 2019 11:29:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9166D8E0005; Tue, 8 Oct 2019 11:29:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0075.hostedemail.com [216.40.44.75]) by kanga.kvack.org (Postfix) with ESMTP id 6B0AD8E0003 for ; Tue, 8 Oct 2019 11:29:32 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 12942824CA38 for ; Tue, 8 Oct 2019 15:29:32 +0000 (UTC) X-FDA: 76021001784.01.work17_532be94b0144d X-HE-Tag: work17_532be94b0144d X-Filterd-Recvd-Size: 3383 Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Oct 2019 15:29:31 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1D112B1B6; Tue, 8 Oct 2019 15:29:30 +0000 (UTC) From: Vlastimil Babka To: Andrew Morton , Mel Gorman , Florian Weimer , Dave Chinner Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Vlastimil Babka , stable@vger.kernel.org Subject: [PATCH] mm, compaction: fix wrong pfn handling in __reset_isolation_pfn() Date: Tue, 8 Oct 2019 17:29:15 +0200 Message-Id: <20191008152915.24704-1-vbabka@suse.cz> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Florian and Dave reported [1] a NULL pointer dereference in __reset_isolation_pfn(). While the exact cause is unclear, staring at the= code revealed two bugs, which might be related. One bug is that if zone starts in the middle of pageblock, block_page mig= ht correspond to different pfn than block_pfn, and then the pfn_valid_within= () checks will check different pfn's than those accessed via struct page. Th= is might result in acessing an unitialized page in CONFIG_HOLES_IN_ZONE conf= igs. The other bug is that end_page refers to the first page of next pageblock= and not last page of current pageblock. The online and valid check is then wr= ong and with sections, the while (page < end_page) loop might wander off actu= al struct page arrays. [1] https://lore.kernel.org/linux-xfs/87o8z1fvqu.fsf@mid.deneb.enyo.de/ Reported-by: Florian Weimer Reported-by: Dave Chinner Fixes: 6b0868c820ff ("mm/compaction.c: correct zone boundary handling whe= n resetting pageblock skip hints") Cc: Signed-off-by: Vlastimil Babka --- mm/compaction.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index ce08b39d85d4..672d3c78c6ab 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -270,14 +270,15 @@ __reset_isolation_pfn(struct zone *zone, unsigned l= ong pfn, bool check_source, =20 /* Ensure the start of the pageblock or zone is online and valid */ block_pfn =3D pageblock_start_pfn(pfn); - block_page =3D pfn_to_online_page(max(block_pfn, zone->zone_start_pfn))= ; + block_pfn =3D max(block_pfn, zone->zone_start_pfn); + block_page =3D pfn_to_online_page(block_pfn); if (block_page) { page =3D block_page; pfn =3D block_pfn; } =20 /* Ensure the end of the pageblock or zone is online and valid */ - block_pfn +=3D pageblock_nr_pages; + block_pfn =3D pageblock_end_pfn(pfn) - 1; block_pfn =3D min(block_pfn, zone_end_pfn(zone) - 1); end_page =3D pfn_to_online_page(block_pfn); if (!end_page) @@ -303,7 +304,7 @@ __reset_isolation_pfn(struct zone *zone, unsigned lon= g pfn, bool check_source, =20 page +=3D (1 << PAGE_ALLOC_COSTLY_ORDER); pfn +=3D (1 << PAGE_ALLOC_COSTLY_ORDER); - } while (page < end_page); + } while (page <=3D end_page); =20 return false; } --=20 2.23.0