Skip to content

Commit fc29bbc

Browse files
GustavoARSilvagregkh
authored andcommitted
ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user()
[ Upstream commit c1d9e34 ] Fix the following out-of-bounds warning: net/ethtool/ioctl.c:492:2: warning: 'memcpy' offset [49, 84] from the object at 'link_usettings' is out of the bounds of referenced subobject 'base' with type 'struct ethtool_link_settings' at offset 0 [-Warray-bounds] The problem is that the original code is trying to copy data into a some struct members adjacent to each other in a single call to memcpy(). This causes a legitimate compiler warning because memcpy() overruns the length of &link_usettings.base. Fix this by directly using &link_usettings and _from_ as destination and source addresses, instead. This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy(). Link: KSPP/linux#109 Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 453f0a4 commit fc29bbc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎net/ethtool/ioctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ store_link_ksettings_for_user(void __user *to,
489489
{
490490
struct ethtool_link_usettings link_usettings;
491491

492-
memcpy(&link_usettings.base, &from->base, sizeof(link_usettings));
492+
memcpy(&link_usettings, from, sizeof(link_usettings));
493493
bitmap_to_arr32(link_usettings.link_modes.supported,
494494
from->link_modes.supported,
495495
__ETHTOOL_LINK_MODE_MASK_NBITS);

0 commit comments

Comments
 (0)