Linux Eliminates the Strncpy API After Six Years of Work, 360 Patches
AIThis post was created with the assistance of artificial intelligence (AI).

TL;DR

Prime Big Deal Days · Oct 6–7Offer from Amazon

Get the latest gadgets delivered free — and shop member deals

  • Fast, free delivery on millions of items
  • Access to Prime Big Deal Days deals on October 6–7
  • Prime Video, Amazon Music and more included
Start your free Prime trial Free trial for eligible customers · Cancel anytime
As an affiliate, we earn on qualifying purchases.

Linux kernel version 7.2 has removed the deprecated strncpy API after six years of development and hundreds of patches. The change aims to improve kernel safety and performance by replacing it with safer functions.

Linux kernel version 7.2 has officially removed the strncpy API after six years of development and over 360 patches, concluding a long-term effort to improve kernel safety and performance.

The Linux kernel team completed the removal of the strncpy() function in Linux 7.2, ending a six-year effort involving approximately 362 commits. The function, used for copying up to a specified number of bytes, has been a persistent source of bugs due to its counter-intuitive semantics and issues with NUL termination. Its removal aligns with efforts to enhance kernel stability and security.

In place of strncpy, developers are encouraged to use alternative functions such as strscpy(), strscpy_pad(), strtomem_pad(), memcpy_and_pad(), or memcpy(), depending on the specific use case. The change affects the last remaining per-CPU architecture implementations of strncpy, which have now been phased out.

Why Removing strncpy Improves Kernel Safety and Performance

The elimination of the strncpy API from the Linux kernel reduces the risk of bugs caused by its confusing behavior and inefficient zero-filling operations. It also aligns the kernel with safer string handling practices, potentially preventing security vulnerabilities related to buffer overflows or improper string termination. This change reflects ongoing efforts to modernize and harden the Linux kernel codebase.

Amazon

Linux kernel development toolkit

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Background on Linux Kernel String Handling Changes

The strncpy() function has been part of the Linux kernel for years but has been criticized for its confusing semantics, especially around NUL termination and performance issues due to redundant zero-filling. Over the past six years, developers have worked through hundreds of patches to replace its usage with safer alternatives. The move to remove it culminates with the release of Linux 7.2, which is part of broader efforts to improve kernel code safety and maintainability.

“The removal of strncpy from the Linux kernel is a significant step toward safer and more efficient code. Its long history of bugs and performance issues made it a prime candidate for deprecation.”

— an anonymous researcher

Amazon

safe string handling libraries for C programming

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Remaining Questions About Kernel String Handling Changes

It is not yet clear how widely adopted the new recommended functions will become across all kernel modules or if legacy code will persist in some branches. Additionally, the impact on kernel modules that relied heavily on strncpy remains to be seen in real-world applications.

Amazon

Linux kernel patch management tools

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Next Steps for Kernel Developers and Users

Kernel developers are expected to adopt the new string handling functions in future code updates, and distributions will incorporate Linux 7.2 with these changes. Monitoring the transition will be important to ensure compatibility and stability, especially for legacy systems still using older code.

Amazon

software development debugging tools

As an affiliate, we earn on qualifying purchases.

As an affiliate, we earn on qualifying purchases.

Key Questions

Why was the strncpy API removed from the Linux kernel?

The strncpy API was removed because it was a persistent source of bugs, had confusing semantics, and caused performance issues due to redundant zero-filling. Its removal aims to improve kernel safety and efficiency.

Developers are advised to use strscpy(), strscpy_pad(), strtomem_pad(), memcpy_and_pad(), or memcpy() depending on the specific copying requirements.

Will legacy code still use strncpy after this change?

It is unlikely, but some older or unmaintained code might still depend on strncpy. Transitioning to the new functions is encouraged for better safety and performance.

When did the removal of strncpy officially happen?

The removal was completed in Linux 7.2, which was released recently after the six-year development effort.

What are the benefits of removing strncpy from the kernel?

The benefits include reduced bugs related to string handling, improved security by avoiding buffer overflows, and better performance due to eliminating redundant zero-filling.

Source: Hacker News


HALLOWEEN

Halloween Picks

As an affiliate, we earn on qualifying purchases.

You May Also Like

Running local models on an M4 with 24GB memory

A detailed report on deploying and running local AI models on an Apple M4 MacBook Pro with 24GB memory, exploring capabilities, setup, and limitations.

Firewalls are not enough against AI attacks. We need a new security mindset around information exchange. https://lantero.se/blog/ai-agenter-i-verksamheten-riskabel-effektivitet… #CyberSecurity #AISäkerhet

Experts warn traditional firewalls are insufficient against AI-driven cyber threats, calling for a fundamental shift in cybersecurity strategies.

Wi‑Fi Coverage Planning: The Simple Home Map Method

Here’s a simple home map method to plan your Wi‑Fi coverage and improve signal strength—discover how to optimize your network effectively.

The Best AI Features To Look For In 4K Monitors In 2026

Discover the key AI features to look for in 4K monitors in 2026, including adaptive brightness, color calibration, and gaming enhancements, to optimize your display experience.