Author: marek Date: 2010-08-08 15:01:02 +0200 (Sun, 08 Aug 2010) New Revision: 1762
Modified: trunk/batman-adv/hard-interface.c trunk/batman-adv/routing.c Log: batman-adv: Provide full headers and packets as linear skb
We must ensure that all interesting data is linear and not paged out to access all information in a header or a full batman-adv related packet. Otherwise we may drop packets which have non-linear headers but which hold valid data.
This doesn't affect non-linear skbs which have all headers in a linear head unless we must process the whole packet like in ogms or vis packets.
Signed-off-by: Sven Eckelmann sven.eckelmann@gmx.de
Modified: trunk/batman-adv/hard-interface.c =================================================================== --- trunk/batman-adv/hard-interface.c 2010-08-08 13:00:58 UTC (rev 1761) +++ trunk/batman-adv/hard-interface.c 2010-08-08 13:01:02 UTC (rev 1762) @@ -498,7 +498,7 @@ goto err_out;
/* packet should hold at least type and version */ - if (unlikely(skb_headlen(skb) < 2)) + if (unlikely(!pskb_may_pull(skb, 2))) goto err_free;
/* expect a valid ethernet header here. */
Modified: trunk/batman-adv/routing.c =================================================================== --- trunk/batman-adv/routing.c 2010-08-08 13:00:58 UTC (rev 1761) +++ trunk/batman-adv/routing.c 2010-08-08 13:01:02 UTC (rev 1762) @@ -756,7 +756,7 @@ unsigned long flags;
/* drop packet if it has not necessary minimum size */ - if (skb_headlen(skb) < sizeof(struct batman_packet)) + if (unlikely(!pskb_may_pull(skb, sizeof(struct batman_packet)))) return NET_RX_DROP;
ethhdr = (struct ethhdr *)skb_mac_header(skb); @@ -773,6 +773,10 @@ if (skb_cow(skb, 0) < 0) return NET_RX_DROP;
+ /* keep skb linear */ + if (skb_linearize(skb) < 0) + return NET_RX_DROP; + ethhdr = (struct ethhdr *)skb_mac_header(skb);
spin_lock_irqsave(&orig_hash_lock, flags); @@ -926,11 +930,11 @@ /** * we truncate all incoming icmp packets if they don't match our size */ - if (skb_headlen(skb) >= sizeof(struct icmp_packet_rr)) + if (skb->len >= sizeof(struct icmp_packet_rr)) hdr_size = sizeof(struct icmp_packet_rr);
/* drop packet if it has not necessary minimum size */ - if (skb_headlen(skb) < hdr_size) + if (unlikely(!pskb_may_pull(skb, hdr_size))) return NET_RX_DROP;
ethhdr = (struct ethhdr *)skb_mac_header(skb); @@ -1099,7 +1103,7 @@ struct ethhdr *ethhdr;
/* drop packet if it has not necessary minimum size */ - if (skb_headlen(skb) < hdr_size) + if (unlikely(!pskb_may_pull(skb, hdr_size))) return -1;
ethhdr = (struct ethhdr *) skb_mac_header(skb); @@ -1259,7 +1263,7 @@ unsigned long flags;
/* drop packet if it has not necessary minimum size */ - if (skb_headlen(skb) < hdr_size) + if (unlikely(!pskb_may_pull(skb, hdr_size))) return NET_RX_DROP;
ethhdr = (struct ethhdr *)skb_mac_header(skb); @@ -1332,9 +1336,13 @@ struct bat_priv *bat_priv; int hdr_size = sizeof(struct vis_packet);
- if (skb_headlen(skb) < hdr_size) + /* keep skb linear */ + if (skb_linearize(skb) < 0) return NET_RX_DROP;
+ if (unlikely(!pskb_may_pull(skb, hdr_size))) + return NET_RX_DROP; + vis_packet = (struct vis_packet *) skb->data; ethhdr = (struct ethhdr *)skb_mac_header(skb);
@@ -1354,13 +1362,11 @@
switch (vis_packet->vis_type) { case VIS_TYPE_SERVER_SYNC: - /* TODO: handle fragmented skbs properly */ receive_server_sync_packet(bat_priv, vis_packet, skb_headlen(skb)); break;
case VIS_TYPE_CLIENT_UPDATE: - /* TODO: handle fragmented skbs properly */ receive_client_update_packet(bat_priv, vis_packet, skb_headlen(skb)); break;