Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6109183ybi; Wed, 31 Jul 2019 08:29:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqy2RpQPGfkBIx9z9a8q+yL9JDr2cdgQu4+4GT9v5sGOXW9aq4hudN4L98WTzBm0rRqqzoJ9 X-Received: by 2002:a63:d30f:: with SMTP id b15mr113332332pgg.341.1564586963833; Wed, 31 Jul 2019 08:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564586963; cv=none; d=google.com; s=arc-20160816; b=ngD8elxtFrKqOexILPpjWOXNVgGW/J40ho15NiDQXtDQTZZpFIWF1lrw10WfUu+WDO vKoHlA6K2MmGBPQNp/njeyWF3Elfvj/5KpyMXSsgzMgeoMVSf4wytZ+tboPoLCa16yvF Cu3SBOmkMRtOtKRFry+pJikAvXkKVy4tQDvILWL7PRD0FFi2xAKwIF58UpcrF1h1tTK3 kffRty5ESCH2yqYgbbwSAZ383q39NYvzeFd2LH82wz1XrOtMOjt4QXxNhtFpV0Xb9hSD 9J0txEwIfT+rawzFdICBSlZdNVYesivyL3E0XxUg2QEJMPBZd2jO1Svj5yUSC0SIyuus DtLw== 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=dXgFqK9tRsaes8xbX8jlTX0gUbPqQYtilIkdLoU6CY4=; b=xXpRmiQqiAgj3YLkjkxSPTZfqLQ4naNyNhnrhpAN5kLz3Wn8VUYeYukICmEY29z5OQ eSLWSmG72ZLmcVcvWMM0BVy3L2Nn3itnEqvNw/+eXJ1rEK0NF7uZBannf10eMQOke6oR uYWSYM60UAra81pdUNy3+6q2z3/wFFHwrE/h28Yedtz1Czc6ICCnq+fhyFflK+kw93E+ 00HeyEFpKsO3hWLV2YY92lYIL0vzTbpfrT8O3My9nO96AxJkETVB6NCQjBFzsmZNCxtf om0w1PoXO/7q2p3YiyfuD9JcK+yA9L/O4pRe2GvEpnMOfccJdcXpW6ecoAhe8LCVBr3o ZZWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b="D/xOlMhr"; 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 b5si34424127pgi.324.2019.07.31.08.29.08; Wed, 31 Jul 2019 08:29:23 -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=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b="D/xOlMhr"; 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 S1729782AbfGaPTz (ORCPT + 99 others); Wed, 31 Jul 2019 11:19:55 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39569 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729708AbfGaPTu (ORCPT ); Wed, 31 Jul 2019 11:19:50 -0400 Received: by mail-ed1-f68.google.com with SMTP id m10so66045131edv.6 for ; Wed, 31 Jul 2019 08:19:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dXgFqK9tRsaes8xbX8jlTX0gUbPqQYtilIkdLoU6CY4=; b=D/xOlMhrdU0ZyN8+we4kbni7hHuGIfv/4U4Ig0LX9ewfIEajz0z1lI9iS5QnH6yCat sfE6Wxgj7gCcNgGeO8sqZDkOENTjXyGaq0eGqLegmkmODaaLkPBU23YDdAqvq4s4OSxZ N0A8Q4QWYpmDkk2dAzVYUHeLTCw2YmNW5FYuyTsyMmseshWxSznRJue51TmL0r+h8LG/ vb4cNBRmMjzUCNNogPHi3S31sph/SJ/M4uXMSstfF9OC/trKRR9pDG2nUWbNR9Ymsx50 ScB2FK2fZENk5csdIp1g+R48LmIGH0MJ/LiEr5bfor9Gh3Un92wYv/649p99ZIJ8QAGO S6YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dXgFqK9tRsaes8xbX8jlTX0gUbPqQYtilIkdLoU6CY4=; b=It787u3pxfm8e0YvvFz/M1H7HUgrh3ahJuUe/lGiz2arKWdtRkbWL+aCvdlKL21GcR 8vjpmpnvEzsM3lYHfPDrW8VWh81DWCAoLFuoP+hKpW96qfzEGPUYczUUXi/8bwJUteov tb8rIGS4+PA/dPvuMxytF954LiwvXwglMw8xpVWBgH8h8j6hbRebFsozJViewUz4wfpL iUs91/YV2v+yipHgE/duJ+vtwcaModl/3utBnIuVtsWeHXRf4R31P/QBwsrwzpZefXVm t5ZBp+iE37bxVUwXH9Au+l/NOl4HemJ9jKqDT8kcChTXTi6FS9igd7sSR+XzpzWRdT9i IA/Q== X-Gm-Message-State: APjAAAVwBo9Q+ErtuQryby+IVgfEjxFtzjVXb0kkcBOm9QSKxh3CVZ1/ NuAWThMEDpl9znjUiC0lmM8= X-Received: by 2002:a50:a485:: with SMTP id w5mr108547875edb.277.1564586038641; Wed, 31 Jul 2019 08:13:58 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id i8sm17219860edg.12.2019.07.31.08.13.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jul 2019 08:13:57 -0700 (PDT) From: "Kirill A. Shutemov" X-Google-Original-From: "Kirill A. Shutemov" Received: by box.localdomain (Postfix, from userid 1000) id 3A5C3104604; Wed, 31 Jul 2019 18:08:17 +0300 (+03) To: Andrew Morton , x86@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Borislav Petkov , Peter Zijlstra , Andy Lutomirski , David Howells Cc: Kees Cook , Dave Hansen , Kai Huang , Jacob Pan , Alison Schofield , linux-mm@kvack.org, kvm@vger.kernel.org, keyrings@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A . Shutemov" Subject: [PATCHv2 46/59] mm: Restrict MKTME memory encryption to anonymous VMAs Date: Wed, 31 Jul 2019 18:08:00 +0300 Message-Id: <20190731150813.26289-47-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> References: <20190731150813.26289-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alison Schofield Memory encryption is only supported for mappings that are ANONYMOUS. Test the VMA's in an encrypt_mprotect() request to make sure they all meet that requirement before encrypting any. The encrypt_mprotect syscall will return -EINVAL and will not encrypt any VMA's if this check fails. Signed-off-by: Alison Schofield Signed-off-by: Kirill A. Shutemov --- mm/mprotect.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 518d75582e7b..4b079e1b2d6f 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -347,6 +347,24 @@ static int prot_none_walk(struct vm_area_struct *vma, unsigned long start, return walk_page_range(start, end, &prot_none_walk); } +/* + * Encrypted mprotect is only supported on anonymous mappings. + * If this test fails on any single VMA, the entire mprotect + * request fails. + */ +static bool mem_supports_encryption(struct vm_area_struct *vma, unsigned long end) +{ + struct vm_area_struct *test_vma = vma; + + do { + if (!vma_is_anonymous(test_vma)) + return false; + + test_vma = test_vma->vm_next; + } while (test_vma && test_vma->vm_start < end); + return true; +} + int mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, unsigned long start, unsigned long end, unsigned long newflags, @@ -533,6 +551,12 @@ static int do_mprotect_ext(unsigned long start, size_t len, goto out; } } + + if (keyid > 0 && !mem_supports_encryption(vma, end)) { + error = -EINVAL; + goto out; + } + if (start > vma->vm_start) prev = vma; -- 2.21.0