In June 2024, a new security vulnerability was patched in the Linux kernel, specifically inside the AMD display subsystem. Tracked as CVE-2024-42227, this issue lied in how the kernel copied memory within critical graphics driver code for AMD GPUs. It may sound like just another bug, but a close look shows the risks: possible data corruption, kernel crashes, or even a window of opportunity for attackers.

This article cuts through jargon and dives into exactly what went wrong, how it was fixed, and what it means for Linux users. Whether you’re a developer, security enthusiast, or just someone curious about real-world bugs, keep reading for a deep (but approachable) breakdown.

What Happened: The Core Bug

The bug lived in the AMD GPU driver, specifically the code managing display timings and watermarks—a part of AMD’s DC (Display Core) library used by the kernel’s DRM (Direct Rendering Manager) subsystem. Here’s the problem in plain English:

A memcpy call tried to copy a structure from one place to another, but both pointers pointed to the exact same spot in memory.

When you use memcpy() and the source and destination overlap, weird bugs can happen: data gets clobbered, values get scrambled, and in the worst cases, it can lead to security holes or system crashes.

Let’s see a simplified version of the problematic code.

Here’s what went wrong

// Inside dml_core_mode_programming.c

memcpy(&mode_lib->mp.Watermark,
       &locals->Watermark,
       sizeof(struct dml_watermark_set));

In the actual scenario, &mode_lib->mp.Watermark and &locals->Watermark ended up pointing to the same address.

The Proper Fix: Using memmove

The patch replaces memcpy() with memmove(), which is designed for safe copying, even if areas overlap.

Fixed Version

memmove(&mode_lib->mp.Watermark,
        &locals->Watermark,
        sizeof(struct dml_watermark_set));

Why memmove?

- Guarantees correctness, even with overlapping source/destination.

Patch upstream (commit):

drm/amd/display: Fix overlapping copy within dml_core_mode_programming

CVE Details:

CVE-2024-42227 at NVD

AMD GPU DC Code:

AMD Display Core (DC) on kernel.org

In this particular situation, a clever attacker might attempt to

- Trigger code paths where the kernel tries to memcpy overlapping regions (user control is highly limited).
- This could, in theory, cause the GPU driver to misuse corrupted data, potentially leading to kernel crashes or unpredictable behavior.
- With specific GPU access and timing, a local user might have a narrow chance to escalate privileges or destabilize the system.

In summary: While practical exploitation is not trivial due to code path requirements, it does create a hard-to-debug, kernel-level instability risk, justifying the CVE.

Am I Affected, and What Should I Do?

- You may be affected if running a kernel version before the patch and using AMD GPUs with DC-enabled drivers.

Fix:

- Update your Linux kernel to include this fix (kernel 6.10+ or backported in various distributions; check your distro security advisories).

Conclusion

CVE-2024-42227 serves as another reminder that even simple mistakes, like using the wrong memory copy function, can have serious consequences in software as complex and privileged as the Linux kernel.

Stay updated with security patches, and always review code changes—especially those touching memory operations in low-level code.

Further Reading

- Difference between memcpy and memmove (StackOverflow)
- Understanding Undefined Behavior in C (Wikipedia)


If you found this analysis useful, please bookmark or share it! For developers: always use memmove when in doubt about memory overlap.

Timeline

Published on: 07/30/2024 08:15:07 UTC
Last modified on: 07/30/2024 20:15:03 UTC