* [PATCH] checkpatch: Check for strcpy and strncpy too
@ 2023-05-17 20:13 Kees Cook
2023-05-17 20:36 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2023-05-17 20:13 UTC (permalink / raw)
To: Andy Whitcroft
Cc: Kees Cook, Joe Perches, Dwaipayan Ray, Lukas Bulwahn,
linux-kernel, linux-hardening
Warn about strcpy(), strncpy(), and strlcpy(). Suggest strscpy() and
include pointers to the open KSPP issues for each, which has further
details and replacement procedures.
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Joe Perches <joe@perches.com>
Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
scripts/checkpatch.pl | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b30114d637c4..a90e0ede53ad 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6997,10 +6997,22 @@ sub process {
# }
# }
+# strcpy uses that should likely be strscpy
+ if ($line =~ /\bstrcpy\s*\(/) {
+ WARN("STRCPY",
+ "Use of strcpy has been replaced with strscpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
+ }
+
# strlcpy uses that should likely be strscpy
if ($line =~ /\bstrlcpy\s*\(/) {
WARN("STRLCPY",
- "Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
+ "Use of strlcpy has been replaced with strscpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
+ }
+
+# strncpy uses that should likely be strscpy or strscpy_pad
+ if ($line =~ /\bstrncpy\s*\(/) {
+ WARN("STRNCPY",
+ "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
}
# typecasts on min/max could be min_t/max_t
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] checkpatch: Check for strcpy and strncpy too
2023-05-17 20:13 [PATCH] checkpatch: Check for strcpy and strncpy too Kees Cook
@ 2023-05-17 20:36 ` Joe Perches
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2023-05-17 20:36 UTC (permalink / raw)
To: Kees Cook, Andy Whitcroft
Cc: Dwaipayan Ray, Lukas Bulwahn, linux-kernel, linux-hardening
On Wed, 2023-05-17 at 13:13 -0700, Kees Cook wrote:
> Warn about strcpy(), strncpy(), and strlcpy(). Suggest strscpy() and
> include pointers to the open KSPP issues for each, which has further
> details and replacement procedures.
>
> Cc: Andy Whitcroft <apw@canonical.com>
> Cc: Joe Perches <joe@perches.com>
> Cc: Dwaipayan Ray <dwaipayanray1@gmail.com>
> Cc: Lukas Bulwahn <lukas.bulwahn@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> scripts/checkpatch.pl | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b30114d637c4..a90e0ede53ad 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6997,10 +6997,22 @@ sub process {
> # }
> # }
>
> +# strcpy uses that should likely be strscpy
> + if ($line =~ /\bstrcpy\s*\(/) {
> + WARN("STRCPY",
> + "Use of strcpy has been replaced with strscpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
I would prefer something like
"Prefer strscpy over strcpy etc..."
as there are just too many existing uses of strcpy that can not
easily be converted.
$ git grep -w strcpy -- "*.[chS]" | wc -l
2015
> + }
> +
> # strlcpy uses that should likely be strscpy
> if ($line =~ /\bstrlcpy\s*\(/) {
> WARN("STRLCPY",
> - "Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
> + "Use of strlcpy has been replaced with strscpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
> + }
> +
> +# strncpy uses that should likely be strscpy or strscpy_pad
> + if ($line =~ /\bstrncpy\s*\(/) {
> + WARN("STRNCPY",
> + "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
> }
>
> # typecasts on min/max could be min_t/max_t
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-17 20:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-17 20:13 [PATCH] checkpatch: Check for strcpy and strncpy too Kees Cook
2023-05-17 20:36 ` Joe Perches
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox