diff options
author | Eric Dumazet <edumazet@google.com> | 2015-10-09 11:29:32 -0700 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2015-11-27 12:48:20 +0000 |
commit | 9914546b256457c85e45c99f9d95759b07452f1a (patch) | |
tree | ec6e9482a7c54693f105303580e28083b0f323d6 /net | |
parent | e7102453150c7081a27744989374c474d2ebea8e (diff) |
packet: fix match_fanout_group()
commit 161642e24fee40fba2c5bc2ceacc00d118a22d65 upstream.
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: c0de08d04215 ("af_packet: don't emit packet on orig fanout group")
Fixes: ca6fb0651883 ("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>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'net')
-rw-r--r-- | net/packet/af_packet.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 0c21f061455f..4a912f78e423 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -1263,10 +1263,10 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po) 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 int fanout_add(struct sock *sk, u16 id, u16 type_flags) |