Skip to content

Commit

Permalink
fs: sysfs: don't pass count == 0 to bin file readers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Vladimir Zapolskiy authored and Greg Kroah-Hartman committed Jun 1, 2015
1 parent 9ba8af6 commit eaa5cd9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion fs/sysfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eaa5cd9

Please sign in to comment.