Skip to content

Commit eaa5cd9

Browse files
vzapolskiygregkh
authored andcommitted
fs: sysfs: don't pass count == 0 to bin file readers
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>
1 parent 9ba8af6 commit eaa5cd9

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎fs/sysfs/file.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static ssize_t sysfs_kf_bin_read(struct kernfs_open_file *of, char *buf,
9090
return 0;
9191

9292
if (size) {
93-
if (pos > size)
93+
if (pos >= size)
9494
return 0;
9595
if (pos + count > size)
9696
count = size - pos;

0 commit comments

Comments
 (0)