checkpatch: Check for strcpy and strncpy too
authorKees Cook <keescook@chromium.org>
Wed, 17 May 2023 20:13:52 +0000 (13:13 -0700)
committerKees Cook <keescook@chromium.org>
Tue, 30 May 2023 23:42:01 +0000 (16:42 -0700)
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>
Link: https://lore.kernel.org/r/20230517201349.never.582-kees@kernel.org
scripts/checkpatch.pl

index b30114d637c40fed8bb4e2db74af55bc71b34acd..30b0b4fdb3bf2d87b838097884af2933101655e7 100755 (executable)
@@ -6997,10 +6997,22 @@ sub process {
 #                      }
 #              }
 
+# strcpy uses that should likely be strscpy
+               if ($line =~ /\bstrcpy\s*\(/) {
+                       WARN("STRCPY",
+                            "Prefer strscpy over strcpy - 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);
+                            "Prefer strscpy over strlcpy - 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