sk_psock_backlog() runs for a given psock, but takes the reference with sk_psock_get(psock->sk), which returns the psock that sk_user_data points to now. That is the same psock only while psock->sk->psock == psock. If sk is removed from the map and added back while the backlog runs, the old psock is dropped and sk_user_data points to the new one. The backlog of the old psock then takes a reference on the new psock and puts the old one, whose refcnt is already 0. The old one hits a refcount underflow and the new one leaks a reference. The SK_PSOCK_TX_ENABLED check before it does not close this window. Take the reference on the psock itself. Fixes: 8259eb0e06d8 ("bpf, sockmap: Avoid using sk_socket after free when sending") Signed-off-by: Jiayuan Chen --- net/core/skmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index dcae3cd968edc..da9b60f34e2df 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -707,7 +707,7 @@ static void sk_psock_backlog(struct work_struct *work) * before sk_socket freed. If refcnt increment fails, it indicates * sock_map_close() completed with sk_socket potentially already freed. */ - if (!sk_psock_get(psock->sk)) + if (!refcount_inc_not_zero(&psock->refcnt)) return; mutex_lock(&psock->work_mutex); while ((skb = skb_peek(&psock->ingress_skb))) { -- 2.43.0