CVE-2024-53193: clk: clk-loongson2: Fix memory corruption bug in struct loongson2_clk_provider
In the Linux kernel, the following vulnerability has been resolved:
clk: clk-loongson2: Fix memory corruption bug in struct loongson2clkprovider
Some heap space is allocated for the flexible structure struct clkhwonecelldata and its flexible-array member hws through the composite structure struct loongson2clkprovider in function loongson2clkprobe(), as shown below:
289 struct loongson2clkprovider clp; ... 296 for (p = data; p->name; p++) 297 clksnum++; 298 299 clp = devmkzalloc(dev, structsize(clp, clkdata.hws, clksnum), 300 GFPKERNEL);
Then some data is written into the flexible array:
350 clp->clkdata.hws[p->id] = hw;
This corrupts clklock, which is the spinlock variable immediately following the clkdata member in struct loongson2clkprovider:
struct loongson2clkprovider { void iomem base; struct device dev; struct clkhwonecelldata clkdata; spinlockt clklock; / protect access to DIV registers / };
The problem is that the flexible structure is currently placed in the middle of struct loongson2clkprovider instead of at the end.
Fix this by moving struct clkhwonecelldata clkdata; to the end of struct loongson2clkprovider. Also, add a code comment to help prevent this from happening again in case new members are added to the structure in the future.
This change also fixes the following -Wflex-array-member-not-at-end warning:
drivers/clk/clk-loongson2.c:32:36: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
debian/linuxto a version that resolves this vulnerability.Fixed in 5.10.223-1Fixed in 5.10.234-1Fixed in 6.1.129-1Fixed in 6.1.135-1Fixed in 6.12.22-1Fixed in 6.12.25-1 - Configuration
Fix the memory corruption bug by relocating the flexible array container `struct clk_hw_onecell_data clk_data;` so it is the final member in `struct loongson2_clk_provider` (currently it is placed before `base`/`dev`/other members per the excerpt). Update `loongson2_clk_probe()` accordingly and ensure the flexible-array member `clk_data.hws` is only written within the allocated flexible tail.
Linux kernel (drivers/clk/clk-loongson2.c) struct loongson2_clk_provider layout = Move `struct clk_hw_onecell_data clk_data;` to the end of `struct loongson2_clk_provider` - Configuration
Add a code comment near the `struct loongson2_clk_provider` definition explaining that `struct clk_hw_onecell_data clk_data;` must remain the last member of the struct because it contains the flexible array member `hws`, otherwise the allocation via `struct_size(..., clk_data.hws, clks_num)` can corrupt the subsequent fields (e.g., `spinlock_t clk_lock`).
Linux kernel (drivers/clk/clk-loongson2.c) Code comment = Add a code comment preventing future flexible-array placement regressions
Event History
Frequently Asked Questions
What is the severity of CVE-2024-53193?
CVE-2024-53193 is classified as a medium severity vulnerability in the Linux kernel.
How do I fix CVE-2024-53193?
To resolve CVE-2024-53193, upgrade your Linux kernel to one of the fixed versions such as 5.10.223-1 or 6.12.15-1.
Which versions of the Linux kernel are affected by CVE-2024-53193?
CVE-2024-53193 affects specific versions of the Linux kernel prior to the patched releases, including versions before 5.10.223-1, 6.1.123-1, and 6.12.12-1.
What type of vulnerability is CVE-2024-53193?
CVE-2024-53193 is a memory corruption vulnerability found in the clk-loongson2 functionality of the Linux kernel.
Is CVE-2024-53193 related to any specific hardware or software?
CVE-2024-53193 primarily affects systems using the Linux kernel, particularly in relation to the Loongson2 clock provider implementation.