TL;DR

The Linux kernel version 7.2 has officially removed the strncpy API after six years of development and hundreds of patches. This change aims to improve safety and performance, replacing strncpy with more reliable functions.

Linux kernel version 7.2 has officially eliminated the strncpy API after six years of development, completing a process that involved over 360 patches. The change removes a longstanding source of bugs and performance issues, replacing it with safer, more predictable functions.

For years, the strncpy() function within the Linux kernel was known to cause bugs due to its counter-intuitive semantics, especially regarding null termination and redundant zero-filling. After extensive work, the Linux kernel community has now removed all uses of strncpy in Linux 7.2. The process involved approximately 362 commits over six years, culminating in the elimination of the last per-CPU architecture implementations of strncpy.

In place of strncpy, developers are now encouraged to use functions such as strscpy() for null-terminated strings, strscpy_pad() for null-terminated strings with zero-padding, strtomem_pad() for fixed-width fields, memcpy_and_pad() for bounded copies with explicit padding, or memcpy() for known-length memory copies. These replacements aim to improve safety, reduce bugs, and enhance performance in kernel code.

Impact on Kernel Safety and Performance

The removal of strncpy from the Linux kernel marks a significant step toward safer kernel code. Since strncpy has been a persistent source of bugs due to its confusing behavior around null termination, eliminating it reduces the risk of security vulnerabilities and stability issues. Additionally, replacing it with functions that avoid unnecessary zero-filling improves overall performance, especially in memory-critical contexts.

The Linux Programming Interface: A Linux and UNIX System Programming Handbook

The Linux Programming Interface: A Linux and UNIX System Programming Handbook

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background of strncpy in Linux Kernel Development

The strncpy() function has been part of the Linux kernel for decades but was known for its problematic semantics, including difficulty in correctly handling null termination. Over the past six years, the kernel development community prioritized replacing it, resulting in hundreds of patches and the development of alternative functions better suited for kernel operations. The effort culminated in the release of Linux 7.2, which officially removes all remaining uses of strncpy.

“The elimination of strncpy reduces a long-standing source of bugs and performance bottlenecks in the Linux kernel.”

— an anonymous researcher

C++ and Linux from Scratch: The Complete Beginner’s Guide to Programming Fundamentals and Linux Basics

C++ and Linux from Scratch: The Complete Beginner’s Guide to Programming Fundamentals and Linux Basics

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Remaining Questions About Future Kernel Practices

It is not yet clear whether all kernel developers have fully adopted the new functions or if some legacy code might still rely on similar patterns. Additionally, the long-term impact on kernel development workflows and compatibility with existing modules remains to be seen.

Linux Kernel Development: The Complete Hands-On Guide to Building, Debugging, and Mastering the Linux Operating System from Scratch

Linux Kernel Development: The Complete Hands-On Guide to Building, Debugging, and Mastering the Linux Operating System from Scratch

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Next Steps for Kernel Developers and Users

Developers will likely focus on ensuring all kernel modules and subsystems fully adopt the new functions replacing strncpy. Kernel maintainers may also review other legacy code patterns for similar issues. Users should expect ongoing updates that improve kernel security and performance, with further documentation and best practices for safe programming.

Secure Coding in C# - The Workbook Edition: Hands-On Exercises, Code Challenges, and Real-World Scenarios to Build Secure .NET Applications

Secure Coding in C# – The Workbook Edition: Hands-On Exercises, Code Challenges, and Real-World Scenarios to Build Secure .NET Applications

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

Why was strncpy problematic in the Linux kernel?

Because of its confusing semantics, especially regarding null termination and redundant zero-filling, which could lead to bugs and security vulnerabilities.

What functions are replacing strncpy in Linux 7.2?

Functions like strscpy(), strscpy_pad(), strtomem_pad(), memcpy_and_pad(), and memcpy() are now used as safer alternatives.

Does this change affect Linux users directly?

Indirectly, yes. It improves overall kernel safety and performance, which benefits all Linux users through more stable and efficient systems.

Are there any compatibility issues with existing modules?

Developers are expected to update modules to use the new functions; compatibility issues are unlikely if updates are applied properly.

Will other deprecated functions be removed in future releases?

It is possible, as the kernel community continues to improve safety and performance by phasing out outdated or problematic APIs.

Source: Hacker News


You May Also Like

The Anthropic IPO Disclosure Document: What the S-1 Has to Say Before October

Anthropic’s S-1 filing, due in October 2026, will reveal critical financial and operational details, including revenue recognition and risk factors, ahead of its Nasdaq debut.