From: Joe Perches <joe@perches.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
zhanglin <zhang.lin16@zte.com.cn>
Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net,
jakub.kicinski@netronome.com, hawk@kernel.org,
john.fastabend@gmail.com, mkubecek@suse.cz, jiri@mellanox.com,
pablo@netfilter.org, f.fainelli@gmail.com,
maxime.chevallier@bootlin.com, lirongqing@baidu.com,
vivien.didelot@gmail.com, linyunsheng@huawei.com,
natechancellor@gmail.com, arnd@arndb.de, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
xue.zhihong@zte.com.cn, wang.yi59@zte.com.cn,
jiang.xuexin@zte.com.cn
Subject: Re: [PATCH] net: Zeroing the structure ethtool_wolinfo in ethtool_get_wol()
Date: Sat, 26 Oct 2019 08:52:35 -0700 [thread overview]
Message-ID: <ec9c36dddd1fb3d7cf339bcfba006f15f51b9120.camel@perches.com> (raw)
In-Reply-To: <20191026142458.GJ23523@kadam>
On Sat, 2019-10-26 at 17:24 +0300, Dan Carpenter wrote:
> 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.
[]
> > diff --git 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_wolinf 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...
The standard doesn't specify what happens to the padding so
it's not just for gcc, it's compiler dependent.
So anything that's used in a copy_to_user with any possible
padding should either be zalloc'd or memset before assigned.
In this case:
include/uapi/linux/ethtool.h:#define SOPASS_MAX 6
and
include/uapi/linux/ethtool.h:struct ethtool_wolinfo {
include/uapi/linux/ethtool.h- __u32 cmd;
include/uapi/linux/ethtool.h- __u32 supported;
include/uapi/linux/ethtool.h- __u32 wolopts;
include/uapi/linux/ethtool.h- __u8 sopass[SOPASS_MAX];
include/uapi/linux/ethtool.h-};
so there's likely a couple bytes of trailing padding.
next prev parent reply other threads:[~2019-10-26 15:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-26 7:54 [PATCH] net: Zeroing the structure ethtool_wolinfo in ethtool_get_wol() zhanglin
2019-10-26 14:24 ` Dan Carpenter
2019-10-26 15:52 ` Joe Perches [this message]
2019-10-26 18:21 ` David Miller
2019-10-26 19:40 ` Joe Perches
2019-10-26 20:17 ` [Cocci] " Julia Lawall
2019-11-21 10:23 ` Enrico Weigelt, metux IT consult
2019-11-21 11:19 ` Michal Kubecek
2019-11-21 11:58 ` Julia Lawall
2019-11-21 12:07 ` Dan Carpenter
2019-11-21 13:38 ` Michal Kubecek
2019-11-21 20:40 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ec9c36dddd1fb3d7cf339bcfba006f15f51b9120.camel@perches.com \
--to=joe@perches.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=hawk@kernel.org \
--cc=jakub.kicinski@netronome.com \
--cc=jiang.xuexin@zte.com.cn \
--cc=jiri@mellanox.com \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linyunsheng@huawei.com \
--cc=lirongqing@baidu.com \
--cc=maxime.chevallier@bootlin.com \
--cc=mkubecek@suse.cz \
--cc=natechancellor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=vivien.didelot@gmail.com \
--cc=wang.yi59@zte.com.cn \
--cc=xue.zhihong@zte.com.cn \
--cc=zhang.lin16@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox