diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2022-07-20 21:28:18 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-08-25 11:15:39 +0200 |
commit | 582565415f2622d381af50e5085d7d618528373d (patch) | |
tree | f685048ee6e2017339e20a68a186f9fa3853ee5d | |
parent | 7eec34ddcba7f08304be33a62d95dc8aad6bdc96 (diff) | |
download | linux-stable-582565415f2622d381af50e5085d7d618528373d.tar.gz linux-stable-582565415f2622d381af50e5085d7d618528373d.tar.bz2 linux-stable-582565415f2622d381af50e5085d7d618528373d.zip |
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>
-rw-r--r-- | drivers/ntb/test/ntb_tool.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c index 311d6ab8d016..6301aa413c3b 100644 --- a/drivers/ntb/test/ntb_tool.c +++ b/drivers/ntb/test/ntb_tool.c @@ -367,14 +367,16 @@ static ssize_t tool_fn_write(struct tool_ctx *tc, u64 bits; int n; + if (*offp) + return 0; + buf = kmalloc(size + 1, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = simple_write_to_buffer(buf, size, offp, ubuf, size); - if (ret < 0) { + if (copy_from_user(buf, ubuf, size)) { kfree(buf); - return ret; + return -EFAULT; } buf[size] = 0; |