History

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().

Cong Wang committed 5 years ago

Commit aadb2bb1 parent 51e01581 file · +2 −1Browse files

Unified · Split

net/core/sock_map.c+2−1
@@ -1521,7 +1521,7 @@ void sock_map_close(struct sock *sk, long timeout) · 1520 unmodified lines
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) · 4 unmodified lines
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 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t