All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Nitin Gote <nitin.r.gote@intel.com>, akpm@linux-foundation.org
Cc: corbet@lwn.net, apw@canonical.com, keescook@chromium.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-hardening@lists.openwall.com
Subject: Re: [PATCH] checkpatch: Added warnings in favor of strscpy().
Date: Thu, 04 Jul 2019 13:46:25 -0700	[thread overview]
Message-ID: <f6a4c2b601bb59179cb2e3b8f4d836a1c11379a3.camel@perches.com> (raw)
In-Reply-To: <1562219683-15474-1-git-send-email-nitin.r.gote@intel.com>

On Thu, 2019-07-04 at 11:24 +0530, Nitin Gote wrote:
> 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>

OK, for whatever reason, this when into a spam folder.

> diff --git 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",
>  );

$ git grep -w strcpy | wc -l
2239
$ git grep -w strlcpy | wc -l
1760
$ git grep -w strncpy | wc -l
839

These functions are _really_ commonly used in the kernel.

This should probably be a different %deprecated_string_api
and these should probably not be emitted at WARN level
when using command line option -f/--file but at CHECK level
so that novice script users just don't send bad patches.

Also, perhaps there could be some macro for the relatively
commonly used

	strscpy(foo, bar, sizeof(foo))
and
	strlcpy(foo, bar, sizeof(foo))

so argument 1 doesn't have to be repeated in the sizeof()

Something like:

#define stracpy(to, from)					\
({								\
	size_t size = ARRAY_SIZE(to);				\
	BUILD_BUG_ON(!__same_type(typeof(*to), char));		\
								\
	strscpy(to, from, size);				\
})



  reply	other threads:[~2019-07-04 20:46 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-04  5:54 Nitin Gote
2019-07-04 20:46 ` Joe Perches [this message]
2019-07-04 20:46   ` 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-05  0:15     ` Joe Perches
2019-07-22 17:33     ` Kees Cook
2019-07-22 17:43       ` Joe Perches
2019-07-22 17:43         ` Joe Perches
2019-07-22 17:58         ` 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
2019-07-22 18:35               ` Joe Perches
  -- strict thread matches above, loose matches on Subject: below --
2019-06-28 11:55 [PATCH] checkpatch: Added warnings in favor of strscpy() Nitin Gote
2019-06-28 14:46 ` Kees Cook
2019-07-01  8:42   ` Gote, Nitin R
2019-07-02 17:31     ` Kees Cook
2019-06-29 16:15 ` Stephen Kitt
2019-07-02 17:25   ` Kees Cook
2019-07-06 12:42     ` Stephen Kitt
2019-07-07  7:40       ` Stephen Kitt
2019-07-22 17:50       ` Kees Cook
2019-07-22 17:59         ` Joe Perches
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:50               ` Joe Perches
2019-07-22 21:57               ` Jonathan Corbet
2019-07-22 22:24                 ` Joe Perches
2019-07-22 22:24                   ` Joe Perches
2019-07-22 22:28                   ` Jonathan Corbet
2019-07-22 22:35                     ` Joe Perches
2019-07-22 22:35                       ` Joe Perches
2019-07-24 11:41                     ` 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=f6a4c2b601bb59179cb2e3b8f4d836a1c11379a3.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=corbet@lwn.net \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nitin.r.gote@intel.com \
    --subject='Re: [PATCH] checkpatch: Added warnings in favor of strscpy().' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.