提交 2235f2ac 编写于 作者: E Eric Dumazet 提交者: David S. Miller

inet: fix races with reqsk timers

reqsk_queue_destroy() and reqsk_queue_unlink() should use
del_timer_sync() instead of del_timer() before calling reqsk_put(),
otherwise we could free a req still used by another cpu.

But before doing so, reqsk_queue_destroy() must release syn_wait_lock
spinlock or risk a dead lock, as reqsk_timer_handler() might
need to take this same spinlock from reqsk_queue_unlink() (called from
inet_csk_reqsk_queue_drop())

Fixes: fa76ce73 ("inet: get rid of central tcp/dccp listener timer")
Signed-off-by: NEric Dumazet <edumazet@google.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 9d332d92
...@@ -103,10 +103,16 @@ void reqsk_queue_destroy(struct request_sock_queue *queue) ...@@ -103,10 +103,16 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
spin_lock_bh(&queue->syn_wait_lock); spin_lock_bh(&queue->syn_wait_lock);
while ((req = lopt->syn_table[i]) != NULL) { while ((req = lopt->syn_table[i]) != NULL) {
lopt->syn_table[i] = req->dl_next; lopt->syn_table[i] = req->dl_next;
/* Because of following del_timer_sync(),
* we must release the spinlock here
* or risk a dead lock.
*/
spin_unlock_bh(&queue->syn_wait_lock);
atomic_inc(&lopt->qlen_dec); atomic_inc(&lopt->qlen_dec);
if (del_timer(&req->rsk_timer)) if (del_timer_sync(&req->rsk_timer))
reqsk_put(req); reqsk_put(req);
reqsk_put(req); reqsk_put(req);
spin_lock_bh(&queue->syn_wait_lock);
} }
spin_unlock_bh(&queue->syn_wait_lock); spin_unlock_bh(&queue->syn_wait_lock);
} }
......
...@@ -593,7 +593,7 @@ static bool reqsk_queue_unlink(struct request_sock_queue *queue, ...@@ -593,7 +593,7 @@ static bool reqsk_queue_unlink(struct request_sock_queue *queue,
} }
spin_unlock(&queue->syn_wait_lock); spin_unlock(&queue->syn_wait_lock);
if (del_timer(&req->rsk_timer)) if (del_timer_sync(&req->rsk_timer))
reqsk_put(req); reqsk_put(req);
return found; return found;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册