# CVE-2024-56664: bpf, sockmap: Fix race between element replace and close()

> Archived entry. Full-text search covers entries since 2026-11-10; exact IDs work for all years.

- **Severity:** HIGH 7.8
- **CVSS:** 7.8 (v3.1, CNA) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H`
- **CVSS metrics:** Attack vector: Local; Attack complexity: Low; Privileges required: Low; User interaction: None; Scope: Unchanged; Confidentiality impact: High; Integrity impact: High; Availability impact: High
- **Exploited in the wild:** Not in CISA KEV
- **Public exploit / PoC:** None known
- **Remote exploitation:** Not remotely exploitable (local or adjacent access needed)
- **EPSS:** 0.23% (percentile 8, 2026-11-28)
- **CWE:** CWE-362, CWE-416
- **Published:** 2024-12-27T15:06:26.276Z
- **Modified:** 2026-10-15T22:18:02.410Z

## Who should check

- Anyone running Linux \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< 6deb9e85dc9a2ba4414b91c1b5b00b8415910890; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< fdb2cd8957ac51f84c9e742ba866087944bb834b; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b79a0d1e9a374d1b376933a354c4fcd01fce0365; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b015f19fedd2e12283a8450dd0aefce49ec57015; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< bf2318e288f636a882eea39f7e1015623629f168; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< ed1fc5d76b81a4d681211333c026202cad4d5649
- Anyone running Linux 4.20

## Description

In the Linux kernel, the following vulnerability has been resolved:

bpf, sockmap: Fix race between element replace and close()

Element replace (with a socket different from the one stored) may race
with socket's close() link popping & unlinking. \_\_sock\_map\_delete()
unconditionally unrefs the (wrong) element:

// set map\[0\] = s0
map\_update\_elem(map, 0, s0)

// drop fd of s0
close(s0)
  sock\_map\_close()
    lock\_sock(sk)               (s0!)
    sock\_map\_remove\_links(sk)
      link = sk\_psock\_link\_pop()
      sock\_map\_unlink(sk, link)
        sock\_map\_delete\_from\_link
                                        // replace map\[0\] with s1
                                        map\_update\_elem(map, 0, s1)
                                          sock\_map\_update\_elem
                                (s1!)       lock\_sock(sk)
                                            sock\_map\_update\_common
                                              psock = sk\_psock(sk)
                                              spin\_lock(&stab-\>lock)
                                              osk = stab-\>sks\[idx\]
                                              sock\_map\_add\_link(..., &stab-\>sks\[idx\])
                                              sock\_map\_unref(osk, &stab-\>sks\[idx\])
                                                psock = sk\_psock(osk)
                                                sk\_psock\_put(sk, psock)
                                                  if (refcount\_dec\_and\_test(&psock))
                                                    sk\_psock\_drop(sk, psock)
                                              spin\_unlock(&stab-\>lock)
                                            unlock\_sock(sk)
          \_\_sock\_map\_delete
            spin\_lock(&stab-\>lock)
            sk = \*psk                        // s1 replaced s0; sk == s1
            if (!sk\_test \|\| sk\_test == sk)   // sk\_test (s0) != sk (s1); no branch
              sk = xchg(psk, NULL)
            if (sk)
              sock\_map\_unref(sk, psk)        // unref s1; sks\[idx\] will dangle
                psock = sk\_psock(sk)
                sk\_psock\_put(sk, psock)
                  if (refcount\_dec\_and\_test())
                    sk\_psock\_drop(sk, psock)
            spin\_unlock(&stab-\>lock)
    release\_sock(sk)

Then close(map) enqueues bpf\_map\_free\_deferred, which finally calls
sock\_map\_free(). This results in some refcount\_t warnings along with
a KASAN splat \[1\].

Fix \_\_sock\_map\_delete(), do not allow sock\_map\_unref() on elements that
may have been replaced.

\[1\]:
BUG: KASAN: slab-use-after-free in sock\_map\_free+0x10e/0x330
Write of size 4 at addr ffff88811f5b9100 by task kworker/u64:12/1063

CPU: 14 UID: 0 PID: 1063 Comm: kworker/u64:12 Not tainted 6.12.0+ \#125
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Arch Linux 1.16.3-1-1 04/01/2014
Workqueue: events\_unbound bpf\_map\_free\_deferred
Call Trace:
 \<TASK\>
 dump\_stack\_lvl+0x68/0x90
 print\_report+0x174/0x4f6
 kasan\_report+0xb9/0x190
 kasan\_check\_range+0x10f/0x1e0
 sock\_map\_free+0x10e/0x330
 bpf\_map\_free\_deferred+0x173/0x320
 process\_one\_work+0x846/0x1420
 worker\_thread+0x5b3/0xf80
 kthread+0x29e/0x360
 ret\_from\_fork+0x2d/0x70
 ret\_from\_fork\_asm+0x1a/0x30
 \</TASK\>

Allocated by task 1202:
 kasan\_save\_stack+0x1e/0x40
 kasan\_save\_track+0x10/0x30
 \_\_kasan\_slab\_alloc+0x85/0x90
 kmem\_cache\_alloc\_noprof+0x131/0x450
 sk\_prot\_alloc+0x5b/0x220
 sk\_alloc+0x2c/0x870
 unix\_create1+0x88/0x8a0
 unix\_create+0xc5/0x180
 \_\_sock\_create+0x241/0x650
 \_\_sys\_socketpair+0x1ce/0x420
 \_\_x64\_sys\_socketpair+0x92/0x100
 do\_syscall\_64+0x93/0x180
 entry\_SYSCALL\_64\_after\_hwframe+0x76/0x7e

Freed by task 46:
 kasan\_save\_stack+0x1e/0x40
 kasan\_save\_track+0x10/0x30
 kasan\_save\_free\_info+0x37/0x60
 \_\_kasan\_slab\_free+0x4b/0x70
 kmem\_cache\_free+0x1a1/0x590
 \_\_sk\_destruct+0x388/0x5a0
 sk\_psock\_destroy+0x73e/0xa50
 process\_one\_work+0x846/0x1420
 worker\_thread+0x5b3/0xf80
 kthread+0x29e/0x360
 ret\_from\_fork+0x2d/0x70
 ret\_from\_fork\_asm+0x1a/0x30

The bu
---truncated---

## Affected and fixed versions

- Linux: \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< 6deb9e85dc9a2ba4414b91c1b5b00b8415910890; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< fdb2cd8957ac51f84c9e742ba866087944bb834b; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b79a0d1e9a374d1b376933a354c4fcd01fce0365; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b015f19fedd2e12283a8450dd0aefce49ec57015; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< bf2318e288f636a882eea39f7e1015623629f168; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< ed1fc5d76b81a4d681211333c026202cad4d5649 (cvelist)
- Linux: 4.20 (cvelist)

## Mitigation

- No fix listed yet: follow the vendor advisory.

## Check your systems with an agent

Paste this into a coding agent:

```text
Check whether anything I run is affected by CVE-2024-56664. Work read-only: do not install, upgrade, delete or change anything.

Details: https://flawdb.com/CVE-2024-56664.md
Affected: Linux >= 604326b41a6fb9b4a78b6179335decee0365cd8c, < 6deb9e85dc9a2ba4414b91c1b5b00b8415910890; >= 604326b41a6fb9b4a78b6179335decee0365cd8c, < fdb2cd8957ac51f84c9e742ba866087944bb834b; >= 604326b41a6fb9b4a78b6179335decee0365cd8c, < b79a0d1e9a374d1b376933a354c4fcd01fce0365; >= 604326b41a6fb9b4a78b617…
Fixed in: Linux 6deb9e85dc9a2ba4414b91c1b5b00b8415910890

Steps:
1. Search this machine and project for Linux: dependency manifests and lockfiles, installed packages, container images and running services.
2. For each match, note the installed version and whether it is inside the affected range.
3. Report a table: location, installed version, affected (yes / no / unsure), evidence. If affected, say which fixed version or mitigation from the details link applies, but don't apply it.
```

## FAQ

### Is CVE-2024-56664 being exploited?

There is no confirmed exploitation: CVE-2024-56664 is not in the CISA Known Exploited Vulnerabilities catalog. No public exploit code is known. EPSS estimates a 0.23% chance of exploitation in the next 30 days (as of 2026-11-28).

### How serious is CVE-2024-56664?

High: CVSS 7.8 (v3.1, scored by CNA). Not remotely exploitable (local or adjacent access needed).

### Which versions are affected by CVE-2024-56664?

Linux \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< 6deb9e85dc9a2ba4414b91c1b5b00b8415910890; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< fdb2cd8957ac51f84c9e742ba866087944bb834b; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b79a0d1e9a374d1b376933a354c4fcd01fce0365; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< b015f19fedd2e12283a8450dd0aefce49ec57015; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< bf2318e288f636a882eea39f7e1015623629f168; \>= 604326b41a6fb9b4a78b6179335decee0365cd8c, \< ed1fc5d76b81a4d681211333c026202cad4d5649; Linux 4.20.

### Is there a fix for CVE-2024-56664?

Yes. Fixed in Linux 6deb9e85dc9a2ba4414b91c1b5b00b8415910890. No fix listed yet: follow the vendor advisory.

### How do I check if I'm affected by CVE-2024-56664?

Find where you use the affected software (dependency lockfiles, installed packages, container images, servers) and compare the installed version with the affected range above. The agent prompt on this page does this read-only.

## References

- patch: <https://git.kernel.org/stable/c/b015f19fedd2e12283a8450dd0aefce49ec57015>
- patch: <https://git.kernel.org/stable/c/bf2318e288f636a882eea39f7e1015623629f168>
- patch: <https://git.kernel.org/stable/c/ed1fc5d76b81a4d681211333c026202cad4d5649>
- other: <https://git.kernel.org/stable/c/6deb9e85dc9a2ba4414b91c1b5b00b8415910890>
- other: <https://git.kernel.org/stable/c/fdb2cd8957ac51f84c9e742ba866087944bb834b>
- other: <https://git.kernel.org/stable/c/b79a0d1e9a374d1b376933a354c4fcd01fce0365>
- other: <https://lists.debian.org/debian-lts-announce/2025/05/msg00030.html>
- other: <https://lists.debian.org/debian-lts-announce/2025/03/msg00001.html>

## Attribution

- CVE Program: CVE® is a registered trademark of The MITRE Corporation. CVE records © 1999–2026 The MITRE Corporation. <https://www.cve.org/Legal/TermsOfUse>
- NVD: This product uses data from the NVD API but is not endorsed or certified by the NVD. <https://nvd.nist.gov/vuln/detail/CVE-2024-56664>

HTML: <https://flawdb.com/CVE-2024-56664> · JSON: <https://flawdb.com/api/v1/entries/CVE-2024-56664>
