Skip to content

Commit

Permalink
flow-dissector: Fix alignment issue in __skb_flow_get_ports
Browse files Browse the repository at this point in the history
This patch addresses a kernel unaligned access bug seen on a sparc64 system
with an igb adapter.  Specifically the __skb_flow_get_ports was returning a
be32 pointer which was then having the value directly returned.

In order to prevent this it is actually easier to simply not populate the
ports or address values when an skb is not present.  In this case the
assumption is that the data isn't needed and rather than slow down the
faster aligned accesses by making them have to assume the unaligned path on
architectures that don't support efficent unaligned access it makes more
sense to simply switch off the bits that were copying the source and
destination address/port for the case where we only care about the protocol
types and lengths which are normally 16 bit fields anyway.

Reported-by: David S. Miller <[email protected]>
Signed-off-by: Alexander Duyck <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Alexander Duyck authored and davem330 committed Oct 10, 2014
1 parent 8ea6e34 commit 5af7fb6
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions net/core/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
if (ip_is_fragment(iph))
ip_proto = 0;

/* skip the address processing if skb is NULL. The assumption
* here is that if there is no skb we are not looking for flow
* info but lengths and protocols.
*/
if (!skb)
break;

iph_to_flow_copy_addrs(flow, iph);
break;
}
Expand All @@ -114,17 +121,15 @@ bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,
return false;

ip_proto = iph->nexthdr;
flow->src = (__force __be32)ipv6_addr_hash(&iph->saddr);
flow->dst = (__force __be32)ipv6_addr_hash(&iph->daddr);
nhoff += sizeof(struct ipv6hdr);

/* skip the flow label processing if skb is NULL. The
* assumption here is that if there is no skb we are not
* looking for flow info as much as we are length.
*/
/* see comment above in IPv4 section */
if (!skb)
break;

flow->src = (__force __be32)ipv6_addr_hash(&iph->saddr);
flow->dst = (__force __be32)ipv6_addr_hash(&iph->daddr);

flow_label = ip6_flowlabel(iph);
if (flow_label) {
/* Awesome, IPv6 packet has a flow label so we can
Expand Down Expand Up @@ -231,9 +236,13 @@ bool __skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow,

flow->n_proto = proto;
flow->ip_proto = ip_proto;
flow->ports = __skb_flow_get_ports(skb, nhoff, ip_proto, data, hlen);
flow->thoff = (u16) nhoff;

/* unless skb is set we don't need to record port info */
if (skb)
flow->ports = __skb_flow_get_ports(skb, nhoff, ip_proto,
data, hlen);

return true;
}
EXPORT_SYMBOL(__skb_flow_dissect);
Expand Down Expand Up @@ -334,15 +343,16 @@ u32 __skb_get_poff(const struct sk_buff *skb, void *data,

switch (keys->ip_proto) {
case IPPROTO_TCP: {
const struct tcphdr *tcph;
struct tcphdr _tcph;
/* access doff as u8 to avoid unaligned access */
const u8 *doff;
u8 _doff;

tcph = __skb_header_pointer(skb, poff, sizeof(_tcph),
data, hlen, &_tcph);
if (!tcph)
doff = __skb_header_pointer(skb, poff + 12, sizeof(_doff),
data, hlen, &_doff);
if (!doff)
return poff;

poff += max_t(u32, sizeof(struct tcphdr), tcph->doff * 4);
poff += max_t(u32, sizeof(struct tcphdr), (*doff & 0xF0) >> 2);
break;
}
case IPPROTO_UDP:
Expand Down

0 comments on commit 5af7fb6

Please sign in to comment.