[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9d71d005-0007-4983-b5dc-251bb4bc17bd@moroto.mountain>
Date: Fri, 12 Jan 2024 08:35:39 +0300
From: Dan Carpenter <dan.carpenter@...aro.org>
To: Kees Cook <keescook@...omium.org>
Cc: "Gustavo A. R. Silva" <gustavo@...eddedor.com>,
Harshit Mogalapalli <harshit.m.mogalapalli@...cle.com>,
linux-hardening@...r.kernel.org, error27@...il.com,
gustavoars@...nel.org, Bryan Tan <bryantan@...are.com>,
Vishnu Dasa <vdasa@...are.com>,
VMware PV-Drivers Reviewers <pv-drivers@...are.com>,
Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-kernel@...r.kernel.org, vegard.nossum@...cle.com,
darren.kenny@...cle.com, syzkaller <syzkaller@...glegroups.com>
Subject: Re: [PATCH v2 2/2] VMCI: Fix memcpy() run-time warning in
dg_dispatch_as_host()
On Thu, Jan 11, 2024 at 10:13:44AM -0800, Kees Cook wrote:
> On Thu, Jan 11, 2024 at 10:15:40AM +0300, Dan Carpenter wrote:
> > On Wed, Jan 10, 2024 at 04:03:28PM -0800, Kees Cook wrote:
> > (I wrote a patch for this a few months back but didn't send it because
> > of the merge window. I forgot about it until now that we're in a merge
> > window again... :P)
>
> memcpy(&ivi->vlan, &bulletin->vlan, VLAN_HLEN);
>
> #define VLAN_HLEN 4
> ivi->vlan is u32
> bulletin has:
> u16 vlan;
> u8 vlan_padding[6];
>
> yeah, ew. Should it even be reading padding? i.e. should this be:
>
> ivi->vlan = bulletin->vlan << 16;
>
That seems reasonable. We don't care about endianness?
> ?
>
> Or should bulletin be:
>
> union {
> struct {
> u16 vlan;
> u8 vlan_padding[6];
> };
> struct {
> u32 vlan_header;
> u8 vlan_header_padding[4];
> };
> };
>
> with:
>
> ivi->vlan = bulletin->vlan_header;
>
> ?
My patch used a struct group.
struct_group(vlan_header,
u16 vlan;
u16 vlan_padding;
);
We don't need 6 bytes of padding, only 2. Using a shift seems like
possibly a better approach. Have to think about that.
>
> I've been finding that almost all memcpy()s and memset()s into non-array
> types are better just rewritten as a direct assignment. :P
That seems like a good rule of thumb, thanks.
regards,
dan carpenter
Powered by blists - more mailing lists