pktgen: fix crash when generating IPv6 packets
authorAmerigo Wang <amwang@redhat.com>
Tue, 9 Oct 2012 17:48:16 +0000 (17:48 +0000)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 30 Oct 2012 23:26:43 +0000 (23:26 +0000)
commitfe54b1e7efb9b0c4bc0be5202c50639cd7571c8e
tree13df578445c2724553a38ab6cf34f4a4d15a64b3
parent6780e9e1d9f227fc2cf1ff966f43a5d794086e79
pktgen: fix crash when generating IPv6 packets

commit 5aa8b572007c4bca1e6d3dd4c4820f1ae49d6bb2 upstream.

For IPv6, sizeof(struct ipv6hdr) = 40, thus the following
expression will result negative:

        datalen = pkt_dev->cur_pkt_size - 14 -
                  sizeof(struct ipv6hdr) - sizeof(struct udphdr) -
                  pkt_dev->pkt_overhead;

And,  the check "if (datalen < sizeof(struct pktgen_hdr))" will be
passed as "datalen" is promoted to unsigned, therefore will cause
a crash later.

This is a quick fix by checking if "datalen" is negative. The following
patch will increase the default value of 'min_pkt_size' for IPv6.

This bug should exist for a long time, so Cc -stable too.

Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <amwang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/core/pktgen.c