In the Linux kernel, the following vulnerability has been resolved:
bpf: reject unhashed sockets in bpfskassign
The semantics for bpfskassign are as follows:
sk = some_lookup_func()
bpf_sk_assign(skb, sk)
bpf_sk_release(sk)
That is, the sk is not consumed by bpfskassign. The function therefore needs to make sure that sk lives long enough to be consumed from _inetlookup_skb. The path through the stack for a TCPv4 packet is roughly:
netifreceiveskbcore: takes RCU read lock _netifreceiveskbcore: schhandleingress: tcfclassify: bpfskassign() deliverptypelistskb: deliverskb: ippackettype->func == iprcv: iprcvcore: iprcvfinishcore: dstinput: iplocaldeliver: iplocaldeliverfinish: ipprotocoldeliverrcu: tcpv4rcv: _inetlookupskb: skbstealsock
The existing helper takes advantage of the fact that everything happens in the same RCU critical section: for sockets with SOCKRCUFREE set bpfskassign never takes a reference. skbstealsock then checks SOCKRCUFREE again and does sock_put if necessary.
This approach assumes that SOCKRCUFREE is never set on a sk between bpfskassign and skbstealsock, but this invariant is violated by unhashed UDP sockets. A new UDP socket is created in TCPCLOSE state but without SOCKRCUFREE set. That flag is only added in udplibgetport() which happens when a socket is bound.
When bpfskassign was added it wasn't possible to access unhashed UDP sockets from BPF, so this wasn't a problem. This changed in commit 0c48eefae712 ("sock_map: Lift socket state restriction for datagram sockets"), but the helper wasn't adjusted accordingly. The following sequence of events will therefore lead to a refcount leak:
Fix the problem by rejecting unhashed sockets in bpfskassign(). This matches the behaviour of _inetlookupskb which is ultimately the goal of bpfsk_assign().
{
"cna_assigner": "Linux",
"osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2023/53xxx/CVE-2023-53585.json"
}"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2023-53585.json"
[
{
"id": "CVE-2023-53585-0a5b9c3e",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@67312adc96b5a585970d03b62412847afe2c6b01",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-31adb585",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@791a12102e5191dcb6ce0b3a99d71b5a2802d12a",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
},
{
"id": "CVE-2023-53585-3510dce7",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@3d4522f59fb748a54446846522941a4f09da63e9",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
},
{
"id": "CVE-2023-53585-3dca4d73",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@c0ce0fb76610d5fad31f56f2ca8241a2a6717a1b",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
},
{
"id": "CVE-2023-53585-3facaa59",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7dcbc0bb0e5cc1823923744befce59ac353135e6",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-6ed1010b",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8aa43cfbb68b25119d2ced14ec717173e2901fa2",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-7a52949b",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7dcbc0bb0e5cc1823923744befce59ac353135e6",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
},
{
"id": "CVE-2023-53585-8e9e5212",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@c0ce0fb76610d5fad31f56f2ca8241a2a6717a1b",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-c0e10150",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@67312adc96b5a585970d03b62412847afe2c6b01",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
},
{
"id": "CVE-2023-53585-c40a284f",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@3d4522f59fb748a54446846522941a4f09da63e9",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-cb86ae2f",
"target": {
"function": "BPF_CALL_3",
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@791a12102e5191dcb6ce0b3a99d71b5a2802d12a",
"digest": {
"function_hash": "337389194893388626895299650417757313332",
"length": 541.0
},
"signature_type": "Function"
},
{
"id": "CVE-2023-53585-dbc00229",
"target": {
"file": "net/core/filter.c"
},
"signature_version": "v1",
"deprecated": false,
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@8aa43cfbb68b25119d2ced14ec717173e2901fa2",
"digest": {
"threshold": 0.9,
"line_hashes": [
"79354962422427016246252354043139641247",
"219299604263347496053978971757721847787",
"64013543073505417623104265435606620045",
"316351947271244352888373922836301827769"
]
},
"signature_type": "Line"
}
]