All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nils Hartmann <nils1hartmann@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] Using MAP_SHARE_VALIDATE in mmap without fd
Date: Fri, 10 Mar 2023 18:16:17 +0100	[thread overview]
Message-ID: <20230310171617.wqnqs42l2viwjsz5@archlinux> (raw)

Hey,
I have a rather simple question about the MAP_SHARED_VALIDATE flag in mmap.
When used without a file pointer, EINVAL is returned. Is there a reason for this?
I researched a bit but could not find anything. I attached a simple patch that adds MAP_SHARE_VALIDATE to the flags switch and checks for invalid flags.

Signed-off-by: Nils Hartmann <nils1hartmann@gmail.com>
---
 mm/mmap.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mm/mmap.c b/mm/mmap.c
index 740b54be3..fd7db51af 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1196,6 +1196,7 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
 {
 	struct mm_struct *mm = current->mm;
 	vm_flags_t vm_flags;
+	unsigned long flags_mask;
 	int pkey = 0;
 
 	validate_mm(mm);
@@ -1266,14 +1267,14 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
 	if (mlock_future_check(mm, vm_flags, len))
 		return -EAGAIN;
 
+	flags_mask = LEGACY_MAP_MASK;
 	if (file) {
 		struct inode *inode = file_inode(file);
-		unsigned long flags_mask;
 
 		if (!file_mmap_ok(file, inode, pgoff, len))
 			return -EOVERFLOW;
 
-		flags_mask = LEGACY_MAP_MASK | file->f_op->mmap_supported_flags;
+		flags_mask |= file->f_op->mmap_supported_flags;
 
 		switch (flags & MAP_TYPE) {
 		case MAP_SHARED:
@@ -1327,6 +1328,10 @@ unsigned long do_mmap(struct file *file, unsigned long addr,
 		}
 	} else {
 		switch (flags & MAP_TYPE) {
+		case MAP_SHARED_VALIDATE:
+			if (flags & ~flags_mask)
+				return -EOPNOTSUPP;
+			fallthrough;
 		case MAP_SHARED:
 			if (vm_flags & (VM_GROWSDOWN|VM_GROWSUP))
 				return -EINVAL;
-- 
2.39.2


             reply	other threads:[~2023-03-10 17:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-10 17:16 Nils Hartmann [this message]
2023-03-16 15:28 ` [PATCH] Using MAP_SHARE_VALIDATE in mmap without fd David Hildenbrand
2023-03-16 19:16   ` Nils Hartmann

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=20230310171617.wqnqs42l2viwjsz5@archlinux \
    --to=nils1hartmann@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.