Skip to content

Commit 2235f2a

Browse files
edumazetdavem330
authored andcommitted
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: fa76ce7 ("inet: get rid of central tcp/dccp listener timer") Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9d332d9 commit 2235f2a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

net/core/request_sock.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ void reqsk_queue_destroy(struct request_sock_queue *queue)
103103
spin_lock_bh(&queue->syn_wait_lock);
104104
while ((req = lopt->syn_table[i]) != NULL) {
105105
lopt->syn_table[i] = req->dl_next;
106+
/* Because of following del_timer_sync(),
107+
* we must release the spinlock here
108+
* or risk a dead lock.
109+
*/
110+
spin_unlock_bh(&queue->syn_wait_lock);
106111
atomic_inc(&lopt->qlen_dec);
107-
if (del_timer(&req->rsk_timer))
112+
if (del_timer_sync(&req->rsk_timer))
108113
reqsk_put(req);
109114
reqsk_put(req);
115+
spin_lock_bh(&queue->syn_wait_lock);
110116
}
111117
spin_unlock_bh(&queue->syn_wait_lock);
112118
}

net/ipv4/inet_connection_sock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static bool reqsk_queue_unlink(struct request_sock_queue *queue,
593593
}
594594

595595
spin_unlock(&queue->syn_wait_lock);
596-
if (del_timer(&req->rsk_timer))
596+
if (del_timer_sync(&req->rsk_timer))
597597
reqsk_put(req);
598598
return found;
599599
}

0 commit comments

Comments
 (0)