From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 6/7] batman-adv: Provide full headers and packets as linear skb
Date: Sun, 1 Aug 2010 23:20:12 +0200 [thread overview]
Message-ID: <1280697613-32001-7-git-send-email-sven.eckelmann@gmx.de> (raw)
In-Reply-To: <1280697613-32001-1-git-send-email-sven.eckelmann@gmx.de>
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>
---
batman-adv/hard-interface.c | 2 +-
batman-adv/routing.c | 22 ++++++++++++++--------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/batman-adv/hard-interface.c b/batman-adv/hard-interface.c
index fdabe4f..23a2595 100644
--- a/batman-adv/hard-interface.c
+++ b/batman-adv/hard-interface.c
@@ -490,7 +490,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
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. */
diff --git a/batman-adv/routing.c b/batman-adv/routing.c
index 7667c55..8f3b6fb 100644
--- a/batman-adv/routing.c
+++ b/batman-adv/routing.c
@@ -756,7 +756,7 @@ int recv_bat_packet(struct sk_buff *skb,
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 @@ int recv_bat_packet(struct sk_buff *skb,
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 @@ int recv_icmp_packet(struct sk_buff *skb)
/**
* 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 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size)
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 @@ int recv_bcast_packet(struct sk_buff *skb)
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,7 +1336,11 @@ int recv_vis_packet(struct sk_buff *skb)
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;
@@ -1354,13 +1362,11 @@ int recv_vis_packet(struct sk_buff *skb)
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;
--
1.7.1
next prev parent reply other threads:[~2010-08-01 21:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-01 21:20 [B.A.T.M.A.N.] [PATCHv2 0/7] SKB cleanup queue Sven Eckelmann
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 1/7] batman-adv: Keep header writable and unshared Sven Eckelmann
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 2/7] batman-adv: Only clone skb data for multiple broadcasts Sven Eckelmann
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 3/7] batman-adv: Aggregate batman packets directly in skb Sven Eckelmann
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 4/7] batman-adv: Prepare vis packets directly inside a skb Sven Eckelmann
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 5/7] batman-adv: Create copy of skb with pre-allocated headroom Sven Eckelmann
2010-08-01 21:20 ` Sven Eckelmann [this message]
2010-08-01 21:20 ` [B.A.T.M.A.N.] [PATCH 7/7] batman-adv: Fix wrong memory access in gw_is_target Sven Eckelmann
2010-08-08 13:05 ` [B.A.T.M.A.N.] [PATCHv2 0/7] SKB cleanup queue Marek Lindner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1280697613-32001-7-git-send-email-sven.eckelmann@gmx.de \
--to=sven.eckelmann@gmx.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).