CVE-2024-53680: ipvs: fix UB due to uninitialized stack access in ip_vs_protocol_init()
In the Linux kernel, the following vulnerability has been resolved:
ipvs: fix UB due to uninitialized stack access in ipvsprotocolinit()
Under certain kernel configurations when building with Clang/LLVM, the compiler does not generate a return or jump as the terminator instruction for ipvsprotocolinit(), triggering the following objtool warning during build time:
vmlinux.o: warning: objtool: ipvsprotocolinit() falls through to next function initstubkmodipvsrr935123ipvsrrinit6()
At runtime, this either causes an oops when trying to load the ipvs module or a boot-time panic if ipvs is built-in. This same issue has been reported by the Intel kernel test robot previously.
Digging deeper into both LLVM and the kernel code reveals this to be a undefined behavior problem. ipvsprotocolinit() uses a on-stack buffer of 64 chars to store the registered protocol names and leaves it uninitialized after definition. The function calls strnlen() when concatenating protocol names into the buffer. With CONFIGFORTIFYSOURCE strnlen() performs an extra step to check whether the last byte of the input char buffer is a null character (commit 3009f891bb9f ("fortify: Allow strlen() and strnlen() to pass compile-time known lengths")). This, together with possibly other configurations, cause the following IR to be generated:
define hidden i32 @ipvsprotocolinit() localunnamedaddr #5 section ".init.text" align 16 !kcfitype !29 { %1 = alloca [64 x i8], align 16 ...
14: ; preds = %11 %15 = getelementptr inbounds i8, ptr %1, i64 63 %16 = load i8, ptr %15, align 1 %17 = tail call i1 @llvm.is.constant.i8(i8 %16) %18 = icmp eq i8 %16, 0 %19 = select i1 %17, i1 %18, i1 false br i1 %19, label %20, label %23
20: ; preds = %14 %21 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #23 ...
23: ; preds = %14, %11, %20 %24 = call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %1, i64 noundef 64) #24 ... }
The above code calculates the address of the last char in the buffer (value %15) and then loads from it (value %16). Because the buffer is never initialized, the LLVM GVN pass marks value %16 as undefined:
%13 = getelementptr inbounds i8, ptr %1, i64 63 br i1 undef, label %14, label %17
This gives later passes (SCCP, in particular) more DCE opportunities by propagating the undef value further, and eventually removes everything after the load on the uninitialized stack location:
define hidden i32 @ipvsprotocolinit() localunnamedaddr #0 section ".init.text" align 16 !kcfitype !11 { %1 = alloca [64 x i8], align 16 ...
12: ; preds = %11 %13 = getelementptr inbounds i8, ptr %1, i64 63 unreachable }
In this way, the generated native code will just fall through to the next function, as LLVM does not generate any code for the unreachable IR instruction and leaves the function without a terminator.
Zero the on-stack buffer to avoid this possible UB.
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.234-1Fixed in 6.1.129-1Fixed in 6.1.135-1Fixed in 6.12.25-1Fixed in 6.12.27-1 - Upgrade
Upgrade
debian/linux-6.1to a version that resolves this vulnerability.Fixed in 6.1.129-1~deb11u1 - Upgrade
Upgrade
Linux kernel ipvsto a version that resolves this vulnerability.Patch ipvs: fix UB due to uninitialized stack access in ip_vs_protocol_init() - Configuration
If building with CONFIG_FORTIFY_SOURCE, ensure the ipvs fix for UB/uninitialized stack access in ip_vs_protocol_init() is present so fortify’s strlen/strnlen behavior (commit 3009f891bb9f) does not trigger the problematic access.
Linux kernel (fortify) CONFIG_FORTIFY_SOURCE = enabled - Operational
Rebuild the kernel/image with the ipvs fix applied, since the issue occurs during compilation (objtool warning about ip_vs_protocol_init() falling through) and can cause an oops when loading the ipvs module or a boot-time panic when ipvs is built-in.
Event History
Frequently Asked Questions
What is the severity of CVE-2024-53680?
CVE-2024-53680 has a severity rating of medium, indicating a potential risk under specific configurations.
How do I fix CVE-2024-53680?
To address CVE-2024-53680, update the Linux kernel to the latest patched version provided by your distribution.
What systems are affected by CVE-2024-53680?
CVE-2024-53680 primarily affects systems running the Linux kernel compiled with Clang/LLVM.
What consequences could result from CVE-2024-53680?
Exploitation of CVE-2024-53680 could lead to undefined behavior due to uninitialized stack access, potentially compromising system stability.
When was CVE-2024-53680 publicly disclosed?
CVE-2024-53680 was publicly disclosed alongside its fix in the Linux kernel updates.