Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp885236pxb; Sat, 9 Jan 2021 00:03:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPxe3L50WpXSGeYaE6TZNSfgfwSJktb2htpTr5ytPsYw/utgex1ErUj88hFeaLiegDdRTG X-Received: by 2002:a05:6402:1d9a:: with SMTP id dk26mr7833303edb.283.1610179435671; Sat, 09 Jan 2021 00:03:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610179435; cv=none; d=google.com; s=arc-20160816; b=D3j+RD2HFttRKM247Byt1az111+fNsR4zn35LQvj3TlHz82p3q6vVhaYS2b99NsJ/G vmnx6llgDV+KH9sbY632FYcaRMS4AbxBkFmbp5jpIAsaciFwvt2W2WZ/Q3ft8wqQbbOY SmAA7YNqeYliyASW9cb5KweEskW7WKqFVcn8gZ05xPF2xbZcPdoxhIlgX8WdwD287ppB 7QD+0gJJCnqaVc88b2yf8ldAkTvZigEwN3RfQ5fRePXZXr3oCQB4ZDVMqHfUTC3wq1GF 6k3SiE1pGh/6cvKvOIOIImLGkYYfenXLkLKpdatbnHV2exsrGoqoF082JSZPOIbgfSA9 pehQ== 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 :message-id:date:subject:cc:to:from; bh=Jo3Il1OX0uvlJKqWzFLZUSl6HdDmicVZptGgGc1o61Y=; b=s65LKodZhmJXNYjIZ55ecl4eI+vmza4ODYRakIXcMqm/4bi2/BMKP0OeXU7pA4BzQH tCcloABQlJWwdu8d7emWJkkOiYBobUuU9skJDkXPEik8QlXRUhD13DUzB+fGOS1iYdDq a/DtBo4iNFAoZAezsaR0lM61OhZrd5zBfeWjQq7CKE+/syFEgCpC08J/xxCLm79jonwV cz0Q9otlRXcLkuME0hwRud9j1JGajwVKcY52jTewJRJ7oOpdjwaLLbVecNg3+8SJtONk WSTSoN9ROpkL7X2hU8YAcgV5nmWQGqWxDUvepD18b4gBAGovyMXxJraPS7lNOk0z8v3Q wf4Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si4716322edp.82.2021.01.09.00.03.32; Sat, 09 Jan 2021 00:03:55 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbhAIICw (ORCPT + 99 others); Sat, 9 Jan 2021 03:02:52 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10124 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbhAIICv (ORCPT ); Sat, 9 Jan 2021 03:02:51 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DCXTy6Dv0z15pfS; Sat, 9 Jan 2021 16:01:10 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Sat, 9 Jan 2021 16:02:00 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH] mm: Fix potential pte_unmap_unlock pte error Date: Sat, 9 Jan 2021 03:01:18 -0500 Message-ID: <20210109080118.20885-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit 42e4089c7890 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings"), when the first pfn modify is not allowed, we would break the loop with pte unchanged. Then the wrong pte - 1 would be passed to pte_unmap_unlock. Fixes: 42e4089c789 ("x86/speculation/l1tf: Disallow non privileged high MMIO PROT_NONE mappings") Signed-off-by: Hongxiang Lou Signed-off-by: Miaohe Lin Cc: stable@kernel.org --- mm/memory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index feff48e1465a..351b78ebd5a4 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2165,11 +2165,11 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd, unsigned long addr, unsigned long end, unsigned long pfn, pgprot_t prot) { - pte_t *pte; + pte_t *pte, *mapped_pte; spinlock_t *ptl; int err = 0; - pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); + mapped_pte = pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); if (!pte) return -ENOMEM; arch_enter_lazy_mmu_mode(); @@ -2183,7 +2183,7 @@ static int remap_pte_range(struct mm_struct *mm, pmd_t *pmd, pfn++; } while (pte++, addr += PAGE_SIZE, addr != end); arch_leave_lazy_mmu_mode(); - pte_unmap_unlock(pte - 1, ptl); + pte_unmap_unlock(mapped_pte, ptl); return err; } -- 2.19.1