Re: kernfs: Prefer strscpy over strlcpy calls

From: Tejun Heo
Date: Tue May 09 2023 - 18:36:46 EST


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