From patchwork Fri Sep 7 22:37:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 10592673 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4862B14E2 for ; Fri, 7 Sep 2018 22:37:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392C6292AC for ; Fri, 7 Sep 2018 22:37:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D2362B2D7; Fri, 7 Sep 2018 22:37:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7284292AC for ; Fri, 7 Sep 2018 22:37:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E7EC48E000B; Fri, 7 Sep 2018 18:37:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E2E028E0001; Fri, 7 Sep 2018 18:37:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D44638E000B; Fri, 7 Sep 2018 18:37:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id 94A8C8E0001 for ; Fri, 7 Sep 2018 18:37:10 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id q12-v6so7806544pgp.6 for ; Fri, 07 Sep 2018 15:37:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:message-id:references:mime-version:content-disposition :in-reply-to:user-agent; bh=A5x5XokmuH1R9NwOMy59/ZYYO2rruoY7j9Ea4JgpN8g=; b=rmay89rspP3PfR+Mexkot+Z5w00AEfTzBEESIPiN4lO5BNeoCzP55Bm+QXrO79i/GG QNMwYxWiMSU8B1zgIMKW3bNApIgxDpRdjkWMEENZkMX6KI5H6hC8AxqBkUpTDy6J55AZ rLfvDd0vbhaNHp85eCm1HHTSWPiTuR5LGjViW5RCI8bflOrc9us/I1F2IZoLrJk29+KS rxEpt8D85blsYPcXRxXRpRTVlrBl17EUIyngTQyhXLPyhBwm3Dv8/gjH+ZLgoC09pTk8 y0pNc/F9zLAzEBxP2pImVG+lK+bPhbEDky01MHdP734VJBSk+GdUk9A3AmTqN594gVas 2A1w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APzg51DQ4UW3EKsQ77fdtCGspEgmoCJlLw+eGbtvORF8D00LeVivaTKX od35jVeLlyzYeSTw5F0ZLumJwYIxAICfWrElOwE4q9p8xBhK3VbIAwJrS6T441tJAj+/v4ALRxs q7prej/LD887diCMtVPWz7VTXwfGjiXpNW+1L1O5nxsUS+acn5TpPTqjL+OIWHaqBnA== X-Received: by 2002:a63:344b:: with SMTP id b72-v6mr10586684pga.184.1536359830296; Fri, 07 Sep 2018 15:37:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbbRnu2/n0skRywCDKwb1s3q6bU6vQv06mF10UyI0i42Mvqub5sQq5oNsfG82Y9kFUQfbOo X-Received: by 2002:a63:344b:: with SMTP id b72-v6mr10586645pga.184.1536359829550; Fri, 07 Sep 2018 15:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536359829; cv=none; d=google.com; s=arc-20160816; b=KqUZ54s69CxE2iQsz5eEB2h4SctT7hC0sURtVvMvpFx59qczKI35h2iuM4smh/ASvM 9q824FIjJ9nTPNi5UxuU8HBG/ehag2uW7ogRfXtRd7+2FD8ZsZdpus2SqG2/OO8Tttnh 2/ZuJiSvs4TBDyGDNopuM9moyJW/iadQjqiwSCi10kr10HAlfJSgJX5wrHLxXrjLPzL+ go5mCEe5N2ZDuzsxISUyTzVPLtyuZ8dihCoWIyNPLOBeRRT2b0+r6OLtW3pkroWUG4uX 3X82jBpr/bRCC2L2M6kv/32X8UsAzzUCO0tYDnbYh93O11yvkDd1QVy08D0SfsqsIlzJ 40FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date; bh=A5x5XokmuH1R9NwOMy59/ZYYO2rruoY7j9Ea4JgpN8g=; b=LOZo8DoYo1NmCzbGPbhHp+fuLevVeijzYDqoVZL3+gjv90sYsKiWx2rSKvNw6oeZvu e7dV6YmE0vOxcooSV01xrxcaOPiZBDMHmAIz+Jw8Wb8+gN1xc6ctimxET3BX3W8Ahr0S hVr8b7wxbB56EJAmJyVz6A5KGyDhi/5IZR1WfYfDznp7atTJmKVxi+xqIv7JFKpErexL eQWaL26RoS/dt0zzeYXNSZZ7P/aTHPsSYFtzo2r2+75jy3O1JH87xWQ9xl2IjuPYX7eq ZPnj+QPE4kO/Et+RaNXLzcIUkLLCW7LNZzp/4mnnx4MHA7M9l/8Y0L1sfe+tYmE3xz/y Zclw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga09.intel.com (mga09.intel.com. [134.134.136.24]) by mx.google.com with ESMTPS id f40-v6si9484448plb.504.2018.09.07.15.37.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Sep 2018 15:37:09 -0700 (PDT) Received-SPF: pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.24 as permitted sender) client-ip=134.134.136.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 134.134.136.24 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Sep 2018 15:37:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,344,1531810800"; d="scan'208";a="89921676" Received: from alison-desk.jf.intel.com ([10.54.74.53]) by orsmga002.jf.intel.com with ESMTP; 07 Sep 2018 15:37:09 -0700 Date: Fri, 7 Sep 2018 15:37:51 -0700 From: Alison Schofield To: dhowells@redhat.com, tglx@linutronix.de Cc: Kai Huang , Jun Nakajima , Kirill Shutemov , Dave Hansen , Jarkko Sakkinen , jmorris@namei.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, linux-mm@kvack.org Subject: [RFC 09/12] mm: Restrict memory encryption to anonymous VMA's Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Memory encryption is only supported for mappings that are ANONYMOUS. Test the entire range of 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 --- mm/mprotect.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 6c2e1106525c..3384b755aad1 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -311,6 +311,24 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start, return pages; } +/* + * Encrypted mprotect is only supported on anonymous mappings. + * All VMA's in the requested range must be anonymous. If this + * test fails on any single VMA, the entire mprotect request fails. + */ +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, @@ -491,6 +509,10 @@ 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;