CVE-2021-46929
Publication date:
27/02/2024
In the Linux kernel, the following vulnerability has been resolved:<br />
<br />
sctp: use call_rcu to free endpoint<br />
<br />
This patch is to delay the endpoint free by calling call_rcu() to fix<br />
another use-after-free issue in sctp_sock_dump():<br />
<br />
BUG: KASAN: use-after-free in __lock_acquire+0x36d9/0x4c20<br />
Call Trace:<br />
__lock_acquire+0x36d9/0x4c20 kernel/locking/lockdep.c:3218<br />
lock_acquire+0x1ed/0x520 kernel/locking/lockdep.c:3844<br />
__raw_spin_lock_bh include/linux/spinlock_api_smp.h:135 [inline]<br />
_raw_spin_lock_bh+0x31/0x40 kernel/locking/spinlock.c:168<br />
spin_lock_bh include/linux/spinlock.h:334 [inline]<br />
__lock_sock+0x203/0x350 net/core/sock.c:2253<br />
lock_sock_nested+0xfe/0x120 net/core/sock.c:2774<br />
lock_sock include/net/sock.h:1492 [inline]<br />
sctp_sock_dump+0x122/0xb20 net/sctp/diag.c:324<br />
sctp_for_each_transport+0x2b5/0x370 net/sctp/socket.c:5091<br />
sctp_diag_dump+0x3ac/0x660 net/sctp/diag.c:527<br />
__inet_diag_dump+0xa8/0x140 net/ipv4/inet_diag.c:1049<br />
inet_diag_dump+0x9b/0x110 net/ipv4/inet_diag.c:1065<br />
netlink_dump+0x606/0x1080 net/netlink/af_netlink.c:2244<br />
__netlink_dump_start+0x59a/0x7c0 net/netlink/af_netlink.c:2352<br />
netlink_dump_start include/linux/netlink.h:216 [inline]<br />
inet_diag_handler_cmd+0x2ce/0x3f0 net/ipv4/inet_diag.c:1170<br />
__sock_diag_cmd net/core/sock_diag.c:232 [inline]<br />
sock_diag_rcv_msg+0x31d/0x410 net/core/sock_diag.c:263<br />
netlink_rcv_skb+0x172/0x440 net/netlink/af_netlink.c:2477<br />
sock_diag_rcv+0x2a/0x40 net/core/sock_diag.c:274<br />
<br />
This issue occurs when asoc is peeled off and the old sk is freed after<br />
getting it by asoc->base.sk and before calling lock_sock(sk).<br />
<br />
To prevent the sk free, as a holder of the sk, ep should be alive when<br />
calling lock_sock(). This patch uses call_rcu() and moves sock_put and<br />
ep free into sctp_endpoint_destroy_rcu(), so that it&#39;s safe to try to<br />
hold the ep under rcu_read_lock in sctp_transport_traverse_process().<br />
<br />
If sctp_endpoint_hold() returns true, it means this ep is still alive<br />
and we have held it and can continue to dump it; If it returns false,<br />
it means this ep is dead and can be freed after rcu_read_unlock, and<br />
we should skip it.<br />
<br />
In sctp_sock_dump(), after locking the sk, if this ep is different from<br />
tsp->asoc->ep, it means during this dumping, this asoc was peeled off<br />
before calling lock_sock(), and the sk should be skipped; If this ep is<br />
the same with tsp->asoc->ep, it means no peeloff happens on this asoc,<br />
and due to lock_sock, no peeloff will happen either until release_sock.<br />
<br />
Note that delaying endpoint free won&#39;t delay the port release, as the<br />
port release happens in sctp_endpoint_destroy() before calling call_rcu().<br />
Also, freeing endpoint by call_rcu() makes it safe to access the sk by<br />
asoc->base.sk in sctp_assocs_seq_show() and sctp_rcv().<br />
<br />
Thanks Jones to bring this issue up.<br />
<br />
v1->v2:<br />
- improve the changelog.<br />
- add kfree(ep) into sctp_endpoint_destroy_rcu(), as Jakub noticed.
Severity CVSS v4.0: Pending analysis
Last modification:
10/04/2024