Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: danborkmann@iogearbox.net
Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [PATCH] af_packet: tpacket_destruct_skb, deref skb after BUG_ON assertion
Date: Sun, 09 Oct 2011 22:57:46 +0200	[thread overview]
Message-ID: <1318193866.21116.3.camel@edumazet-laptop> (raw)
In-Reply-To: <20111009171919.10922hrx8qjm2f7b@webmail.your-server.de>

Le dimanche 09 octobre 2011 à 17:19 +0200, danborkmann@iogearbox.net a
écrit :
> This tiny patch derefs the skb only after BUG_ON(skb==NULL) was evaluated
> and not before. Patched against latest Linus tree.
> 
> Thanks,
> Daniel
> 
> Signed-off-by: Daniel Borkmann <danborkmann@iogearbox.net>
> 
> diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
> index fabb4fa..d9d833b 100644
> --- a/net/packet/af_packet.c
> +++ b/net/packet/af_packet.c
> @@ -1167,11 +1167,12 @@ ring_is_full:
> 
>   static void tpacket_destruct_skb(struct sk_buff *skb)
>   {
> -	struct packet_sock *po = pkt_sk(skb->sk);
> +	struct packet_sock *po;
>   	void *ph;
> 
>   	BUG_ON(skb == NULL);
> 
> +	po = pkt_sk(skb->sk);
>   	if (likely(po->tx_ring.pg_vec)) {
>   		ph = skb_shinfo(skb)->destructor_arg;
>   		BUG_ON(__packet_get_status(po, ph) != TP_STATUS_SENDING);
> 
> 

Well, to be honest, this BUG_ON(!skb) is absolutely useless for two
reasons.

1) If skb happens to be NULL, the NULL dereference is trapped and stack
trace dumped as well.

2) Of course, tpacket_destruct_skb() being an skb destructor, skb cannot
be NULL at this point by design.

Please remove the BUG_ON() instead of trying to move it ;)

Thanks

  reply	other threads:[~2011-10-09 20:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-09 15:19 [PATCH] af_packet: tpacket_destruct_skb, deref skb after BUG_ON assertion danborkmann
2011-10-09 20:57 ` Eric Dumazet [this message]
2011-10-10  8:02   ` danborkmann
2011-10-10 16:06     ` Eric Dumazet

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=1318193866.21116.3.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=danborkmann@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.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