Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3912053ybf; Tue, 3 Mar 2020 15:39:01 -0800 (PST) X-Google-Smtp-Source: ADFU+vvKcnikEIszRdfhWSNSUnO++OEtC5ZhXhJ9q4BjIBC0xC77PNZEKmsV7RBhn9M/wwsx+STE X-Received: by 2002:a9d:7c9a:: with SMTP id q26mr291559otn.206.1583278741586; Tue, 03 Mar 2020 15:39:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583278741; cv=none; d=google.com; s=arc-20160816; b=CHp8vt9lIf0h3jbjota/N+R3ieEbY4tGtyM8ggZWh8QAFsM98+ECpYi4YZrMZ9w0un bQa//o1BuX8OUHA7KlRIVkZlXh+8FY5qPdyySoGeIZKI0ZbBan8J2EGSGBuBBVmhDiXK 13oL/+yKqe3P1aeho2HRuoeBTFzZuf/HVQ8PgYvjEQrAS/pfDC465de/yd9XlwDDr2EF i9sPD/z3EufPr/Cc5PIgZ9rUPOy0QknYxHj9Mf4yVQ2e58ayqVDsQJw+92Tt43h7KMkE ZkPOchFiHvnhHHBio6pihyuPljJVe+bL2gFFATb7zE+08AV00NkqvBXiOQoqTSD0jqBL jx4g== 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; bh=KzBGnmojFfLNAo6EXgP5FMMUs3gunLUEQb5rsbtqXTg=; b=g7mJvkR91/NxoffLYpPJ2CVKNv6aiZLI+zVQ9aBrfCKDI7GWPZu264l33NtOo3VK3t 8Q4whGkFRkLeJleY88ZSoC7O64d2bTWcioS6Qhegv7ezPsDmxJGG/+2qU7jwVCz71sMT ITOF7jncVjAeWs/1yEVY6+XiCUyf1qNZ7vvdseQbeklP/q/Aq9rMJurw58SUKEtVV4Zx dXV+HH+y6eidRhSNzIHDWmfhbMULS/2Bp/KC0Awwpp8dCjE3VlyctCgpSgJTrj5FoHkx Yh2Fxz6C4AS73XIKjIZLfYXAyo6r8lBVbnXaQ418CJQS0QaGUD3faY5p+ckToC3iZdCj 1aVg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si153852oic.126.2020.03.03.15.38.49; Tue, 03 Mar 2020 15:39:01 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728499AbgCCXiT (ORCPT + 99 others); Tue, 3 Mar 2020 18:38:19 -0500 Received: from mga18.intel.com ([134.134.136.126]:46749 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728387AbgCCXiT (ORCPT ); Tue, 3 Mar 2020 18:38:19 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2020 15:38:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,511,1574150400"; d="scan'208";a="229117511" Received: from kwasilew-mobl.ger.corp.intel.com (HELO localhost) ([10.251.88.57]) by orsmga007.jf.intel.com with ESMTP; 03 Mar 2020 15:38:08 -0800 From: Jarkko Sakkinen To: linux-kernel@vger.kernel.org, x86@kernel.org, linux-sgx@vger.kernel.org Cc: akpm@linux-foundation.org, dave.hansen@intel.com, sean.j.christopherson@intel.com, nhorman@redhat.com, npmccallum@redhat.com, haitao.huang@intel.com, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kai.svahn@intel.com, bp@alien8.de, josh@joshtriplett.org, luto@kernel.org, kai.huang@intel.com, rientjes@google.com, cedric.xing@intel.com, puiterwijk@redhat.com, Jarkko Sakkinen Subject: [PATCH v28 10/22] mm: Introduce vm_ops->may_mprotect() Date: Wed, 4 Mar 2020 01:35:57 +0200 Message-Id: <20200303233609.713348-11-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200303233609.713348-1-jarkko.sakkinen@linux.intel.com> References: <20200303233609.713348-1-jarkko.sakkinen@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: Sean Christopherson Add vm_ops()->may_mprotect() to check additional constrains set by a subsystem for a mprotect() call. Signed-off-by: Sean Christopherson Signed-off-by: Jarkko Sakkinen --- include/linux/mm.h | 2 ++ mm/mprotect.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 52269e56c514..ad08eb666e1c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -464,6 +464,8 @@ struct vm_operations_struct { void (*close)(struct vm_area_struct * area); int (*split)(struct vm_area_struct * area, unsigned long addr); int (*mremap)(struct vm_area_struct * area); + int (*may_mprotect)(struct vm_area_struct *vma, unsigned long start, + unsigned long end, unsigned long prot); vm_fault_t (*fault)(struct vm_fault *vmf); vm_fault_t (*huge_fault)(struct vm_fault *vmf, enum page_entry_size pe_size); diff --git a/mm/mprotect.c b/mm/mprotect.c index 7a8e84f86831..c0cb40e23b43 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -543,13 +543,21 @@ static int do_mprotect_pkey(unsigned long start, size_t len, goto out; } + tmp = vma->vm_end; + if (tmp > end) + tmp = end; + + if (vma->vm_ops && vma->vm_ops->may_mprotect) { + error = vma->vm_ops->may_mprotect(vma, nstart, tmp, + prot); + if (error) + goto out; + } + error = security_file_mprotect(vma, reqprot, prot); if (error) goto out; - tmp = vma->vm_end; - if (tmp > end) - tmp = end; error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); if (error) goto out; -- 2.25.0