linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: msync: require either MS_ASYNC or MS_SYNC
@ 2014-04-01 18:25 Richard Hansen
       [not found] ` <533B04A9.6090405-A08e6c8yq/Q@public.gmane.org>
  0 siblings, 1 reply; 17+ messages in thread
From: Richard Hansen @ 2014-04-01 18:25 UTC (permalink / raw)
  To: linux-mm, linux-kernel; +Cc: linux-api, Greg Troxel

For the flags parameter, POSIX says "Either MS_ASYNC or MS_SYNC shall
be specified, but not both." [1]  There was already a test for the
"both" condition.  Add a test to ensure that the caller specified one
of the flags; fail with EINVAL if neither are specified.

Without this change, specifying neither is the same as specifying
flags=MS_ASYNC because nothing in msync() is conditioned on the
MS_ASYNC flag.  This has not always been true, and there's no good
reason to believe that this behavior would have persisted
indefinitely.

The msync(2) man page (as currently written in man-pages.git) is
silent on the behavior if both flags are unset, so this change should
not break an application written by somone who carefully reads the
Linux man pages or the POSIX spec.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/msync.html

Signed-off-by: Richard Hansen <rhansen@bbn.com>
Reported-by: Greg Troxel <gdt@ir.bbn.com>
Reviewed-by: Greg Troxel <gdt@ir.bbn.com>
---

This is a resend of:
http://article.gmane.org/gmane.linux.kernel/1554416
I didn't get any feedback from that submission, so I'm resending it
without changes.

 mm/msync.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/msync.c b/mm/msync.c
index 632df45..472ad3e 100644
--- a/mm/msync.c
+++ b/mm/msync.c
@@ -42,6 +42,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t,
len, int, flags)
 		goto out;
 	if ((flags & MS_ASYNC) && (flags & MS_SYNC))
 		goto out;
+	if (!(flags & (MS_ASYNC | MS_SYNC)))
+		goto out;
 	error = -ENOMEM;
 	len = (len + ~PAGE_MASK) & PAGE_MASK;
 	end = start + len;
-- 
1.8.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 17+ messages in thread
* [PATCH] mm: msync: require either MS_ASYNC or MS_SYNC
@ 2013-09-01 19:58 Richard Hansen
  0 siblings, 0 replies; 17+ messages in thread
From: Richard Hansen @ 2013-09-01 19:58 UTC (permalink / raw)
  To: linux-mm, linux-kernel; +Cc: linux-api, Richard Hansen

For the flags parameter, POSIX says "Either MS_ASYNC or MS_SYNC shall
be specified, but not both." [1]  There was already a test for the
"both" condition.  Add a test to ensure that the caller specified one
of the flags; fail with EINVAL if neither are specified.

Without this change, specifying neither is the same as specifying
flags=MS_ASYNC because nothing in msync() is conditioned on the
MS_ASYNC flag.  This has not always been true, and there's no good
reason to believe that this behavior would have persisted
indefinitely.

The msync(2) man page (as currently written in man-pages.git) is
silent on the behavior if both flags are unset, so this change should
not break an application written by somone who carefully reads the
Linux man pages or the POSIX spec.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/msync.html

Signed-off-by: Richard Hansen <rhansen@bbn.com>
Reported-by: Greg Troxel <gdt@ir.bbn.com>
Reviewed-by: Greg Troxel <gdt@ir.bbn.com>
---
 mm/msync.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/msync.c b/mm/msync.c
index 632df45..472ad3e 100644
--- a/mm/msync.c
+++ b/mm/msync.c
@@ -42,6 +42,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
 		goto out;
 	if ((flags & MS_ASYNC) && (flags & MS_SYNC))
 		goto out;
+	if (!(flags & (MS_ASYNC | MS_SYNC)))
+		goto out;
 	error = -ENOMEM;
 	len = (len + ~PAGE_MASK) & PAGE_MASK;
 	end = start + len;
-- 
1.8.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-04-04 14:07 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 18:25 [PATCH] mm: msync: require either MS_ASYNC or MS_SYNC Richard Hansen
     [not found] ` <533B04A9.6090405-A08e6c8yq/Q@public.gmane.org>
2014-04-01 19:32   ` Michael Kerrisk (man-pages)
2014-04-02  0:53     ` Richard Hansen
     [not found]     ` <533B1439.3010403-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-04-02 10:45       ` chrubis-AlSwsSmVLrQ
2014-04-02 11:10   ` Christoph Hellwig
     [not found]     ` <20140402111032.GA27551-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2014-04-02 11:45       ` Steven Whitehouse
2014-04-02 23:44         ` Richard Hansen
2014-04-03  8:25           ` Michael Kerrisk (man-pages)
2014-04-03 11:51             ` Christopher Covington
2014-04-04  6:54               ` Michael Kerrisk (man-pages)
2014-04-03 12:57             ` Greg Troxel
2014-04-04  7:11               ` Michael Kerrisk (man-pages)
2014-04-03 20:23             ` Richard Hansen
2014-04-04  6:53               ` Christoph Hellwig
2014-04-04  7:12           ` [PATCH] mm: msync: require either MS_ASYNC or MS_SYNC [resend] Michael Kerrisk (man-pages)
2014-04-04 14:07             ` Peter Zijlstra
  -- strict thread matches above, loose matches on Subject: below --
2013-09-01 19:58 [PATCH] mm: msync: require either MS_ASYNC or MS_SYNC Richard Hansen

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).