FAILED: patch "[PATCH] NTB: ntb_tool: uninitialized heap data in tool_fn_write()" failed to apply to 4.9-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.9-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 45e1058b77feade4e36402828bfe3e0d3363177b Mon Sep 17 00:00:00 2001
From: Dan Carpenter <[email protected]>
Date: Wed, 20 Jul 2022 21:28:18 +0300
Subject: [PATCH] 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().
drivers/ntb/test/ntb_tool.c +5 -3
@@ -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 ;