Re: [PATCH] net: Zeroing the structure ethtool_wolinfo in ethtool_get_wol()

Dan Carpenter
2019-10-26T14:26:24Z

On Sat, Oct 26, 2019 at 03:54:16PM +0800, zhanglin wrote:
> memset() the structure ethtool_wolinfo that has padded bytes
> but the padded bytes have not been zeroed out.
>
> Signed-off-by: zhanglin <zhang.lin16@zte.com.cn>
> ---
> net/core/ethtool.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/net/core/ethtool.c b/net/core/ethtool.c
> index aeabc48..563a845 100644
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
> @@ -1471,11 +1471,13 @@ static int ethtool_reset(struct net_device *dev, char __user *useraddr)
>
> static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
> {
> - struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
> + struct ethtool_wolinfo wol;
>

How did you detect that they weren't initialized? Is this a KASAN
thing?

Most of the time GCC will zero out the padding bytes when you have an
initializer like this, but sometimes it just makes the intialization a
series of assignments which leaves the holes uninitialized. I wish I
knew the rules so that I could check for it in Smatch. Or even better,
I wish that there were an option to always zero the holes in this
situation...

regards,
dan carpenter