]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Currently in oprofilefs, files that use ulong_fops mis-handle writes of
authorMike Waychison <mikew@google.com>
Wed, 24 Aug 2011 23:47:38 +0000 (09:47 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 22 Sep 2011 08:26:32 +0000 (18:26 +1000)
zero length.  A count of 0 causes oprofilefs_ulong_from_user to return 0
(success), which then leads to oprofile_set_ulong being called to stuff
"value" into file->private_data without it being initialized.

Fix this by moving the check for a zero-length write up into
ulong_write_file.

Signed-off-by: Mike Waychison <mikew@google.com>
Cc: Robert Richter <robert.richter@amd.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/oprofile/oprofilefs.c

index d0de6cc2d7a5e56e36d2dfa8b2cc8b6ad17074f5..87506ecdd94236b93a972caa99c78dfac79d2e6a 100644 (file)
@@ -65,9 +65,6 @@ int oprofilefs_ulong_from_user(unsigned long *val, char const __user *buf, size_
        char tmpbuf[TMPBUFSIZE];
        unsigned long flags;
 
        char tmpbuf[TMPBUFSIZE];
        unsigned long flags;
 
-       if (!count)
-               return 0;
-
        if (count > TMPBUFSIZE - 1)
                return -EINVAL;
 
        if (count > TMPBUFSIZE - 1)
                return -EINVAL;
 
@@ -97,6 +94,8 @@ static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_
 
        if (*offset)
                return -EINVAL;
 
        if (*offset)
                return -EINVAL;
+       if (count == 0)
+               return 0;
 
        retval = oprofilefs_ulong_from_user(&value, buf, count);
        if (retval)
 
        retval = oprofilefs_ulong_from_user(&value, buf, count);
        if (retval)