[RFC][PATCH 4/4] anon_inode fcntl() checks: report failure for fcntl(F_SETFL) on eventfd

From: Matt Helsley
Date: Sat Feb 13 2010 - 19:28:34 EST


Report failure when userspace attempts to set unsupported flags
on eventfd files with fcntl().

Signed-off-by: Matt Helsley <matthltc@xxxxxxxxxx>
Cc: Davide Libenzi <davidel@xxxxxxxxxxxxxxx>
---
fs/eventfd.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/eventfd.c b/fs/eventfd.c
index 7758cc3..8976079 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -287,7 +287,19 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
return res;
}

+static int eventfd_check_flags(int flags)
+{
+ /* Check the EFD_* constants for consistency. */
+ BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
+ BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK);
+
+ if (flags & ~EFD_SHARED_FCNTL_FLAGS)
+ return -EINVAL;
+ return 0;
+}
+
static const struct file_operations eventfd_fops = {
+ .check_flags = eventfd_check_flags,
.release = eventfd_release,
.poll = eventfd_poll,
.read = eventfd_read,
@@ -381,9 +393,6 @@ struct file *eventfd_file_create(unsigned int count, int flags)
struct file *file;
struct eventfd_ctx *ctx;

- /* Check the EFD_* constants for consistency. */
- BUILD_BUG_ON(EFD_CLOEXEC != O_CLOEXEC);
- BUILD_BUG_ON(EFD_NONBLOCK != O_NONBLOCK);

if (flags & ~EFD_FLAGS_SET)
return ERR_PTR(-EINVAL);
--
1.6.3.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/