Skip to content

Commit aadb2bb

Browse files
Cong Wangborkmann
authored andcommitted
sock_map: Fix a potential use-after-free in sock_map_close()
The last refcnt of the psock can be gone right after sock_map_remove_links(), so sk_psock_stop() could trigger a UAF. The reason why I placed sk_psock_stop() there is to avoid RCU read critical section, and more importantly, some callee of sock_map_remove_links() is supposed to be called with RCU read lock, we can not simply get rid of RCU read lock here. Therefore, the only choice we have is to grab an additional refcnt with sk_psock_get() and put it back after sk_psock_stop(). Fixes: 799aa7f ("skmsg: Avoid lock_sock() in sk_psock_backlog()") Reported-by: [email protected] Signed-off-by: Cong Wang <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 51e0158 commit aadb2bb

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

net/core/sock_map.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ void sock_map_close(struct sock *sk, long timeout)
15211521

15221522
lock_sock(sk);
15231523
rcu_read_lock();
1524-
psock = sk_psock(sk);
1524+
psock = sk_psock_get(sk);
15251525
if (unlikely(!psock)) {
15261526
rcu_read_unlock();
15271527
release_sock(sk);
@@ -1532,6 +1532,7 @@ void sock_map_close(struct sock *sk, long timeout)
15321532
sock_map_remove_links(sk, psock);
15331533
rcu_read_unlock();
15341534
sk_psock_stop(psock, true);
1535+
sk_psock_put(sk, psock);
15351536
release_sock(sk);
15361537
saved_close(sk, timeout);
15371538
}

0 commit comments

Comments
 (0)