From: Eric Wong <normalperson@yhbt.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fadvise: avoid EINVAL if user input is valid
Date: Sat, 25 Feb 2012 02:27:10 +0000 [thread overview]
Message-ID: <20120225022710.GA29455@dcvr.yhbt.net> (raw)
The kernel is not required to act on fadvise, so fail silently
and ignore advice as long as it has a valid descriptor and
parameters.
Cc: linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
Of course I wouldn't knowingly call posix_fadvise() on a file in
tmpfs, but a userspace app often doesn't know (nor should it
care) what type of filesystem it's on.
I encountered EINVAL while running the Ruby 1.9.3 test suite on a
stock Debian wheezy installation. Wheezy uses tmpfs for "/tmp" by
default and the test suite creates a temporary file to test the
Ruby wrapper for posix_fadvise() on.
mm/fadvise.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/mm/fadvise.c b/mm/fadvise.c
index 469491e0..f9e48dd 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -43,13 +43,13 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
goto out;
}
- mapping = file->f_mapping;
- if (!mapping || len < 0) {
+ if (len < 0) {
ret = -EINVAL;
goto out;
}
- if (mapping->a_ops->get_xip_mem) {
+ mapping = file->f_mapping;
+ if (!mapping || mapping->a_ops->get_xip_mem) {
switch (advice) {
case POSIX_FADV_NORMAL:
case POSIX_FADV_RANDOM:
@@ -93,10 +93,9 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
spin_unlock(&file->f_lock);
break;
case POSIX_FADV_WILLNEED:
- if (!mapping->a_ops->readpage) {
- ret = -EINVAL;
+ /* ignore the advice if readahead isn't possible (tmpfs) */
+ if (!mapping->a_ops->readpage)
break;
- }
/* First and last PARTIAL page! */
start_index = offset >> PAGE_CACHE_SHIFT;
@@ -106,12 +105,8 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
nrpages = end_index - start_index + 1;
if (!nrpages)
nrpages = ~0UL;
-
- ret = force_page_cache_readahead(mapping, file,
- start_index,
- nrpages);
- if (ret > 0)
- ret = 0;
+
+ force_page_cache_readahead(mapping, file, start_index, nrpages);
break;
case POSIX_FADV_NOREUSE:
break;
--
Eric Wong
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
WARNING: multiple messages have this Message-ID (diff)
From: Eric Wong <normalperson@yhbt.net>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fadvise: avoid EINVAL if user input is valid
Date: Sat, 25 Feb 2012 02:27:10 +0000 [thread overview]
Message-ID: <20120225022710.GA29455@dcvr.yhbt.net> (raw)
The kernel is not required to act on fadvise, so fail silently
and ignore advice as long as it has a valid descriptor and
parameters.
Cc: linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
Of course I wouldn't knowingly call posix_fadvise() on a file in
tmpfs, but a userspace app often doesn't know (nor should it
care) what type of filesystem it's on.
I encountered EINVAL while running the Ruby 1.9.3 test suite on a
stock Debian wheezy installation. Wheezy uses tmpfs for "/tmp" by
default and the test suite creates a temporary file to test the
Ruby wrapper for posix_fadvise() on.
mm/fadvise.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/mm/fadvise.c b/mm/fadvise.c
index 469491e0..f9e48dd 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -43,13 +43,13 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
goto out;
}
- mapping = file->f_mapping;
- if (!mapping || len < 0) {
+ if (len < 0) {
ret = -EINVAL;
goto out;
}
- if (mapping->a_ops->get_xip_mem) {
+ mapping = file->f_mapping;
+ if (!mapping || mapping->a_ops->get_xip_mem) {
switch (advice) {
case POSIX_FADV_NORMAL:
case POSIX_FADV_RANDOM:
@@ -93,10 +93,9 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
spin_unlock(&file->f_lock);
break;
case POSIX_FADV_WILLNEED:
- if (!mapping->a_ops->readpage) {
- ret = -EINVAL;
+ /* ignore the advice if readahead isn't possible (tmpfs) */
+ if (!mapping->a_ops->readpage)
break;
- }
/* First and last PARTIAL page! */
start_index = offset >> PAGE_CACHE_SHIFT;
@@ -106,12 +105,8 @@ SYSCALL_DEFINE(fadvise64_64)(int fd, loff_t offset, loff_t len, int advice)
nrpages = end_index - start_index + 1;
if (!nrpages)
nrpages = ~0UL;
-
- ret = force_page_cache_readahead(mapping, file,
- start_index,
- nrpages);
- if (ret > 0)
- ret = 0;
+
+ force_page_cache_readahead(mapping, file, start_index, nrpages);
break;
case POSIX_FADV_NOREUSE:
break;
--
Eric Wong
next reply other threads:[~2012-02-25 2:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-25 2:27 Eric Wong [this message]
2012-02-25 2:27 ` [PATCH] fadvise: avoid EINVAL if user input is valid Eric Wong
2012-02-25 22:56 ` Pádraig Brady
2012-02-25 22:56 ` Pádraig Brady
2012-02-25 23:10 ` Eric Wong
2012-02-25 23:10 ` Eric Wong
2012-02-26 5:52 ` Hillf Danton
2012-02-26 5:52 ` Hillf Danton
2012-02-26 8:44 ` Eric Wong
2012-02-26 8:44 ` Eric Wong
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=20120225022710.GA29455@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--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.