# CVE-2022-49236: bpf: Fix UAF due to race between btf\_try\_get\_module and load\_module

> 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.30% (percentile 15, 2026-11-26)
- **CWE:** CWE-416
- **Published:** 2025-02-26T01:56:00.689Z
- **Modified:** 2026-06-17T05:17:28.370Z

## Who should check

- Anyone running Linux \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 51b82141fffa454abf937a8ff0b8af89e4fd0c8f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< d7fccf264b1a785525b366a5b7f8113c756187ad; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 0481baa2318cb1ab13277715da6cdbb657807b3f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 18688de203b47e5d8d9d0953385bf30b5949324f
- Anyone running Linux 5.12

## Description

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

bpf: Fix UAF due to race between btf\_try\_get\_module and load\_module

While working on code to populate kfunc BTF ID sets for module BTF from
its initcall, I noticed that by the time the initcall is invoked, the
module BTF can already be seen by userspace (and the BPF verifier). The
existing btf\_try\_get\_module calls try\_module\_get which only fails if
mod-\>state == MODULE\_STATE\_GOING, i.e. it can increment module reference
when module initcall is happening in parallel.

Currently, BTF parsing happens from MODULE\_STATE\_COMING notifier
callback. At this point, the module initcalls have not been invoked.
The notifier callback parses and prepares the module BTF, allocates an
ID, which publishes it to userspace, and then adds it to the btf\_modules
list allowing the kernel to invoke btf\_try\_get\_module for the BTF.

However, at this point, the module has not been fully initialized (i.e.
its initcalls have not finished). The code in module.c can still fail
and free the module, without caring for other users. However, nothing
stops btf\_try\_get\_module from succeeding between the state transition
from MODULE\_STATE\_COMING to MODULE\_STATE\_LIVE.

This leads to a use-after-free issue when BPF program loads
successfully in the state transition, load\_module's do\_init\_module call
fails and frees the module, and BPF program fd on close calls module\_put
for the freed module. Future patch has test case to verify we don't
regress in this area in future.

There are multiple points after prepare\_coming\_module (in load\_module)
where failure can occur and module loading can return error. We
illustrate and test for the race using the last point where it can
practically occur (in module \_\_init function).

An illustration of the race:

CPU 0                           CPU 1
			  load\_module
			    notifier\_call(MODULE\_STATE\_COMING)
			      btf\_parse\_module
			      btf\_alloc\_id	// Published to userspace
			      list\_add(&btf\_mod-\>list, btf\_modules)
			    mod-\>init(...)
...				^
bpf\_check		        \|
check\_pseudo\_btf\_id             \|
  btf\_try\_get\_module            \|
    returns true                \|  ...
...                             \|  module \_\_init in progress
return prog\_fd                  \|  ...
...                             V
			    if (ret \< 0)
			      free\_module(mod)
			    ...
close(prog\_fd)
 ...
 bpf\_prog\_free\_deferred
  module\_put(used\_btf.mod) // use-after-free

We fix this issue by setting a flag BTF\_MODULE\_F\_LIVE, from the notifier
callback when MODULE\_STATE\_LIVE state is reached for the module, so that
we return NULL from btf\_try\_get\_module for modules that are not fully
formed. Since try\_module\_get already checks that module is not in
MODULE\_STATE\_GOING state, and that is the only transition a live module
can make before being removed from btf\_modules list, this is enough to
close the race and prevent the bug.

A later selftest patch crafts the race condition artifically to verify
that it has been fixed, and that verifier fails to load program (with
ENXIO).

Lastly, a couple of comments:

 1. Even if this race didn't exist, it seems more appropriate to only
    access resources (ksyms and kfuncs) of a fully formed module which
    has been initialized completely.

 2. This patch was born out of need for synchronization against module
    initcall for the next patch, so it is needed for correctness even
    without the aforementioned race condition. The BTF resources
    initialized by module initcall are set up once and then only looked
    up, so just waiting until the initcall has finished ensures correct
    behavior.

## Affected and fixed versions

- Linux: \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 51b82141fffa454abf937a8ff0b8af89e4fd0c8f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< d7fccf264b1a785525b366a5b7f8113c756187ad; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 0481baa2318cb1ab13277715da6cdbb657807b3f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 18688de203b47e5d8d9d0953385bf30b5949324f (cvelist)
- Linux: 5.12 (cvelist)

## Mitigation

- Upgrade Linux to 18688de203b47e5d8d9d0953385bf30b5949324f or later.

## Check your systems with an agent

Paste this into a coding agent:

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

Details: https://flawdb.com/CVE-2022-49236.md
Affected: Linux >= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, < 51b82141fffa454abf937a8ff0b8af89e4fd0c8f; >= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, < d7fccf264b1a785525b366a5b7f8113c756187ad; >= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, < 0481baa2318cb1ab13277715da6cdbb657807b3f; >= 541c3bad8dc51b253ba8686…
Fixed in: Linux 51b82141fffa454abf937a8ff0b8af89e4fd0c8f, Linux 0481baa2318cb1ab13277715da6cdbb657807b3f, Linux 18688de203b47e5d8d9d0953385bf30b5949324f

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-2022-49236 being exploited?

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

### How serious is CVE-2022-49236?

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

### Which versions are affected by CVE-2022-49236?

Linux \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 51b82141fffa454abf937a8ff0b8af89e4fd0c8f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< d7fccf264b1a785525b366a5b7f8113c756187ad; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 0481baa2318cb1ab13277715da6cdbb657807b3f; \>= 541c3bad8dc51b253ba8686d0cd7628e6b9b5f4c, \< 18688de203b47e5d8d9d0953385bf30b5949324f; Linux 5.12.

### Is there a fix for CVE-2022-49236?

Yes. Fixed in Linux 51b82141fffa454abf937a8ff0b8af89e4fd0c8f, Linux 0481baa2318cb1ab13277715da6cdbb657807b3f, Linux 18688de203b47e5d8d9d0953385bf30b5949324f. Upgrade Linux to 18688de203b47e5d8d9d0953385bf30b5949324f or later.

### How do I check if I'm affected by CVE-2022-49236?

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/51b82141fffa454abf937a8ff0b8af89e4fd0c8f>
- patch: <https://git.kernel.org/stable/c/d7fccf264b1a785525b366a5b7f8113c756187ad>
- patch: <https://git.kernel.org/stable/c/0481baa2318cb1ab13277715da6cdbb657807b3f>
- patch: <https://git.kernel.org/stable/c/18688de203b47e5d8d9d0953385bf30b5949324f>

## 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-2022-49236>

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