Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3202702pxb; Mon, 9 Nov 2020 05:30:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzkUUgG8hZXnOr+y++I5UKXg13OHb6HDnclNm7BSVvtv9/vJaYPh4K8okq8jENYvGh1E3xz X-Received: by 2002:a17:906:6a15:: with SMTP id o21mr14529743ejr.305.1604928635399; Mon, 09 Nov 2020 05:30:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928635; cv=none; d=google.com; s=arc-20160816; b=FrotuSmex4kPHbSizVtR3VcaDqTLXXxg86BRXCJgNdr2bCQxWAMHKYZAqNNJsYgWqg pKReNnb6NFCPh3XfV+4aYifh2OvAzL4LXmDWqhg1Nye67ii9AXMV39+3u198Q62IT3Ej vCr+k4tHDETo0QZtrOZ6Xn7G9rmbwlBwp5htM9UottbGqfbaRm0VFHRdOg1kQmagSNTk jaMuoin9d5qEu2Jh4KA3lJMgdgz61A8fRZxIWE003E/qimJdPmbokAM358ajRfg5ylQW CXPD/JNPIShlFJa2FuwG/dqN/kuNfwSvBRE7NUvsU9z3f03/vBrJ8WmDIQpR0Y75f/6i wQdA== 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=EKcKx4LbSDQVsxUm2dwBI2WnHDVd1tjzuH7WOeH4+9Q=; b=KnMPIi7rNQQrYqBUV3ybcntmdA+h8FpRyyAMVHC50BBVGgwNaRZlwTLktNyN0A4GEH Ccxehr0ky37quzP41cIfLPD/n9YDmFriOuJeB3hOg8uAz1xGbozstGH+yxqIBv2ae+MJ nGJCqQxGnmbwdA/hlRwwFQJW80vmjvQb2hw7aTaBEVzdcVVxIgsWrx22AQ6CzTuEkaTA qkpjK3viXiiwgfHstEWyf/EQH1WHiGoWLMnMH449hTmYhKkQwTmQD2aHyBW+EYiESBqI ouYT+EI0I+XMI22+tDX1YiX2V9QN97XHXrQKAdl5ZZIgNzSa5SiyeYMDVz93lgeX96/W hY7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fc/ias8h"; 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=fail (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 bd20si6634651edb.98.2020.11.09.05.30.12; Mon, 09 Nov 2020 05:30:35 -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=@kernel.org header.s=default header.b="fc/ias8h"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732774AbgKIN2l (ORCPT + 99 others); Mon, 9 Nov 2020 08:28:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:39382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732967AbgKINNa (ORCPT ); Mon, 9 Nov 2020 08:13:30 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 188242076E; Mon, 9 Nov 2020 13:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927609; bh=XxnATp9HULNcOgR/Wtu94Yzo15VEht3cuy99ua/fkEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fc/ias8h3fEJqIEJbdrrhjJlNcu2VAjrIYNt/oL8RZqSrZIPS97c+ZCBXcPSsoAYw xsb2mXoMyNHU7bnwmYyuDlMoWyxXrPFTujzmq5lVnEAsCKSBDzuPF2/cPkRIdYkhDB MiTwuEz/wYVIbvSr1zOuHqF6JnK4ROyvJz+xAWPI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shijie Luo , Miaohe Lin , Andrew Morton , Oscar Salvador , Michal Hocko , Feilong Lin , Linus Torvalds Subject: [PATCH 5.4 29/85] mm: mempolicy: fix potential pte_unmap_unlock pte error Date: Mon, 9 Nov 2020 13:55:26 +0100 Message-Id: <20201109125023.985251501@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125022.614792961@linuxfoundation.org> References: <20201109125022.614792961@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: Shijie Luo commit 3f08842098e842c51e3b97d0dcdebf810b32558e upstream. When flags in queue_pages_pte_range don't have MPOL_MF_MOVE or MPOL_MF_MOVE_ALL bits, code breaks and passing origin pte - 1 to pte_unmap_unlock seems like not a good idea. queue_pages_pte_range can run in MPOL_MF_MOVE_ALL mode which doesn't migrate misplaced pages but returns with EIO when encountering such a page. Since commit a7f40cfe3b7a ("mm: mempolicy: make mbind() return -EIO when MPOL_MF_STRICT is specified") and early break on the first pte in the range results in pte_unmap_unlock on an underflow pte. This can lead to lockups later on when somebody tries to lock the pte resp. page_table_lock again.. Fixes: a7f40cfe3b7a ("mm: mempolicy: make mbind() return -EIO when MPOL_MF_STRICT is specified") Signed-off-by: Shijie Luo Signed-off-by: Miaohe Lin Signed-off-by: Andrew Morton Reviewed-by: Oscar Salvador Acked-by: Michal Hocko Cc: Miaohe Lin Cc: Feilong Lin Cc: Shijie Luo Cc: Link: https://lkml.kernel.org/r/20201019074853.50856-1-luoshijie1@huawei.com Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -496,7 +496,7 @@ static int queue_pages_pte_range(pmd_t * unsigned long flags = qp->flags; int ret; bool has_unmovable = false; - pte_t *pte; + pte_t *pte, *mapped_pte; spinlock_t *ptl; ptl = pmd_trans_huge_lock(pmd, vma); @@ -510,7 +510,7 @@ static int queue_pages_pte_range(pmd_t * if (pmd_trans_unstable(pmd)) return 0; - pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); + mapped_pte = pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl); for (; addr != end; pte++, addr += PAGE_SIZE) { if (!pte_present(*pte)) continue; @@ -542,7 +542,7 @@ static int queue_pages_pte_range(pmd_t * } else break; } - pte_unmap_unlock(pte - 1, ptl); + pte_unmap_unlock(mapped_pte, ptl); cond_resched(); if (has_unmovable)