In the Linux kernel, the following vulnerability has been resolved:
tcp: prevent concurrent execution of tcpskexit_batch
Its possible that two threads call tcpskexitbatch() concurrently, once from the cleanupnet workqueue, once from a task that failed to clone a new netns. In the latter case, error unwinding calls the exit handlers in reverse order for the 'failed' netns.
tcpskexitbatch() calls tcptwskpurge(). Problem is that since commit b099ce2602d8 ("net: Batch inettwskpurge"), this function picks up twsk in any dying netns, not just the one passed in via exitbatch list.
This means that the error unwind of setup_net() can "steal" and destroy timewait sockets belonging to the exiting netns.
This allows the netns exit worker to proceed to call
WARNONONCE(!refcountdecandtest(&net->ipv4.tcpdeathrow.twrefcount));
without the expected 1 -> 0 transition, which then splats.
At same time, error unwind path that is also running inettwskpurge() will splat as well:
WARNING: .. at lib/refcount.c:31 refcountwarnsaturate+0x1ed/0x210 ... refcountdec include/linux/refcount.h:351 [inline] inettwskkill+0x758/0x9c0 net/ipv4/inettimewaitsock.c:70 inettwskdescheduleput net/ipv4/inettimewaitsock.c:221 inettwskpurge+0x725/0x890 net/ipv4/inettimewaitsock.c:304 tcpskexitbatch+0x1c/0x170 net/ipv4/tcpipv4.c:3522 opsexitlist+0x128/0x180 net/core/netnamespace.c:178 setupnet+0x714/0xb40 net/core/netnamespace.c:375 copynetns+0x2f0/0x670 net/core/netnamespace.c:508 createnewnamespaces+0x3ea/0xb10 kernel/nsproxy.c:110
... because refcountdec() of twrefcount unexpectedly dropped to 0.
This doesn't seem like an actual bug (no tw sockets got lost and I don't see a use-after-free) but as erroneous trigger of debug check.
Add a mutex to force strict ordering: the task that calls tcptwskpurge() blocks other task from doing final decand_test before mutex-owner has removed all tw sockets of dying netns.
[
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"length": 277.0,
"function_hash": "167430414399472676513158455899674322230"
},
"id": "CVE-2024-44991-0e2dd0ba",
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@f6fd2dbf584a4047ba88d1369ff91c9851261ec1",
"target": {
"file": "net/ipv4/tcp_ipv4.c",
"function": "tcp_sk_exit_batch"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"length": 277.0,
"function_hash": "167430414399472676513158455899674322230"
},
"id": "CVE-2024-44991-1888ac77",
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@565d121b69980637f040eb4d84289869cdaabedf",
"target": {
"file": "net/ipv4/tcp_ipv4.c",
"function": "tcp_sk_exit_batch"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"threshold": 0.9,
"line_hashes": [
"249806605821603186161259913259055200285",
"153291043751847599881521367783740331875",
"243031376890555221872153591917428449761",
"142995607108540992450888950813322902967",
"119646743948964429830211239099902328479",
"238278036579254109366234199789038850552",
"32772722749649028837009356749463086138",
"239422875296568987991214659481903223033",
"190863228386120364337235515353299879849",
"269387773591805881034878532106407612860"
]
},
"id": "CVE-2024-44991-19acb391",
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e3d9de3742f4d5c47ae35f888d3023a5b54fcd2f",
"target": {
"file": "net/ipv4/tcp_ipv4.c"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"length": 277.0,
"function_hash": "167430414399472676513158455899674322230"
},
"id": "CVE-2024-44991-38a96386",
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@99580ae890ec8bd98b21a2a9c6668f8f1555b62e",
"target": {
"file": "net/ipv4/tcp_ipv4.c",
"function": "tcp_sk_exit_batch"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"length": 277.0,
"function_hash": "167430414399472676513158455899674322230"
},
"id": "CVE-2024-44991-73816197",
"signature_type": "Function",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@e3d9de3742f4d5c47ae35f888d3023a5b54fcd2f",
"target": {
"file": "net/ipv4/tcp_ipv4.c",
"function": "tcp_sk_exit_batch"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"threshold": 0.9,
"line_hashes": [
"249806605821603186161259913259055200285",
"153291043751847599881521367783740331875",
"243031376890555221872153591917428449761",
"142995607108540992450888950813322902967",
"119646743948964429830211239099902328479",
"238278036579254109366234199789038850552",
"32772722749649028837009356749463086138",
"239422875296568987991214659481903223033",
"190863228386120364337235515353299879849",
"269387773591805881034878532106407612860"
]
},
"id": "CVE-2024-44991-77191df3",
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@f6fd2dbf584a4047ba88d1369ff91c9851261ec1",
"target": {
"file": "net/ipv4/tcp_ipv4.c"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"threshold": 0.9,
"line_hashes": [
"249806605821603186161259913259055200285",
"153291043751847599881521367783740331875",
"243031376890555221872153591917428449761",
"142995607108540992450888950813322902967",
"119646743948964429830211239099902328479",
"238278036579254109366234199789038850552",
"32772722749649028837009356749463086138",
"239422875296568987991214659481903223033",
"190863228386120364337235515353299879849",
"269387773591805881034878532106407612860"
]
},
"id": "CVE-2024-44991-90b92aa5",
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@99580ae890ec8bd98b21a2a9c6668f8f1555b62e",
"target": {
"file": "net/ipv4/tcp_ipv4.c"
}
},
{
"deprecated": false,
"signature_version": "v1",
"digest": {
"threshold": 0.9,
"line_hashes": [
"306942740257316457093574800753488575893",
"96765130306557746829244552156871786087",
"280965757244423749109224771621465697757",
"142995607108540992450888950813322902967",
"119646743948964429830211239099902328479",
"238278036579254109366234199789038850552",
"32772722749649028837009356749463086138",
"239422875296568987991214659481903223033",
"190863228386120364337235515353299879849",
"269387773591805881034878532106407612860"
]
},
"id": "CVE-2024-44991-f1099c16",
"signature_type": "Line",
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@565d121b69980637f040eb4d84289869cdaabedf",
"target": {
"file": "net/ipv4/tcp_ipv4.c"
}
}
]