Re: [PATCH v2 2/4] btrfs: also validate compression levels in btrfs_compress_is_valid_type()

"koraynilay" <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <[email protected]>
On Sun Aug 9, 2026 at 4:53 AM CEST, Qu Wenruo wrote:
> Please make sure every commit compiles, this will easily break bisection.
>
> You're changing a function prototype and implementation without 
> modifying any callers, this fails compiling.

Right, I'm sorry, I didn't notice I changed the caller in 3/4 as that
call point also had other changes.

> Furthermore, I do not think it's a good idea to just rely on the strlen().
>
> E.g. if a crafted image removing the last terminating NUL, relying 
> strlen() can easily go beyond the expected string.
>
> I think the change to remove @len is going to reduce the robustness of 
> the original code.

That was what I feared too, the problem is that
btrfs_compress_str2level() uses kstrtoint(), which requires the string
to be null-terminated[1], so the len paramenter would only be used by
if (len < comp_len) and that reduces the robustness even more IMO, since
a developer could think it's safe because of len, while it actually
isn't because of kstrtoint().
The only fix I can think of would be to use
_parse_integer_limit(..., len) directly or write a wrapper.
Or just document that it needs a null-terminated string.

Thanks.

Best,
koraynilay

[1]: 
from lib/kstrtox.c:251:
 * kstrtoint - convert a string to an int
 * @s: The start of the string. The string must be null-terminated [...]
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCanf1lAAKCRDmj22qf5IG
XKo7AQDn6jOuQPBzJU33d9krYB4nZp8Mrru+arp/66lCE5o59AEAyxUHSQ3pGTkS
Tzan7avav5nqvb6luvYd9rXUX/5HdQ0=
=a4fP
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.