aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarissa Wall <marissaw@google.com>2017-11-16 16:56:10 -0800
committerShirle Yuen <shirleyshukyee@google.com>2018-08-05 16:36:34 -0700
commit244e23c69481b8ec2b0df542f77e6808c16b7bbc (patch)
tree4eb575f31497a05766fd82f7a5a8c2a871c2932f
parent7099a9736ab73a32b00c71ec8ef7d339cf12c000 (diff)
downloadqcom-msm8x09-v3.10-244e23c69481b8ec2b0df542f77e6808c16b7bbc.tar.gz
BACKPORT: packet: in packet_do_bind, test fanout with bind_lock held
[ Upstream commit 4971613c1639d8e5f102c4e797c3bf8f83a5a69e ] Once a socket has po->fanout set, it remains a member of the group until it is destroyed. The prot_hook must be constant and identical across sockets in the group. If fanout_add races with packet_do_bind between the test of po->fanout and taking the lock, the bind call may make type or dev inconsistent with that of the fanout group. Hold po->bind_lock when testing po->fanout to avoid this race. I had to introduce artificial delay (local_bh_enable) to actually observe the race. Bug: 111289931 Change-Id: I8944e2bb562f72f8e1d50ad4bc60a3bce82cf089 Fixes: dc99f600698d ("packet: Add fanout support.") Signed-off-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Marissa Wall <marissaw@google.com> Git-repo: https://android.googlesource.com/kernel/common Git-commit: 4e2a95fdd6c9d298e32f55852da811fcf6924c06 Signed-off-by: Ashwanth Goli <ashwanth@codeaurora.org> (cherry picked from commit d6ccf8acddbc2bb66594e0f7cae4d2c974bea2d4)
-rw-r--r--net/packet/af_packet.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index a867351bc19..65aff0f7b3e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2493,17 +2493,20 @@ static int packet_release(struct socket *sock)
static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protocol)
{
struct packet_sock *po = pkt_sk(sk);
+ int ret = 0;
+
+ lock_sock(sk);
+
+ spin_lock(&po->bind_lock);
if (po->fanout) {
if (dev)
dev_put(dev);
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_unlock;
}
- lock_sock(sk);
-
- spin_lock(&po->bind_lock);
unregister_prot_hook(sk, true);
po->num = protocol;
@@ -2530,7 +2533,7 @@ static int packet_do_bind(struct sock *sk, struct net_device *dev, __be16 protoc
out_unlock:
spin_unlock(&po->bind_lock);
release_sock(sk);
- return 0;
+ return ret;
}
/*