Skip to content

Commit

Permalink
batman-adv: Even Batman should not dereference NULL pointers
Browse files Browse the repository at this point in the history
There's a problem in net/batman-adv/unicast.c::frag_send_skb().
dev_alloc_skb() allocates memory and may fail, thus returning NULL. If
this happens we'll pass a NULL pointer on to skb_split() which in turn
hands it to skb_split_inside_header() from where it gets passed to
skb_put() that lets skb_tail_pointer() play with it and that function
dereferences it. And thus the bat dies.

While I was at it I also moved the call to dev_alloc_skb() above the
assignment to 'unicast_packet' since there's no reason to do that
assignment if the memory allocation fails.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
  • Loading branch information
Jesper Juhl authored and Sven Eckelmann committed Jan 13, 2011
1 parent 53320fe commit ed7809d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions net/batman-adv/unicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,12 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
if (!bat_priv->primary_if)
goto dropped;

unicast_packet = (struct unicast_packet *) skb->data;
frag_skb = dev_alloc_skb(data_len - (data_len / 2) + ucf_hdr_len);
if (!frag_skb)
goto dropped;

unicast_packet = (struct unicast_packet *) skb->data;
memcpy(&tmp_uc, unicast_packet, uc_hdr_len);
frag_skb = dev_alloc_skb(data_len - (data_len / 2) + ucf_hdr_len);
skb_split(skb, frag_skb, data_len / 2);

if (my_skb_head_push(skb, ucf_hdr_len - uc_hdr_len) < 0 ||
Expand Down

0 comments on commit ed7809d

Please sign in to comment.