Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

NTB: ntb_tool: uninitialized heap data in tool_fn_write()

The call to:

ret = simple_write_to_buffer(buf, size, offp, ubuf, size);

will return success if it is able to write even one byte to "buf".
The value of "*offp" controls which byte. This could result in
reading uninitialized data when we do the sscanf() on the next line.

This code is not really desigined to handle partial writes where
*offp is non-zero and the "buf" is preserved and re-used between writes.
Just ban partial writes and replace the simple_write_to_buffer() with
copy_from_user().

Fixes: 578b881ba9c4 ("NTB: Add tool test client")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jon Mason <jdmason@kudzu.us>

authored by

Dan Carpenter and committed by
Jon Mason
45e1058b a44252d5

+5 -3
+5 -3
drivers/ntb/test/ntb_tool.c
··· 367 367 u64 bits; 368 368 int n; 369 369 370 + if (*offp) 371 + return 0; 372 + 370 373 buf = kmalloc(size + 1, GFP_KERNEL); 371 374 if (!buf) 372 375 return -ENOMEM; 373 376 374 - ret = simple_write_to_buffer(buf, size, offp, ubuf, size); 375 - if (ret < 0) { 377 + if (copy_from_user(buf, ubuf, size)) { 376 378 kfree(buf); 377 - return ret; 379 + return -EFAULT; 378 380 } 379 381 380 382 buf[size] = 0;