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

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.

Embedded Linux Development: Build, Customize, and Optimize Linux Kernel, Device Drivers, Buildroot, Yocto, and Real-Time Systems for ARM and x86 (Morden developer toolkit)

Embedded Linux Development: Build, Customize, and Optimize Linux Kernel, Device Drivers, Buildroot, Yocto, and Real-Time Systems for ARM and x86 (Morden developer 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.

Tux the Linux Penguin Embroidered Iron-on Patch

Tux the Linux Penguin Embroidered Iron-on Patch

  • Size: 3.5 x 3 inches
  • Attachment Method: Iron-on or sew for security
  • Design Quality: Embroidery with laser-cut edges

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.

6 Stages of Debugging Programmer Computer Funny Software T-Shirt

6 Stages of Debugging Programmer Computer Funny Software T-Shirt

  • Lightweight and comfortable fit: Classic fit for all-day wear
  • Durable construction: Double-needle sleeve and hem

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


You May Also Like

How to Back Up Your Photos So You Never Lose Them Again

Discover essential steps to back up your photos effectively and ensure your memories are always protected—don’t miss out on these crucial tips.

AMD reaches 46% of server x86 CPU revenue — Intel still controls 70% of the consumer PC market share

In Q1 2026, AMD’s server CPU revenue share hit 46.2%, while Intel maintains 70% of the unit market, highlighting shifting dynamics in the x86 CPU sector.

The Hidden Tech Behind ‘SINGULARITY’: Particle Geometry Mapping In AI

New tech behind ‘SINGULARITY’ uses particle geometry mapping to create immersive AI-driven spaces, blending art and advanced algorithms.

Show HN: Shirei, Cross-platform GUI Framework In Native Go

Shirei is a new native Go-based GUI framework announced on Show HN, enabling cross-platform app development without external dependencies.