Commit c2e514bc authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by David S. Miller

[AF_PACKET]: Fix bind()/setsockopt(PACKET_RX_RING) bug and socket leak.

This problem was the bug of packet_set_ring(). packet_set_ring()
removes the hook for preparation of ring buffer, but it didn't
restore.

Also it's leaking the refcount of sk.
parent 5597ba1e
......@@ -1550,7 +1550,7 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
unsigned long *pg_vec = NULL;
struct tpacket_hdr **io_vec = NULL;
struct packet_opt *po = pkt_sk(sk);
int order = 0;
int was_running, num, order = 0;
int err = 0;
if (req->tp_block_nr) {
......@@ -1623,10 +1623,13 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
/* Detach socket from network */
spin_lock(&po->bind_lock);
if (po->running) {
was_running = po->running;
num = po->num;
if (was_running) {
__dev_remove_pack(&po->prot_hook);
po->num = 0;
po->running = 0;
__sock_put(sk);
}
spin_unlock(&po->bind_lock);
......@@ -1657,8 +1660,12 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
}
spin_lock(&po->bind_lock);
if (po->running)
if (was_running && !po->running) {
sock_hold(sk);
po->running = 1;
po->num = num;
dev_add_pack(&po->prot_hook);
}
spin_unlock(&po->bind_lock);
release_sock(sk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment