Skip to content

Commit

Permalink
packet: fix match_fanout_group()
Browse files Browse the repository at this point in the history
Recent TCP listener patches exposed a prior af_packet bug :
match_fanout_group() blindly assumes it is always safe
to cast sk to a packet socket to compare fanout with af_packet_priv

But SYNACK packets can be sent while attached to request_sock, which
are smaller than a "struct sock".

We can read non existent memory and crash.

Fixes: c0de08d ("af_packet: don't emit packet on orig fanout group")
Fixes: ca6fb06 ("tcp: attach SYNACK messages to request sockets instead of listener")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Willem de Bruijn <willemb@google.com>
Cc: Eric Leblond <eric@regit.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Oct 13, 2015
1 parent 9916596 commit 161642e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,10 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po)

static bool match_fanout_group(struct packet_type *ptype, struct sock *sk)
{
if (ptype->af_packet_priv == (void *)((struct packet_sock *)sk)->fanout)
return true;
if (sk->sk_family != PF_PACKET)
return false;

return false;
return ptype->af_packet_priv == pkt_sk(sk)->fanout;
}

static void fanout_init_data(struct packet_fanout *f)
Expand Down

0 comments on commit 161642e

Please sign in to comment.