mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Azeem Shaikh <azeemshaikh38@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	security@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: kernfs: Prefer strscpy over strlcpy calls
Date: Tue, 9 May 2023 12:36:37 -1000	[thread overview]
Message-ID: <ZFrK9Vw9sbE6NSLi@slm.duckdns.org> (raw)
In-Reply-To: <20230509223036.3007500-1-azeemshaikh38@gmail.com>

On Tue, May 09, 2023 at 10:30:36PM +0000, Azeem Shaikh wrote:
> strlcpy() reads the entire source buffer first.
> This read may exceed the destination size limit.
> This is both inefficient and can lead to linear read
> overflows if a source string is not NUL-terminated.
> Since strscpy() returns -E2BIG on truncate, we rely on
> strlen(src) to imitate strlcpy behavior.

The security angle is too hand wavy. If there are bugs in source string
handling, please identify and fix them. The performance claim is dubious too
given that in the vast majority of cases, we'd be copying the whole string.

I'm not necessarily against conversion if we're unifying the code base to
always use strscpy but the currently provided justifications don't seem
strong. I mean, if anything, we know for sure that code churns like this
have non-trivial chance of introducing new bugs.

Thanks.

-- 
tejun

  reply	other threads:[~2023-05-09 22:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 22:30 Azeem Shaikh
2023-05-09 22:36 ` Tejun Heo [this message]
     [not found]   ` <CADmuW3VAP3-oZSK5Hix5sk62+bbwiCoC3MFoFHmBd-OwXS-pHA@mail.gmail.com>
2023-05-10  0:43     ` Tejun Heo
2023-05-10  5:42 ` Linus Torvalds
2023-05-10 20:48   ` Azeem Shaikh

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=ZFrK9Vw9sbE6NSLi@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=azeemshaikh38@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=security@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

all inboxes | Powered by JetHome®