Kees Cook deleted strncpy from the Linux kernel
Linux 7.2 removed strncpy after six years and about 362 commits. Here are the strscpy, strtomem_pad and memcpy replacements and when to use each.
Linux 7.2 ships without a single caller of strncpy(). The merge landed on a Friday and removed the generic API along with the last per-architecture strncpy implementations. Getting there took about six years and roughly 362 commits to convert every user in the tree.
strncpy has been deprecated in the kernel for years, and the reasons are the ones that have tripped up C programmers for decades. The function copies up to a fixed number of bytes from source to destination. If the source string is shorter than that limit, strncpy pads the rest of the destination with NUL bytes. If the source is as long as or longer than the limit, it writes no terminating NUL at all. You get a buffer that looks like a string but is not NUL-terminated, and the next function that treats it as one reads past the end.
Sometimes padding, sometimes not terminating: that is what the kernel developers mean when they call the semantics counter-intuitive. The zero-filling is also a performance cost. Every short copy into a large buffer writes out the remaining bytes as NUL whether or not anything depends on them. Across a kernel’s worth of fixed-size fields, that adds up, and it hid real bugs where the termination simply never happened.
There is no single drop-in replacement, which is the point. The conversion forced each call site to say what the destination actually is:
strscpy()for NUL-terminated destinations.strscpy_pad()for NUL-terminated destinations that also need zero-padding.strtomem_pad()for non-NUL-terminated fixed-width fields.memcpy_and_pad()for bounded copies with explicit padding.memcpy()for known-length memory copies.
Each of those encodes a decision strncpy left implicit: is the target a C string or a fixed-width byte field, and does the unused tail need to be zeroed? strncpy answered both questions silently and often wrongly. The replacements make you answer them in the name of the function you call.
If you maintain out-of-tree modules or backport patches against recent kernels, strncpy is no longer available to you. Map each use to the destination’s contract rather than reaching for the nearest string copy. A field that other code reads as a C string wants strscpy(); add _pad only when the trailing bytes genuinely need to be zero. A fixed-width field that is never treated as a terminated string wants strtomem_pad() or memcpy_and_pad(), and a copy whose length you already know wants plain memcpy(). Picking the wrong one reintroduces exactly the ambiguity this work spent six years removing.
Keep Reading
linux-kernelLinux kernel deleted strncpy across 360 patches
Linux 7.2 removed strncpy() from the kernel after six years and 362 commits. What the replacements are and how to port out-of-tree code.
ubuntuUbuntu still has no patch for CVSS 9.8 kernel flaw
CVE-2026-98432 is a CVSS 9.8 remote root flaw in the Linux kernel's TCP code. Debian patched it October 16; Ubuntu still has no fix two weeks on.
rustSafe Rust prints freed stack memory
Rust issue #164250 exposes an 11-year borrow-checker unsoundness: covariant field assignment lets a malicious Drop read freed stack memory in safe Rust.
Latest on the Wire
Full wire →- AI Coding Agents Boost Output But Code Review Bottlenecks IncreaseHacker News
- AI Overviews Cut Organic Traffic by 40%Hacker News
- Apache Patches Critical Roller RCE VulnerabilityBleepingComputer
- Complete Web Browser Built from Scratch in PythonHacker News
New signal daily · RSS
Stay in the loop
New writing delivered when it's ready. No schedule, no spam.