Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp109126ybk; Thu, 14 May 2020 17:49:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6jbsqs+H8+imE2gAgQMaCZdII9qYWSEg9XbWtBAzSwJHqvOSs7lAbZG2ixoTW3HOFsJTL X-Received: by 2002:a17:906:f103:: with SMTP id gv3mr601084ejb.226.1589503763683; Thu, 14 May 2020 17:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589503763; cv=none; d=google.com; s=arc-20160816; b=O2rEj/6qUhsBdCyvjLuRGVNhH2mnQXQaS6yEGZXbTzS23fji3nxmElhSLxRG1Uo9ub EHfVVlTiAWkxAiXsLmrrre+jS49BbRdPDnj2waAt0AB9txUsnmDcST1gw1DDWjJy6JoV enJnqqfKdeFdhx8015TzXVIVsXIuzB/4KbJj+DeuVZSFPwxMMopwALwSp+FLl9KW+iYn on87qNJ4C6KbwrEXRdGjcVOU+53bZuSv35o2f93svBx8K8P3A9BphcJCVe8sRe+0ubVo 0yEjaKxppWLsyfAcr8plA6Xh7F9wG69i/lQvhxKxi9xURsxgho0IkAO5j78vqaJpPYft 7xEw== 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 :ironport-sdr:ironport-sdr; bh=zA0r3EFpwiQzMSp22fziHCMijVhzVWffm91lzm8hygQ=; b=U+b8P6fozxQQvhwEcIQeL9H5q/1QScPWjQFHPoMP+yLAwclNlbIhnpRNsycqsv9eyk xoMNEe/y6ElspOGPlw2fG0G+ToSpoOIooBy7h1WLKfT7YefS6JR9JUjUCIDb51xzy2Fg 5L3kYHjKKDgrQ7HfafE3ktQf9UjnjlyLvvRY7W7Qq0scpb7wUorwd4BGhVO20GXX61wm jY/53m/XjKYDpzxhtYqpvvRKBSyYJNGbuWI0Svfk38RKEqlZSL1VZ3OYLUIWnQFTwLcd xCcyCbsKsK5RAn/fgoRAGu1P+ICoJ2xHP6UUWtVNAgWTOZ+8obyy17sUveAzdf12mx25 ZALA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id s3si232901edq.467.2020.05.14.17.49.01; Thu, 14 May 2020 17:49:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728768AbgEOApy (ORCPT + 99 others); Thu, 14 May 2020 20:45:54 -0400 Received: from mga04.intel.com ([192.55.52.120]:44619 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726170AbgEOApx (ORCPT ); Thu, 14 May 2020 20:45:53 -0400 IronPort-SDR: yA8GHZaXQ03esXhBLAn7ehrNxcwCweavzpNIiAnzh5R9iy44DY1DjcgahCLivwL1CcEt35sbxP KHaaZPL0gagg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2020 17:45:52 -0700 IronPort-SDR: 6vwB3z44MgpBrcpqO/AB/BLxmqW4r6CLWxvt793HZ7JFIrujYrgEWhMI17RZaVQGuGrB3Af/N6 m0ObU+2hDaMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,393,1583222400"; d="scan'208";a="253644211" Received: from ashadrin-mobl1.ccr.corp.intel.com (HELO localhost) ([10.249.38.112]) by fmsmga008.fm.intel.com with ESMTP; 14 May 2020 17:45:45 -0700 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, Jethro Beekman , Jarkko Sakkinen Subject: [PATCH v30 09/20] mm: Introduce vm_ops->may_mprotect() Date: Fri, 15 May 2020 03:43:59 +0300 Message-Id: <20200515004410.723949-10-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200515004410.723949-1-jarkko.sakkinen@linux.intel.com> References: <20200515004410.723949-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 Acked-by: Jethro Beekman 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 5a323422d783..dbcc2846b3b8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -546,6 +546,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 494192ca954b..079ba92df377 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -603,13 +603,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.1