Message ID | 18a010357eb63dfd50751c5eb529f6261cf90ecd.1305232529.git.joe@perches.com |
---|---|
State | Rejected, archived |
Delegated to: | David Miller |
Headers | show |
From: Joe Perches <joe@perches.com> Date: Thu, 12 May 2011 13:36:10 -0700 > Save a memset, initialize only the portion necessary. > > packet_snd either gets this structure completely from > memcpy_fromiovec or uses only the hdr_len set to 0, > so don't always initialize the structure to 0. > > Signed-off-by: Joe Perches <joe@perches.com> On ARM this won't be tightly packed, therefore you'll leave uninitialized pieces of padding in this structure and this thing is an "on-the-wire" network header. I'm not applying this. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2011-05-12 at 17:26 -0400, David Miller wrote: > From: Joe Perches <joe@perches.com> > Date: Thu, 12 May 2011 13:36:10 -0700 > > > Save a memset, initialize only the portion necessary. > > > > packet_snd either gets this structure completely from > > memcpy_fromiovec or uses only the hdr_len set to 0, > > so don't always initialize the structure to 0. > > > > Signed-off-by: Joe Perches <joe@perches.com> > > On ARM this won't be tightly packed, therefore you'll leave > uninitialized pieces of padding in this structure and this > thing is an "on-the-wire" network header. > > I'm not applying this. I believe that it's only sent when po->has_vnet_hdr is set. In that case, it's completely filled from memcpy_fromiovec. In the not set po->has_vnet_hdr case, only vnet_hdr.hdr_len is accessed by packet_alloc_skb. cheers, Joe -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Joe Perches <joe@perches.com> Date: Thu, 12 May 2011 14:33:20 -0700 > On Thu, 2011-05-12 at 17:26 -0400, David Miller wrote: >> From: Joe Perches <joe@perches.com> >> Date: Thu, 12 May 2011 13:36:10 -0700 >> >> > Save a memset, initialize only the portion necessary. >> > >> > packet_snd either gets this structure completely from >> > memcpy_fromiovec or uses only the hdr_len set to 0, >> > so don't always initialize the structure to 0. >> > >> > Signed-off-by: Joe Perches <joe@perches.com> >> >> On ARM this won't be tightly packed, therefore you'll leave >> uninitialized pieces of padding in this structure and this >> thing is an "on-the-wire" network header. >> >> I'm not applying this. > > I believe that it's only sent when po->has_vnet_hdr > is set. In that case, it's completely filled from > memcpy_fromiovec. In the not set po->has_vnet_hdr case, > only vnet_hdr.hdr_len is accessed by packet_alloc_skb. I think with the way this code is protecting accesses to vnet_hdr, it's going to start warning that some parts "may" be use uninitialized. It's also slightly ugly to partially initialize these on-stack things. I would rather see the code rearranged such that this sort of hackish scheme isn't necessary. Again, I'm not applying this. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 549527b..ac88df9 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1123,7 +1123,7 @@ static int packet_snd(struct socket *sock, __be16 proto; unsigned char *addr; int ifindex, err, reserve = 0; - struct virtio_net_hdr vnet_hdr = { 0 }; + struct virtio_net_hdr vnet_hdr; int offset = 0; int vnet_hdr_len; struct packet_sock *po = pkt_sk(sk); @@ -1206,7 +1206,9 @@ static int packet_snd(struct socket *sock, goto out_unlock; } - } + } else + vnet_hdr.hdr_len = 0; + err = -EMSGSIZE; if (!gso_type && (len > dev->mtu + reserve + VLAN_HLEN))
Save a memset, initialize only the portion necessary. packet_snd either gets this structure completely from memcpy_fromiovec or uses only the hdr_len set to 0, so don't always initialize the structure to 0. Signed-off-by: Joe Perches <joe@perches.com> --- net/packet/af_packet.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)