]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
fs: sysfs: don't pass count == 0 to bin file readers
authorVladimir Zapolskiy <vz@mleia.com>
Thu, 21 May 2015 21:21:16 +0000 (00:21 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 1 Jun 2015 01:17:17 +0000 (10:17 +0900)
If count == 0 bytes are requested by a reader, sysfs_kf_bin_read()
deliberately returns 0 without passing a potentially harmful value to
some externally defined underlying battr->read() function.

However in case of (pos == size && count) the next clause always sets
count to 0 and this value is handed over to battr->read().

The change intends to make obsolete (and remove later) a redundant
sanity check in battr->read(), if it is present, or add more
protection to struct bin_attribute users, who does not care about
input arguments.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/sysfs/file.c

index 7c2867b44141e5df54734e7e27e3df344a976dea..6c95628ea377dc0d4c07cbb7979f2a280dd3e6a8 100644 (file)
@@ -90,7 +90,7 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf,
                return 0;
 
        if (size) {
-               if (pos > size)
+               if (pos >= size)
                        return 0;
                if (pos + count > size)
                        count = size - pos;