You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove all strcpy() uses in favor of strscpy() #88
A lot of kernel code is still using strcpy(). While the CONFIG_FORTIFY_SOURCE wrapper macros tend to make its use mostly safe, it would be nice to eliminate the function from the kernel entirely.
I'm interested in having a go at this, but I was just wondering what you think would be the cleanest way to deal with strcpy(str, "constant string"), where we know that sizeof(str) > sizeof("constant string") will always hold?
I'm interested in having a go at this, but I was just wondering what you think would be the cleanest way to deal with strcpy(str, "constant string"), where we know that sizeof(str) > sizeof("constant string") will always hold?
Normally this shouldn't be a problem. Prior to v5.11, under CONFIG_FORTIFY_SOURCE=y a compile-time error will be generated. For example:
char dst[8];
...
strcpy(dst, "Crash point unregistered\n"); /* line 21 noted below */
produces:
...
from drivers/misc/lkdtm/core.c:21:
In function 'memcpy',
inlined from 'lkdtm_module_exit' at ./include/linux/fortify-string.h:281:2:
./include/linux/fortify-string.h:185:4: error: call to '__write_overflow' declared with attribute error: detected write beyond size of object passed as 1st parameter
185 | __write_overflow();
| ^~~~~~~~~~~~~~~~~~
v5.11 and later seem to have a bug here when strscpy() coverage was added. The runtime check is correct, but the compile time error has gone missing. This needs fixing.
Part of an October 2026 triage of every open KSPP issue. The research was AI-assisted (Claude Opus 5.5 investigated and searched the mailing lists; Claude Haiku 4.5 summarized), and I reviewed this summary before posting. Kernel state is as of mainline d24e8ac715de (v7.3-rc5+) and next-20261001.
Status as of 2026-10-01: Still valid and actively progressing; strcpy() sites dropped from 1948 (v5.9) to 568 in mainline and 555 in linux-next.
The issue asks to remove all strcpy() calls in the kernel (outside tools/ and scripts/) by replacing them with strscpy() or memcpy(). This treewide refactor is healthy, moving fast, and still fits the "good first issue" label. Mainline commits over the past year average 30 to 40 conversions per release. The remaining ~555 call sites concentrate in drivers/net (117: tg3.c with 21 alone, qed_debug.c 11, mwifiex), drivers/scsi (88: myrb, qla2xxx, bfa, esas2r, csiostor), drivers/video/fbdev (53), drivers/acpi/acpica (16, needs upstream ACPICA sync), drivers/gpu (17), drivers/mtd (15), and init/main.c (10). checkpatch already warns on new uses.
Evidence
d722f1e06fbc ("drivers/iio: Remove all strcpy() uses", v5.16-rc1): early bulk conversion showing the pattern works.
0bdbce25855f ("ALSA: hda: Use safer strscpy() instead of strcpy()", v6.17-rc1): part of the 600-site ALSA sweep that drove the v6.17 drop.
aa264d9511aa ("nios2: Replace strcpy() with strscpy() and simplify setup_cpuinfo()", v6.16-rc1): recent mainline patch exemplifying the pattern.
Call site count: v5.9 (1948) to v6.16 (1470) to v6.17 (852) to mainline d24e8ac (568), with 309 commits since v6.16 by Takashi Iwai, Thorsten Blum, David Laight and others.
Mailing list
No blocking series. About 20 patches since 2026-07 are mostly merged in v7.3 or queued in linux-next. Key caveat: David Laight and Jani Nikula have NAKed mechanical conversions of strcpy(fixed_array, "literal") to strscpy(), because FORTIFY makes the strcpy form fail at compile time on overflow while strscpy silently truncates. Newcomers should target call sites where destination size or source is not compile-time known, or use the 2-argument strscpy() or memcpy() patterns.
Suggested next step
Refresh the issue description with current call-site counts by subsystem (especially drivers/net, scsi, fbdev, acpica) and add the list of high-count files (tg3.c, qed_debug.c, myrb.c, qla2xxx, bfa, esas2r, csiostor) to guide new contributors. Point them toward sites where the size is not known at compile time or where return value checks are needed, to avoid the FORTIFY gotcha. For drivers/acpi/acpica, route patches to upstream ACPICA instead. Keep the label "good first issue" as the refactor is still one driver or subsystem per patch.
Activity
[-]Deprecate strcpy() in favor of strscpy()[/-][+]Remove all strcpy() uses in favor of strscpy()[/+]alexdewar commentedon Aug 24, 2020
I'm interested in having a go at this, but I was just wondering what you think would be the cleanest way to deal with
strcpy(str, "constant string"), where we know thatsizeof(str) > sizeof("constant string")will always hold?kees commentedon Aug 1, 2021
Normally this shouldn't be a problem. Prior to v5.11, under CONFIG_FORTIFY_SOURCE=y a compile-time error will be generated. For example:
produces:
v5.11 and later seem to have a bug here when strscpy() coverage was added. The runtime check is correct, but the compile time error has gone missing. This needs fixing.
drivers/iio: Remove all strcpy() uses in favor of strscpy()
drivers/iio: Remove all strcpy() uses
drivers/iio: Remove all strcpy() uses
drivers/iio: Remove all strcpy() uses
EDAC/mc: Prefer strscpy or scnprintf over strcpy
EDAC/mc: Prefer strscpy or scnprintf over strcpy
EDAC/mc: Replace strcpy(), sprintf() and snprintf() with strscpy() or…
drivers/iio: Remove all strcpy() uses
drivers/iio: Remove all strcpy() uses
drivers/iio: Remove all strcpy() uses
257 remaining items
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
ALSA: ctxfi: Replace deprecated strcpy() with strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
ALSA: mips/sgio2audio: Replace deprecated strcpy() with strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
ALSA: mips/sgio2audio: Replace deprecated strcpy() with strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
alpha: replace sprintf()/strcpy() with scnprintf()/strscpy()
ASoC: Intel: Replace deprecated strcpy() with strscpy()
ACPI / sysfs: Replace deprecated strcpy() with strscpy()
JustinStitt commentedon Oct 19, 2026
Note
Part of an October 2026 triage of every open KSPP issue. The research was AI-assisted (Claude Opus 5.5 investigated and searched the mailing lists; Claude Haiku 4.5 summarized), and I reviewed this summary before posting. Kernel state is as of mainline
d24e8ac715de(v7.3-rc5+) andnext-20261001.Status as of 2026-10-01: Still valid and actively progressing; strcpy() sites dropped from 1948 (v5.9) to 568 in mainline and 555 in linux-next.
The issue asks to remove all strcpy() calls in the kernel (outside tools/ and scripts/) by replacing them with strscpy() or memcpy(). This treewide refactor is healthy, moving fast, and still fits the "good first issue" label. Mainline commits over the past year average 30 to 40 conversions per release. The remaining ~555 call sites concentrate in drivers/net (117: tg3.c with 21 alone, qed_debug.c 11, mwifiex), drivers/scsi (88: myrb, qla2xxx, bfa, esas2r, csiostor), drivers/video/fbdev (53), drivers/acpi/acpica (16, needs upstream ACPICA sync), drivers/gpu (17), drivers/mtd (15), and init/main.c (10). checkpatch already warns on new uses.
Evidence
Mailing list
strcpy(fixed_array, "literal")tostrscpy(), because FORTIFY makes the strcpy form fail at compile time on overflow while strscpy silently truncates. Newcomers should target call sites where destination size or source is not compile-time known, or use the 2-argument strscpy() or memcpy() patterns.Suggested next step
Full investigation: https://github.com/KSPP/bug-scrub-archaeology/tree/master/issues/issue-88