netdevsim: fix uninitialized data in nsim_dev_trap_fa_cookie_write()
authorDan Carpenter <dan.carpenter@linaro.org>
Tue, 11 Jul 2023 08:52:26 +0000 (11:52 +0300)
committerJakub Kicinski <kuba@kernel.org>
Wed, 12 Jul 2023 19:46:35 +0000 (12:46 -0700)
commitf72207a5c0dbaaf6921cf9a6c0d2fd0bc249ea78
treed2ca842dde675a23356b97e804f6bfb1703c8328
parentd3f87278bcb80bd7f9519669d928b43320363d4f
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: d3cbb907ae57 ("netdevsim: add ACL trap reporting cookie as a metadata")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Link: https://lore.kernel.org/r/7c1f950b-3a7d-4252-82a6-876e53078ef7@moroto.mountain
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/netdevsim/dev.c