From: Nitin Gote <nitin.r.gote@intel.com>
To: akpm@linux-foundation.org
Cc: corbet@lwn.net, apw@canonical.com, joe@perches.com,
keescook@chromium.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org,
kernel-hardening@lists.openwall.com,
Nitin Gote <nitin.r.gote@intel.com>
Subject: [PATCH] checkpatch: Added warnings in favor of strscpy().
Date: Thu, 4 Jul 2019 11:24:43 +0530 [thread overview]
Message-ID: <1562219683-15474-1-git-send-email-nitin.r.gote@intel.com> (raw)
Added warnings in checkpatch.pl script to :
1. Deprecate strcpy() in favor of strscpy().
2. Deprecate strlcpy() in favor of strscpy().
3. Deprecate strncpy() in favor of strscpy() or strscpy_pad().
Updated strncpy() section in Documentation/process/deprecated.rst
to cover strscpy_pad() case.
Signed-off-by: Nitin Gote <nitin.r.gote@intel.com>
---
This patch is already reviewed by mailing list
kernel-hardening@lists.openwall.com. Refer below link
<https://www.openwall.com/lists/kernel-hardening/2019/07/03/4>
Acked-by: Kees Cook <keescook@chromium.org>
Documentation/process/deprecated.rst | 6 +++---
scripts/checkpatch.pl | 5 +++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/Documentation/process/deprecated.rst b/Documentation/process/deprecated.rst
index 49e0f64..f564de3 100644
--- a/Documentation/process/deprecated.rst
+++ b/Documentation/process/deprecated.rst
@@ -93,9 +93,9 @@ will be NUL terminated. This can lead to various linear read overflows
and other misbehavior due to the missing termination. It also NUL-pads the
destination buffer if the source contents are shorter than the destination
buffer size, which may be a needless performance penalty for callers using
-only NUL-terminated strings. The safe replacement is :c:func:`strscpy`.
-(Users of :c:func:`strscpy` still needing NUL-padding will need an
-explicit :c:func:`memset` added.)
+only NUL-terminated strings. In this case, the safe replacement is
+:c:func:`strscpy`. If, however, the destination buffer still needs
+NUL-padding, the safe replacement is :c:func:`strscpy_pad`.
If a caller is using non-NUL-terminated strings, :c:func:`strncpy()` can
still be used, but destinations should be marked with the `__nonstring
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 342c7c7..3d80967 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -595,6 +595,11 @@ our %deprecated_apis = (
"rcu_barrier_sched" => "rcu_barrier",
"get_state_synchronize_sched" => "get_state_synchronize_rcu",
"cond_synchronize_sched" => "cond_synchronize_rcu",
+ "strcpy" => "strscpy",
+ "strlcpy" => "strscpy",
+ "strncpy" => "strscpy, strscpy_pad or for
+ non-NUL-terminated strings, strncpy() can still be used, but
+ destinations should be marked with the __nonstring",
);
#Create a search pattern for all these strings to speed up a loop below
--
2.7.4
next reply other threads:[~2019-07-04 5:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-04 5:54 Nitin Gote [this message]
2019-07-04 20:46 ` [PATCH] checkpatch: Added warnings in favor of strscpy() Joe Perches
2019-07-05 0:15 ` [RFC PATCH] string.h: Add stracpy/stracpy_pad (was: Re: [PATCH] checkpatch: Added warnings in favor of strscpy().) Joe Perches
2019-07-22 17:33 ` Kees Cook
2019-07-22 17:43 ` Joe Perches
2019-07-22 17:58 ` Joe Perches
2019-07-22 18:21 ` Kees Cook
2019-07-22 18:27 ` Matthew Wilcox
2019-07-22 18:35 ` Joe Perches
[not found] <1561722948-28289-1-git-send-email-nitin.r.gote@intel.com>
[not found] ` <20190629181537.7d524f7d@sk2.org>
[not found] ` <201907021024.D1C8E7B2D@keescook>
[not found] ` <20190706144204.15652de7@heffalump.sk2.org>
2019-07-22 17:50 ` [PATCH] checkpatch: Added warnings in favor of strscpy() Kees Cook
2019-07-22 17:59 ` Joe Perches
2019-07-22 21:01 ` Stephen Kitt
2019-07-22 21:50 ` Joe Perches
2019-07-22 21:57 ` Jonathan Corbet
2019-07-22 22:24 ` Joe Perches
2019-07-22 22:28 ` Jonathan Corbet
2019-07-22 22:35 ` Joe Perches
2019-07-24 11:41 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1562219683-15474-1-git-send-email-nitin.r.gote@intel.com \
--to=nitin.r.gote@intel.com \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=corbet@lwn.net \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).