Skip to content

Commit

Permalink
af_packet: Don't use skb after dev_queue_xmit()
Browse files Browse the repository at this point in the history
tpacket_snd() can change and kfree an skb after dev_queue_xmit(),
which is illegal.

With debugging by: Stephen Hemminger <[email protected]>

Reported-by: Michael Breuer <[email protected]>
With help from: David S. Miller <[email protected]>
Signed-off-by: Jarek Poplawski <[email protected]>
Tested-by: Michael Breuer<[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jarek Poplawski authored and davem330 committed Jan 11, 2010
1 parent fa15e99 commit eb70df1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,20 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)

status = TP_STATUS_SEND_REQUEST;
err = dev_queue_xmit(skb);
if (unlikely(err > 0 && (err = net_xmit_errno(err)) != 0))
goto out_xmit;
if (unlikely(err > 0)) {
err = net_xmit_errno(err);
if (err && __packet_get_status(po, ph) ==
TP_STATUS_AVAILABLE) {
/* skb was destructed already */
skb = NULL;
goto out_status;
}
/*
* skb was dropped but not destructed yet;
* let's treat it like congestion or err < 0
*/
err = 0;
}
packet_increment_head(&po->tx_ring);
len_sum += tp_len;
} while (likely((ph != NULL) ||
Expand All @@ -1033,9 +1045,6 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
err = len_sum;
goto out_put;

out_xmit:
skb->destructor = sock_wfree;
atomic_dec(&po->tx_ring.pending);
out_status:
__packet_set_status(po, ph, status);
kfree_skb(skb);
Expand Down

0 comments on commit eb70df1

Please sign in to comment.