CVE-2022-49236·Kernel vulnerability
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.
- Severity
- high
- Software
- Kernel
- Fixed in
- 5.17.2
- Published
How likely is exploitation
FIRST's Exploit Prediction Scoring System puts the probability of this CVE being exploited in the next 30 days at <0.1% — higher than 11% of all published CVEs. EPSS is an independent forecast of exploitation, not a severity rating: it says nothing about how much damage a successful attack does, which is what a CVSS score measures.
Read the two together. CVE-2022-49236 scores 7.8 on CVSS, so a successful attack would be serious — but at <0.1%, almost nobody is currently attempting it. That is a different situation from a flaw under mass exploitation, and it is usually the difference between patching on your next maintenance window and patching tonight.
Affected versions
From: 5.17
Until: 5.17.2
Fixed in: 5.17.2
How to fix this CVE
Update your Linux kernel to version 5.17.2 or later to resolve this use-after-free vulnerability in the BPF module BTF handling subsystem. The vulnerability allows a race condition between module initialization and BTF reference counting that can lead to kernel memory corruption. Perform a system reboot after patching to ensure the new kernel is active.
sudo dnf update kernel kernel-devel && sudo rebootDefensia detects this vulnerability
How to check if you are affected
- Step 1: Check installed kernel version with `uname -r` and compare against fixed version 5.17.2 or later
- Step 2: Verify if BPF programs are loaded via `bpftool prog list` to confirm the vulnerable subsystem is in active use
- Step 3: Search kernel logs for UAF-related messages with `dmesg | grep -i 'use.*after.*free\|kasan\|page.*fault'` or check `/var/log/kern.log`
- Step 4: After patching, confirm the new kernel version with `uname -r` and verify BPF functionality remains intact with `bpftool prog list`
FAQ
What is CVE-2022-49236?
This is a use-after-free vulnerability in the Linux kernel's BPF (Berkeley Packet Filter) subsystem that occurs when module BTF (BPF Type Format) resources are referenced during a race condition between module initialization and cleanup, potentially allowing memory corruption.
Is CVE-2022-49236 being actively exploited?
No, this vulnerability is not listed in the CISA Known Exploited Vulnerabilities catalog and no public exploits are currently available, though it remains a high-severity issue due to its potential impact on kernel stability.
What versions of Kernel are affected by CVE-2022-49236?
Linux kernel versions 5.17 through 5.17.1 are vulnerable; the issue is resolved in kernel 5.17.2 and later.
How do I check if my server is vulnerable to CVE-2022-49236?
Run `uname -r` to display your kernel version; if the output shows 5.17.0, 5.17.1, or any 5.17.x version below 5.17.2, your system is vulnerable.
Does Defensia detect CVE-2022-49236?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If the Linux kernel is installed on a monitored server, CVE-2022-49236 will appear in your dashboard with remediation steps.
Related Kernel CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2022-49236. Free for 1 server.
Get started free