In June 2024, security researchers and the Linux kernel team resolved a potentially dangerous flaw in the kernel tracing subsystem, now tracked as CVE-2024-56763. This vulnerability revolved around the function tracing_cpumask_write and could lead to kernel warnings and possible instability when handling malicious user input. In this post, we’ll break down what happened, share links and code, and explain the risk in everyday language.
What is kernel tracing, and why does this matter?
Linux kernel tracing is a powerful debugging tool built into the Linux kernel. It lets admins and developers watch how the kernel works in real-time, helping with troubleshooting or optimization. The tracing_cpumask_write function is related to controlling which CPU cores tracing operates on, using a setting called "cpumask."
If an attacker figured out a way to abuse how cpumask accepts input, like sending a *huge* or *zero* value when not expected, things could go wrong in the kernel space, leading to warnings or possibly more severe issues. This is the problem addressed in CVE-2024-56763.
The Vulnerability in Simple Terms
When a user (with enough privileges) writes to tracing-related files from user space, the kernel handles that input. But what if someone writes an *extremely large* or *impossible* number of CPUs into the relevant file, or even tries to set the CPU mask to zero? Before the patch, this could cause:
The main issue sat inside the following code
ssize_t tracing_cpumask_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
struct trace_array *tr = filp->private_data;
cpumask_var_t new_mask;
if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
return -ENOMEM;
// Missing checks here for cnt > PAGE_SIZE or cnt ==
if (bitmap_parse_user(ubuf, cnt, , cpumask_bits(new_mask), nr_cpumask_bits)
< ) {
free_cpumask_var(new_mask);
return -EINVAL;
}
cpumask_copy(tr->tracing_cpumask, new_mask);
free_cpumask_var(new_mask);
return cnt;
}
Problem: If userspace provides an overly large cnt value to this function, the bitmap_parse_user function triggers a warning due to unexpected/bad data sizes.
Exploit Details & Proof-of-Concept (PoC)
Anyone with the right permissions (usually root, but sometimes less with poor permissions) could try to write a very large string or an empty string (length zero) to the cpumask file for tracing:
# Example of writing a huge string (simulate in test, do not crash production!)
python3 -c "print('1,'*10000)" > /sys/kernel/tracing/tracing_cpumask
# Example of writing zero bytes (empty string)
echo -n "" > /sys/kernel/tracing/tracing_cpumask
Before the fix, these tricks could trigger kernel warnings similar to
WARNING: CPU: PID: 1234 at lib/bitmap.c:XXX bitmap_parse_user()
The Official Patch
To fix this, the Linux kernel maintainers added checks to make sure cnt is not zero and not greater than a safe maximum (usually PAGE_SIZE). Here’s the patch (see commit e9c79c2e32cd):
ssize_t tracing_cpumask_write(struct file *filp, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
struct trace_array *tr = filp->private_data;
cpumask_var_t new_mask;
/* Prevent too large or zero writes */
if (!cnt || cnt > PAGE_SIZE)
return -EINVAL;
if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
return -ENOMEM;
if (bitmap_parse_user(ubuf, cnt, , cpumask_bits(new_mask), nr_cpumask_bits)
< ) {
free_cpumask_var(new_mask);
return -EINVAL;
}
cpumask_copy(tr->tracing_cpumask, new_mask);
free_cpumask_var(new_mask);
return cnt;
}
References
- Linux Kernel commit: e9c79c2e32cd ("tracing: Prevent bad count for tracing_cpumask_write")
- CVE Details for CVE-2024-56763 (pending official Mitre entry)
- Linux Kernel Tracing Documentation
Should I worry? Am I at risk?
- Who is affected?: Any unpatched Linux kernel version before this fix, with untrusted users who have write access to tracing files.
- Can remote attackers use this?: Not directly – they’d need access to your kernel tracing settings, which is privileged.
- Is it serious?: It could cause denial-of-service or instability if attackers already have special access.
Backport the commit if you maintain custom kernels (see link above).
- Restrict write access to /sys/kernel/tracing/ or /sys/kernel/debug/tracing/ as a quick stop-gap.
Conclusion
CVE-2024-56763 is yet another reminder that even “admin-only” kernel interfaces should guard against poor or malicious input. The Linux kernel team responded quickly and shipped a straightforward patch. If you care for critical Linux infrastructures or development tools, make sure to keep your system up to date and block untrusted users from writing to kernel tracing files!
*Want help checking your kernel or patching?* Drop your kernel version below, and I’ll help you figure out your next steps. Stay safe!
Timeline
Published on: 01/06/2025 17:15:42 UTC
Last modified on: 01/07/2025 23:03:48 UTC