Skip to content

Commit f5c16f2

Browse files
htejungregkh
authored andcommitted
sysfs: make sure read buffer is zeroed
13c589d ("sysfs: use seq_file when reading regular files") switched sysfs from custom read implementation to seq_file to enable later transition to kernfs. After the change, the buffer passed to ->show() is acquired through seq_get_buf(); unfortunately, this introduces a subtle behavior change. Before the commit, the buffer passed to ->show() was always zero as it was allocated using get_zeroed_page(). Because seq_file doesn't clear buffers on allocation and neither does seq_get_buf(), after the commit, depending on the behavior of ->show(), we may end up exposing uninitialized data to userland thus possibly altering userland visible behavior and leaking information. Fix it by explicitly clearing the buffer. Signed-off-by: Tejun Heo <tj@kernel.org> Reported-by: Ron <ron@debian.org> Fixes: 13c589d ("sysfs: use seq_file when reading regular files") Cc: stable <stable@vger.kernel.org> # 3.13+ Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 555724a commit f5c16f2

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎fs/sysfs/file.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ static int sysfs_kf_seq_show(struct seq_file *sf, void *v)
4747
ssize_t count;
4848
char *buf;
4949

50-
/* acquire buffer and ensure that it's >= PAGE_SIZE */
50+
/* acquire buffer and ensure that it's >= PAGE_SIZE and clear */
5151
count = seq_get_buf(sf, &buf);
5252
if (count < PAGE_SIZE) {
5353
seq_commit(sf, -1);
5454
return 0;
5555
}
56+
memset(buf, 0, PAGE_SIZE);
5657

5758
/*
5859
* Invoke show(). Control may reach here via seq file lseek even

0 commit comments

Comments
 (0)