LKML Archive on
help / color / mirror / Atom feed
From: Borislav Petkov <>
To: Len Baker <>
Cc: Mauro Carvalho Chehab <>,
	Tony Luck <>,
	James Morse <>,
	Robert Richter <>, Joe Perches <>,
	David Laight <>,
	Kees Cook <>,,,
Subject: Re: [PATCH v4] EDAC/mc: Prefer strscpy over strcpy
Date: Tue, 24 Aug 2021 20:26:10 +0200	[thread overview]
Message-ID: <YSU5wp/ZpsXuDgmu@zn.tnic> (raw)
In-Reply-To: <20210824090338.GB7999@titan>

On Tue, Aug 24, 2021 at 12:28:07PM +0200, Len Baker wrote:
> This is a task of the KSPP [1] and the main reason is to clean up the
> proliferation of str*cpy functions in the kernel.

That I understood - you prominently explain where the patches stem from.

What I can't parse is that formulation "previous step". What previous
step do you mean?

> Yes, you are right. The same discussion happened in the v3 review [2] and
> I agree with the reasons that Robert Richter exposed. Using the strlen()
> implementation it is not necessary to check the return code of strcpy and
> we can assume a silent truncation.
> [2]

Ok, looking at the asm, gcc is actually smart enough not to call
strlen() twice on the same buffer.

But then there's this in the strscpy() kernel-doc comment:

"The destination buffer is always NUL terminated, unless it's

so looking at the code, we're merrily decrementing len but nothing's
checking whether len can become 0. Because if it does, strscpy() will

	if (count == 0 || WARN_ON_ONCE(count > INT_MAX))
		return -E2BIG;

so if p ends up pointing to something which is *not* '\0', strlen() will
go off into the weeds.

So I don't care if it doesn't look just as nice - it better be correct
in all cases first.



  reply	other threads:[~2021-08-24 18:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14  7:55 Len Baker
2021-08-23 17:30 ` Borislav Petkov
2021-08-24 10:28   ` Len Baker
2021-08-24 18:26     ` Borislav Petkov [this message]
2021-08-24 19:05       ` Joe Perches
2021-08-25  8:48       ` David Laight
2021-08-27 17:36       ` Len Baker
2021-08-27 17:54         ` Borislav Petkov
2021-08-27 19:08           ` Joe Perches
2021-08-29 16:14           ` Len Baker

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YSU5wp/ZpsXuDgmu@zn.tnic \ \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v4] EDAC/mc: Prefer strscpy over strcpy' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).