Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp847201ybe; Wed, 11 Sep 2019 05:46:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwX+w5lww+OjgxJW90Jr9nBiKE9xEnuGUbh3qUpPYnZpjZLdm88eEtCyrYfJv49rs+Dkkcd X-Received: by 2002:a17:906:6dc2:: with SMTP id j2mr16824689ejt.268.1568205965418; Wed, 11 Sep 2019 05:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568205965; cv=none; d=google.com; s=arc-20160816; b=vCxKgFNYmhsoTuipIL4zemRiw1Hjm0rwgAZK1Z1SnySTO+eko3BHmThSGqbiI+ka3u fOmTrZ/eH0Uau9Sp6s3fSBxOiDMahqx3FzKe8zJatXitRCWvslN+3F00yAQU99Fj1fax vhagozLR6KKItvamhskMHBwxl5BMdEdZyYg5ePNAMxL9hM4u8rtVU5TuR418AYNPVa2R QhNhAKsWWW7rxJlVwhHdd578Bz6hnjofpaUCpE3FZA1OSng1236x77zRTzaUDfU7o/Uo cy2rtnCLUes7J0MYrk/GDCFmFh8olti9OT6beztw+dNnmOfz0zw/AuybStyyFKE9Dgya rZKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rqso4fn8gbPwol7Jjx1bkE38+XmQTMDBGsBsgpxbF10=; b=eXWq8M7NnOGVVzm5yaskfL8VSoG/AxP8W5GoZCGZys3aXcQjp+3xZoa0QEH3pE+VLD wx1yW3ARRWSFTM9Iiy8nG77ZOXQUWuRcVWfs26+1xrWtmAo1VD28H37w0/vxhNRss8Xt t2mReC4Ap1qQPGb1U6HkfaRRpVwbv5zsvFNCQzaiYx57n3nd2C6HYUaQVvAjPubfk7wz VTVCLACnMHsGSR4h+vC+Ncg/5B106qNfXg13o2sgAxLQba0rYzhR6cCdj2NBGoDV5A2p +lnETdypYFBp8bsUAob1DCBGzrBX2FbilL9G6nNSDCgjdd+I0rjbodV21ET1cc/AQxWG 2xCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=UVq8ZG1m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id um4si11324585ejb.268.2019.09.11.05.45.40; Wed, 11 Sep 2019 05:46:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@shipmail.org header.s=mail header.b=UVq8ZG1m; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727945AbfIKMkn (ORCPT + 99 others); Wed, 11 Sep 2019 08:40:43 -0400 Received: from pio-pvt-msa2.bahnhof.se ([79.136.2.41]:35304 "EHLO pio-pvt-msa2.bahnhof.se" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726928AbfIKMkm (ORCPT ); Wed, 11 Sep 2019 08:40:42 -0400 Received: from localhost (localhost [127.0.0.1]) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTP id E47373F4B9; Wed, 11 Sep 2019 14:40:34 +0200 (CEST) Authentication-Results: pio-pvt-msa2.bahnhof.se; dkim=pass (1024-bit key; unprotected) header.d=shipmail.org header.i=@shipmail.org header.b=UVq8ZG1m; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at bahnhof.se X-Spam-Flag: NO X-Spam-Score: -2.099 X-Spam-Level: X-Spam-Status: No, score=-2.099 tagged_above=-999 required=6.31 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Received: from pio-pvt-msa2.bahnhof.se ([127.0.0.1]) by localhost (pio-pvt-msa2.bahnhof.se [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Rh--3oeQzsSf; Wed, 11 Sep 2019 14:40:34 +0200 (CEST) Received: from mail1.shipmail.org (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) (Authenticated sender: mb878879) by pio-pvt-msa2.bahnhof.se (Postfix) with ESMTPA id 8B86A3F40C; Wed, 11 Sep 2019 14:40:30 +0200 (CEST) Received: from localhost.localdomain.localdomain (h-205-35.A357.priv.bahnhof.se [155.4.205.35]) by mail1.shipmail.org (Postfix) with ESMTPSA id C74E03602AF; Wed, 11 Sep 2019 14:40:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=shipmail.org; s=mail; t=1568205629; bh=HCfXSiSlYFFQuEbgg0fd/Beb1ygPT33Fwve4O2CKjik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVq8ZG1mdRJ99zzTOa06A0WCSmICDeoA923j5vpbwF/96VtBbpv21b0xS9KOXmUxU CZYlvPug27fuPUPo2quSq8QxEevm7/jjfCLHMcefeyneRdAjeSbqieiJ4IhDGZ6CYe N4djwYRPtK8N62+7Rm2l53dYNwk+1Fd85cPkJAO0= From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= To: linux-kernel@vger.kernel.org Cc: pv-drivers@vmware.com, linux-graphics-maintainer@vmware.com, x86@kernel.org, Thomas Hellstrom , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Christoph Hellwig , =?UTF-8?q?Christian=20K=C3=B6nig?= , Marek Szyprowski , Tom Lendacky Subject: [PATCH v2 1/2] x86: Don't let pgprot_modify() change the page encryption bit Date: Wed, 11 Sep 2019 14:40:21 +0200 Message-Id: <20190911124022.22423-2-thomas_os@shipmail.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190911124022.22423-1-thomas_os@shipmail.org> References: <20190911124022.22423-1-thomas_os@shipmail.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Hellstrom When SEV or SME is enabled and active, vm_get_page_prot() typically returns with the encryption bit set. This means that users of pgprot_modify(, vm_get_page_prot()) (mprotect_fixup, do_mmap) end up with a value of vma->vm_pg_prot that is not consistent with the intended protection of the PTEs. This is also important for fault handlers that rely on the VMA vm_page_prot to set the page protection. Fix this by not allowing pgprot_modify() to change the encryption bit, similar to how it's done for PAT bits. Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Christoph Hellwig Cc: Christian König Cc: Marek Szyprowski Cc: Tom Lendacky Signed-off-by: Thomas Hellstrom --- arch/x86/include/asm/pgtable.h | 7 +++++-- arch/x86/include/asm/pgtable_types.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 0bc530c4eb13..1e6bb4c25334 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -624,12 +624,15 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot) return __pmd(val); } -/* mprotect needs to preserve PAT bits when updating vm_page_prot */ +/* + * mprotect needs to preserve PAT and encryption bits when updating + * vm_page_prot + */ #define pgprot_modify pgprot_modify static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) { pgprotval_t preservebits = pgprot_val(oldprot) & _PAGE_CHG_MASK; - pgprotval_t addbits = pgprot_val(newprot); + pgprotval_t addbits = pgprot_val(newprot) & ~_PAGE_CHG_MASK; return __pgprot(preservebits | addbits); } diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index b5e49e6bac63..e13084b3d6cb 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -123,7 +123,7 @@ */ #define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP) + _PAGE_SOFT_DIRTY | _PAGE_DEVMAP | sme_me_mask) #define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE) /* -- 2.20.1