NTB: ntb_tool: uninitialized heap data in tool_fn_write()
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 20 Jul 2022 18:28:18 +0000 (21:28 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:40:14 +0000 (11:40 +0200)
commit5c21186c5f3a7d836e75de7cd11fb40ab1e984e9
tree1ca3759a727406403c8dab3df532cf4b8552e8e1
parentcffd1cefcdd7a4a64da4dd8d5d330aec65550c41
NTB: ntb_tool: uninitialized heap data in tool_fn_write()

commit 45e1058b77feade4e36402828bfe3e0d3363177b upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/ntb/test/ntb_tool.c