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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D6EDC433F5 for ; Thu, 7 Apr 2022 14:17:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2AAD6B0072; Thu, 7 Apr 2022 10:17:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED9276B0073; Thu, 7 Apr 2022 10:17:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA2EE6B0074; Thu, 7 Apr 2022 10:17:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id CBACE6B0072 for ; Thu, 7 Apr 2022 10:17:47 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9AF812A372 for ; Thu, 7 Apr 2022 14:17:37 +0000 (UTC) X-FDA: 79330286154.10.59FFC8A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id C18D84000C for ; Thu, 7 Apr 2022 14:17:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iveGK1/Yuor96D4y10ufJ6G2Pghx6MVtRSQWDI/71jg=; b=Lau3m21l6fe80P7yOEfaJmxZIM Woq6nDA/hd61xO6MJxvkRU+zcJo2Ms/KlRHAaYEGaB1bf4t10T8POdWQxLt1TnCjyvBhtDs9YHKbJ cqZwDKgZHWLGfCkUSkwers4k8vzmUsLl7+HJnZ6mLI/Xm8q26rG2kj9+68OAAnhdrijztYaWk+0mm Lv+32woMRaSAwAzPaD/bHBFbuuMtcd4hWjOwaqxnRhubGdwvunbnXXIz0CywFvQmBT+ywTc9nnKGk KY7/gXQ1SfzNlA52cae4Yb35ywZdAlh/jr3jEY6oSL4PVJayJgHYrrePRS+GE1G6umuxmbw3DKe/4 QjEOJAbQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncSwx-008uHX-3R; Thu, 07 Apr 2022 14:17:27 +0000 Date: Thu, 7 Apr 2022 15:17:27 +0100 From: Matthew Wilcox To: zhenwei pi Cc: Mike Kravetz , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: fix kernel NULL pointer dereference in page_vma_mapped_walk Message-ID: References: <20220407064008.71869-1-pizhenwei@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Stat-Signature: h1gyky49wf4nqpo97hibd3bzscj93epj Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Lau3m21l; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C18D84000C X-HE-Tag: 1649341055-109981 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: On Thu, Apr 07, 2022 at 02:54:42PM +0100, Matthew Wilcox wrote: > On Thu, Apr 07, 2022 at 02:40:08PM +0800, zhenwei pi wrote: > > size_to_hstate(4K) returns NULL pointer, this leads kernel BUG in > > function page_vma_mapped_walk. > > Yes, I think this is the right fix. It's not immediately obvious from > the bug and the patch, but what's going on is: > > page_mapped_in_vma() sets nr_pages to 1. This is correct because we > usually only want to know about the precise page, and not about the > folio containing it. But hugetlbfs is special (... in so many ways ...) > and actually wants to work on the entire folio. We could set nr_pages > specially for hugetlb pages, but it's better to ignore it in > page_vma_mapped_walk() for the hugetlb case. > > I'll fix up the changelog and add it to my pile of fixes that I'm > sending tomorrow. > https://git.infradead.org/users/willy/pagecache.git/shortlog/refs/heads/for-next I looked over the patch in context, and realised we now don't need to call size_to_hstate since we're getting the hstate from the VMA. https://git.infradead.org/users/willy/pagecache.git/commitdiff/98ea02597b9967c0817d29fee2f96d21b9e59ca5