linux-hardening.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: jeffxu@chromium.org
To: dave.hansen@intel.com, luto@kernel.org, jorgelo@chromium.org,
	keescook@chromium.org, groeck@chromium.org, jannh@google.com,
	sroettger@google.com
Cc: akpm@linux-foundation.org, jeffxu@google.com,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-mm@kvack.org, linux-hardening@vger.kernel.org
Subject: [PATCH v1 3/6] PKEY: Apply PKEY_ENFORCE_API to mprotect
Date: Fri, 19 May 2023 01:19:11 +0000	[thread overview]
Message-ID: <20230519011915.846407-4-jeffxu@chromium.org> (raw)
In-Reply-To: <20230519011915.846407-1-jeffxu@chromium.org>

From: Jeff Xu <jeffxu@google.com>

This patch enables PKEY_ENFORCE_API for the mprotect and
mprotect_pkey syscalls.

Signed-off-by: Jeff Xu<jeffxu@google.com>
---
 mm/mprotect.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/mm/mprotect.c b/mm/mprotect.c
index 8a68fdca8487..1db30b8baac3 100644
--- a/mm/mprotect.c
+++ b/mm/mprotect.c
@@ -794,6 +794,17 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
 		}
 	}
 
+	/*
+	 * arch_check_pkey_enforce_api checks if current thread
+	 * has the PKEY permission to modify the memory mapping.
+	 * Note: this should only apply to the cases that do_mprotect_pkey
+	 * is called from syscall entry. Ref. to munmap for other cases.
+	 */
+	if (arch_check_pkey_enforce_api(current->mm, start, end) < 0) {
+		error = -EACCES;
+		goto out;
+	}
+
 	prev = vma_prev(&vmi);
 	if (start > vma->vm_start)
 		prev = vma;
-- 
2.40.1.606.ga4b1b128d6-goog


  parent reply	other threads:[~2023-05-19  1:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19  1:19 [PATCH v1 0/6] Memory Mapping (VMA) protection using PKU - set 1 jeffxu
2023-05-19  1:19 ` [PATCH v1 1/6] PKEY: Introduce PKEY_ENFORCE_API flag jeffxu
2023-05-19  1:19 ` [PATCH v1 2/6] PKEY: Add arch_check_pkey_enforce_api() jeffxu
2023-05-19  1:19 ` jeffxu [this message]
2023-05-19  1:19 ` [PATCH v1 4/6] PKEY:selftest pkey_enforce_api for mprotect jeffxu
2023-05-30  9:32   ` kernel test robot
2023-05-19  1:19 ` [PATCH v1 5/6] PKEY: Apply PKEY_ENFORCE_API to munmap jeffxu
2023-05-19  1:19 ` [PATCH v1 6/6] PKEY:selftest pkey_enforce_api for munmap jeffxu
2023-05-19  1:21 ` [PATCH v1 0/6] Memory Mapping (VMA) protection using PKU - set 1 Jeff Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519011915.846407-4-jeffxu@chromium.org \
    --to=jeffxu@chromium.org \
    --cc=akpm@linux-foundation.org \
    --cc=dave.hansen@intel.com \
    --cc=groeck@chromium.org \
    --cc=jannh@google.com \
    --cc=jeffxu@google.com \
    --cc=jorgelo@chromium.org \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=sroettger@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).