From: Robert Love <rml@ximian.com>
To: John McCutchan <ttb@tentacle.dhs.org>
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org
Subject: [patch] inotify: ioctl makeover
Date: Thu, 30 Sep 2004 17:36:53 -0400 [thread overview]
Message-ID: <1096580213.4203.70.camel@betsy.boston.ximian.com> (raw)
In-Reply-To: <1096410792.4365.3.camel@vertex>
[-- Attachment #1: Type: text/plain, Size: 441 bytes --]
Attached patch greatly cleans up inotify's ioctl method. Oh my.
Net loss of 36 lines.
Main thing is removing all of the access_ok() checks and _IOC macros.
We don't need them. We can just fall off the end of the switch and
return -EINVAL if the cmd does not match. Any other access control is
handled by the device node itself or the copy_from_user() calls.
Also, other misc. changes.
Patch is on top of 0.11.0.
Best,
Robert Love
[-- Attachment #2: inotify-0.11.0-rml-ioctl-cleanup-1.patch --]
[-- Type: text/x-patch, Size: 2549 bytes --]
inotify, not your mom's notify, gets an ioctl makeover
Signed-Off-By: Robert Love <rml@novell.com>
drivers/char/inotify.c | 66 +++++++++++--------------------------------------
1 files changed, 15 insertions(+), 51 deletions(-)
diff -urN linux-inotify/drivers/char/inotify.c linux/drivers/char/inotify.c
--- linux-inotify/drivers/char/inotify.c 2004-09-30 16:53:45.223669616 -0400
+++ linux/drivers/char/inotify.c 2004-09-30 17:30:17.283425880 -0400
@@ -920,73 +920,37 @@
static int inotify_ioctl(struct inode *ip, struct file *fp,
unsigned int cmd, unsigned long arg)
{
- int err;
struct inotify_device *dev;
struct inotify_watch_request request;
+ void __user *p;
int wd;
dev = fp->private_data;
- err = 0;
-
- if (_IOC_TYPE(cmd) != INOTIFY_IOCTL_MAGIC)
- return -EINVAL;
- if (_IOC_NR(cmd) > INOTIFY_IOCTL_MAXNR)
- return -EINVAL;
-
- if (_IOC_DIR(cmd) & _IOC_READ)
- err = !access_ok(VERIFY_READ, (void *) arg, _IOC_SIZE(cmd));
-
- if (err) {
- err = -EFAULT;
- goto out;
- }
-
- if (_IOC_DIR(cmd) & _IOC_WRITE)
- err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));
-
- if (err) {
- err = -EFAULT;
- goto out;
- }
-
- err = -EINVAL;
+ p = (void __user *) arg;
switch (cmd) {
case INOTIFY_WATCH:
iprintk(INOTIFY_DEBUG_ERRORS, "INOTIFY_WATCH ioctl\n");
- if (copy_from_user(&request, (void *) arg,
- sizeof(struct inotify_watch_request))) {
- err = -EFAULT;
- goto out;
- }
- err = inotify_watch(dev, &request);
- break;
+ if (copy_from_user(&request, p, sizeof (request)))
+ return -EFAULT;
+ return inotify_watch(dev, &request);
case INOTIFY_IGNORE:
iprintk(INOTIFY_DEBUG_ERRORS, "INOTIFY_IGNORE ioctl\n");
- if (copy_from_user(&wd, (void *)arg, sizeof (int))) {
- err = -EFAULT;
- goto out;
- }
- err = inotify_ignore(dev, wd);
- break;
+ if (copy_from_user(&wd, p, sizeof (wd)))
+ return -EFAULT;
+ return inotify_ignore(dev, wd);
case INOTIFY_STATS:
iprintk(INOTIFY_DEBUG_ERRORS, "INOTIFY_STATS ioctl\n");
inotify_print_stats(dev);
- err = 0;
- break;
+ return 0;
case INOTIFY_SETDEBUG:
- iprintk(INOTIFY_DEBUG_ERRORS,
- "INOTIFY_SETDEBUG ioctl\n");
- if (copy_from_user(&inotify_debug_flags, (void *) arg,
- sizeof (int))) {
- err = -EFAULT;
- goto out;
- }
- break;
+ iprintk(INOTIFY_DEBUG_ERRORS, "INOTIFY_SETDEBUG ioctl\n");
+ if (copy_from_user(&inotify_debug_flags, p, sizeof (int)))
+ return -EFAULT;
+ return 0;
+ default:
+ return -EINVAL;
}
-
-out:
- return err;
}
static struct file_operations inotify_fops = {
next prev parent reply other threads:[~2004-09-30 21:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-28 22:33 [RFC][PATCH] inotify 0.11.0 [WITH PATCH!] John McCutchan
2004-09-30 19:01 ` [patch] inotify: locking Robert Love
2004-09-30 19:17 ` Robert Love
2004-09-30 21:36 ` Robert Love [this message]
2004-09-30 22:25 ` [patch] inotify: make user visible types portable Robert Love
2004-09-30 22:30 ` Robert Love
2004-10-02 9:21 ` David Woodhouse
2004-09-30 22:57 ` Paul Jackson
2004-10-01 5:35 ` Robert Love
2004-10-01 6:44 ` Paul Jackson
2004-10-01 7:39 ` Robert Love
2004-10-01 15:40 ` Paul Jackson
2004-10-01 15:47 ` Robert Love
2004-10-01 16:13 ` Paul Jackson
2004-10-01 16:31 ` Chris Friesen
2004-10-01 18:00 ` Paul Jackson
2004-09-30 22:43 ` [patch] inotify: rename inotify_watcher Robert Love
2004-09-30 22:44 ` Robert Love
2004-09-30 22:53 ` [patch] inotify: rename slab-related stuff Robert Love
2004-10-01 17:46 ` [patch] inotify: misc changes Robert Love
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=1096580213.4203.70.camel@betsy.boston.ximian.com \
--to=rml@ximian.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ttb@tentacle.dhs.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®