Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp406666pxb; Wed, 3 Mar 2021 06:22:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJH9lx0VuzEiIyLNXwKHfNdxxVAsqNMxWoVhAFqMeNEqDJdPrwyE6T4iOBu8g1Iy5Z8Zk9 X-Received: by 2002:a17:906:bb06:: with SMTP id jz6mr1016125ejb.429.1614781346538; Wed, 03 Mar 2021 06:22:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614781346; cv=none; d=google.com; s=arc-20160816; b=HBhF6U0MtQqjtYcb08BD+s+k8IdnRlI8bRVrMpV9s1cqsLg7CTC5S9aC+YO7V1SH0C 5bNlOPY5yQSBoCkPqJsQMX1IlEhNpxUtt08zriEXVsxUx/5z8L/PMmGwABYLXWiLL/LJ Bi9nzACAZCC79LXhM73YOVlcPXHiYmPcgjqi9Tjf9UJuyQrEXKxzpdf5gegoG4p9qB9G 8wb175Fb6KNIQrm1TGoaHf0XoSkGFs1EGCZJuWT1eOLE8LbjKSWU63tobgAu13qERKnx hWLpeHXQyZaRiapQR+HU1SseJoZq8x1gqu7MEvJb2lvi7MjjXS+PChrI5oyCj+x+gCKJ hv2A== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=riDEFO9oRdIPvGfW8959mTOy7QNLQ52GmKkiOWR/2Ds=; b=0UFXknJ2V5nwuO2zzswMKgjtbzUYTxA4hvTJJKG7vpvHvNtGEeNBoRo/9Yy4mw+f+w oiEdpvF89SZi5Di3GWD4+BqzAn9+1xXMo5zr964MQJveAek9P8/nNh6d/VTBccUtYuPq U5C00qQnAWt+HD1pzL0YAGL3XR6Z4KfLyj+H8fz4Iv7ZGKaT468QNxmFVT0D5iMRLhUy znVfFMmxrjTUx+uuMBtiGN/s69lDQV9QGf/+494f82GFRFijwcbfGb3/d2cxH/0zXNI0 PmtEqilKUTFIwRYT25MaB2ZoLdhnOeBaTRwbjmxx9N5DTaPtf8q2ht2FsVNABvJLE/kc xRBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2FePPdVp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si5749171edr.603.2021.03.03.06.21.16; Wed, 03 Mar 2021 06:22:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2FePPdVp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240305AbhCAVGG (ORCPT + 99 others); Mon, 1 Mar 2021 16:06:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:51394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237661AbhCARM7 (ORCPT ); Mon, 1 Mar 2021 12:12:59 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6857B6502C; Mon, 1 Mar 2021 16:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617026; bh=8KetaY3jJxH96ZE64Is+hsCF0fw8fPzVg9/TFD8GjgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2FePPdVpGHM7G6Y+Ye8wlww6If8ssgBJeXGrdqFbgL5JnzuMNCBki4JHe4vsmMk4J Svq2UrLQLVfmh46cybIQ3O0txbasrEp9TFz+2lbLOZBFc58Ktw9TFcaDi16TJCQ5Zo 3XIKwGshdSsuCjaw3bTz6h/gIbJ0l8ekN0weZ+2I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hongxiang Lou , Miaohe Lin , Sedat Dilek , Kees Cook , Nathan Chancellor , Mike Kravetz , Shakeel Butt , Johannes Weiner , Vlastimil Babka , Michel Lespinasse , Nick Desaulniers , "Kirill A. Shutemov" , Wei Yang , Dmitry Safonov <0x7f454c46@gmail.com>, Brian Geffon , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 176/247] mm/rmap: fix potential pte_unmap on an not mapped pte Date: Mon, 1 Mar 2021 17:13:16 +0100 Message-Id: <20210301161040.266545926@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ Upstream commit 5d5d19eda6b0ee790af89c45e3f678345be6f50f ] For PMD-mapped page (usually THP), pvmw->pte is NULL. For PTE-mapped THP, pvmw->pte is mapped. But for HugeTLB pages, pvmw->pte is not mapped and set to the relevant page table entry. So in page_vma_mapped_walk_done(), we may do pte_unmap() for HugeTLB pte which is not mapped. Fix this by checking pvmw->page against PageHuge before trying to do pte_unmap(). Link: https://lkml.kernel.org/r/20210127093349.39081-1-linmiaohe@huawei.com Fixes: ace71a19cec5 ("mm: introduce page_vma_mapped_walk()") Signed-off-by: Hongxiang Lou Signed-off-by: Miaohe Lin Tested-by: Sedat Dilek Cc: Kees Cook Cc: Nathan Chancellor Cc: Mike Kravetz Cc: Shakeel Butt Cc: Johannes Weiner Cc: Vlastimil Babka Cc: Michel Lespinasse Cc: Nick Desaulniers Cc: "Kirill A. Shutemov" Cc: Wei Yang Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Brian Geffon Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/rmap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 988d176472df7..d7d6d4eb17949 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -214,7 +214,8 @@ struct page_vma_mapped_walk { static inline void page_vma_mapped_walk_done(struct page_vma_mapped_walk *pvmw) { - if (pvmw->pte) + /* HugeTLB pte is set to the relevant page table entry without pte_mapped. */ + if (pvmw->pte && !PageHuge(pvmw->page)) pte_unmap(pvmw->pte); if (pvmw->ptl) spin_unlock(pvmw->ptl); -- 2.27.0