Skip to content

Commit f72207a

Browse files
Dan Carpenterkuba-moo
authored andcommitted
netdevsim: fix uninitialized data in nsim_dev_trap_fa_cookie_write()
The simple_write_to_buffer() function is designed to handle partial writes. It returns negatives on error, otherwise it returns the number of bytes that were able to be copied. This code doesn't check the return properly. We only know that the first byte is written, the rest of the buffer might be uninitialized. There is no need to use the simple_write_to_buffer() function. Partial writes are prohibited by the "if (*ppos != 0)" check at the start of the function. Just use memdup_user() and copy the whole buffer. Fixes: d3cbb90 ("netdevsim: add ACL trap reporting cookie as a metadata") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Pavan Chebbi <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d3f8727 commit f72207a

File tree

1 file changed

+3
-6
lines changed
  • drivers/net/netdevsim

1 file changed

+3
-6
lines changed

drivers/net/netdevsim/dev.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,10 @@ static ssize_t nsim_dev_trap_fa_cookie_write(struct file *file,
184184
cookie_len = (count - 1) / 2;
185185
if ((count - 1) % 2)
186186
return -EINVAL;
187-
buf = kmalloc(count, GFP_KERNEL | __GFP_NOWARN);
188-
if (!buf)
189-
return -ENOMEM;
190187

191-
ret = simple_write_to_buffer(buf, count, ppos, data, count);
192-
if (ret < 0)
193-
goto free_buf;
188+
buf = memdup_user(data, count);
189+
if (IS_ERR(buf))
190+
return PTR_ERR(buf);
194191

195192
fa_cookie = kmalloc(sizeof(*fa_cookie) + cookie_len,
196193
GFP_KERNEL | __GFP_NOWARN);

0 commit comments

Comments
 (0)