Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3881487pxb; Tue, 17 Nov 2020 06:07:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9HpuyncGHaXh8khHOGLxwbTgkNplXO7B2pXDVwNsILtJsUC0bVFLJ1ZejDEqwZYPrxn38 X-Received: by 2002:a17:906:ca93:: with SMTP id js19mr20549587ejb.537.1605622035059; Tue, 17 Nov 2020 06:07:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605622035; cv=none; d=google.com; s=arc-20160816; b=nSRA+GFHZ3p55okho+RkCJYDqMBmgUJAMLAomD73CYiBQPISsGqTIChIQBDBanWqj0 9GCbxx8VtumEMkB9L8JmdAFejQqLVs/fI7jKJ7l2tDnVco70oBQINZY6OhDfEXTziAi3 MmwxEheH/LpSdNyGbQDQJrLKGqcxl3qhQGlNlRk3gNxZMOoyiVIBLDewxpdFiH0VrOgn WJ2jASAhsbNiPfc0yPTpvvgD347SkR5i+t/D7sgGmdtIxuYxDlMaZRTj64o85S40bUqp B71DBcp/RbjOFgEW4XsZOwomqgpzUvE+usSI4PuvFvWZ9kqC0c5CS0hF6jDdflPYpuRc dcsA== 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=1JTbU7TvV8h6ksilQHez6WMv8jOZ1bVoxtEjLWMWNO0=; b=m3tuW8DD4fc1TjYnbZN5Le8liUNQsCqGPtV8GxqVl8tUWdtXtka6hJysug16VJNgHF mqgANUo5aKEm3eUz2dq4hDCmSZb7VIH6acgwRheCHk0N5EW78l0Ob1Qg2RGQ43LRVq6r wEMe/LwLmGRgcMz3tKf5y3tb4wEWlewiDBxZ/JrZK0CIzm260idsQtlrrtXCLNFfgsVs pRC/4QiXqVDjFUk+4PEatvXcNwDEPaAwhZUXw4ejKV7CWw4qsKErhpNd46NKzlwlUGJp rQdMX4JCZZ9oB9oeaFzQtC+Fe9oV0KlOIb/ct5lTkZagJBNUGDWFJT08PJzGiiKsqYMn Hysw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qFQGG2Hq; 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 o1si12430562ejn.643.2020.11.17.06.06.47; Tue, 17 Nov 2020 06:07:15 -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=qFQGG2Hq; 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 S1729512AbgKQOEY (ORCPT + 99 others); Tue, 17 Nov 2020 09:04:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:40000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729488AbgKQNKg (ORCPT ); Tue, 17 Nov 2020 08:10:36 -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 12B56221EB; Tue, 17 Nov 2020 13:10:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618635; bh=sDle4BanFvLiTyXPkW94/wH0luaWEP4b4rv4Z2/qip0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qFQGG2HqC3TsGv4QW6DICIAZtMdUcUIe9M/qQFmYzW5cDKKxEI7zcYEe1ZG88qR0j r2z+zreJ3sgVsx1kll6ofbg/kzBNG49Li6nnSlQPp4Nnk5SNp6NJOpZ1pf0hpDxXg2 I8pZjzkKnDdKtglJCBr0VFN1Xv6RvmNsP4dShY1A= 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 , Sasha Levin Subject: [PATCH 4.9 04/78] mm: mempolicy: fix potential pte_unmap_unlock pte error Date: Tue, 17 Nov 2020 14:04:30 +0100 Message-Id: <20201117122109.334051504@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122109.116890262@linuxfoundation.org> References: <20201117122109.116890262@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 [ Upstream commit 3f08842098e842c51e3b97d0dcdebf810b32558e ] 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: Sasha Levin --- mm/mempolicy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a2be65bf5d8cc..2f443767fd1b4 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -487,7 +487,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, struct queue_pages *qp = walk->private; unsigned long flags = qp->flags; int nid, ret; - pte_t *pte; + pte_t *pte, *mapped_pte; spinlock_t *ptl; if (pmd_trans_huge(*pmd)) { @@ -515,7 +515,7 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, if (pmd_trans_unstable(pmd)) return 0; retry: - 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; @@ -554,7 +554,7 @@ retry: } else break; } - pte_unmap_unlock(pte - 1, ptl); + pte_unmap_unlock(mapped_pte, ptl); cond_resched(); return addr != end ? -EIO : 0; } -- 2.27.0