Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1556529ybv; Sun, 23 Feb 2020 09:28:07 -0800 (PST) X-Google-Smtp-Source: APXvYqwpUcJJBuU+g1bColCNHOjx9Ar9IOkbn4EQr1TTgDSdLHz47tbBokpq775iPEJDEEjl+dtu X-Received: by 2002:a54:4895:: with SMTP id r21mr10148661oic.107.1582478887634; Sun, 23 Feb 2020 09:28:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582478887; cv=none; d=google.com; s=arc-20160816; b=bgKyZbAzJ1WeUHh9ilr2818sBDvyU4/8rVo2DqmYSaAE/Lqs+A+SghIHQSZeJOJ/Xp xllvwBmaHb0oG/fX1AdpRZiGpW7u9adivrt/bl3aqW8JrxQJunp5e80XXW73ld3ibeaH jTaanSHZv+3/28ZqiIQwp38GJx+g9E9yvTj4ADO2RUbCEU75+OSYCSfMcvP3A9c4KUQR lzKLBr9fCwTcS6mwAE3DwlgwCzqB1bmGNvisVYRXicMFDwbK2XW062WJF8yb4ffVn3kx iWXcJ7BHP7laiFujcRmxgfuJLIiLMlZd/Gnmf35EXBgJ3DN4LkNcsDd64zT7r//cT0R5 53Hg== 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=EopAvJihj9hR9QSelvyacy80JVP0+vyNeNdf+tq9m0A=; b=GgxkylKHKmC4kpwRPm4upqz+wnWhwFqPIxZxvXpCYwwjIpqJogZBty5oNc1sFaJbUV WxlV2WPeuSmiCqwT2+/X+hJ5zhNyC0iX6W5BO7D7SE8aOf2IEdUbPV/BWascaBW7EdcE Ew/BpUnwCwSCEwGpEg3t8liBvja1gjjZd6djHmzXwwGDEHCIwTw7MiYicO9FLLakzJ2z IYXiQEc7TprgdRWKqrWeM4Kouk/tD8rsRJub0ARP3pFTRZvf/jyWizadviTRX0RpOAc6 hj46DZhMJBQr+q5P5aBhp+N4hNLfXwEfj5SrB7bycCdlJdidXiNkxXw5xWt2RNtu80sL 5FqA== 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 a14si5570841otk.2.2020.02.23.09.27.56; Sun, 23 Feb 2020 09:28:07 -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 S1727278AbgBWR11 (ORCPT + 99 others); Sun, 23 Feb 2020 12:27:27 -0500 Received: from mga12.intel.com ([192.55.52.136]:10522 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726933AbgBWR10 (ORCPT ); Sun, 23 Feb 2020 12:27:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Feb 2020 09:27:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,476,1574150400"; d="scan'208";a="229650145" Received: from ajbergin-mobl.ger.corp.intel.com (HELO localhost) ([10.252.23.203]) by fmsmga007.fm.intel.com with ESMTP; 23 Feb 2020 09:27:18 -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 v27 09/22] mm: Introduce vm_ops->may_mprotect() Date: Sun, 23 Feb 2020 19:25:46 +0200 Message-Id: <20200223172559.6912-10-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200223172559.6912-1-jarkko.sakkinen@linux.intel.com> References: <20200223172559.6912-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.20.1