Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: "koraynilay" <koray.fra@gmail.com>
To: "Qu Wenruo" <wqu@suse.com>, "koraynilay" <koray.fra@gmail.com>,
	"Chris Mason" <clm@fb.com>, "David Sterba" <dsterba@suse.com>
Cc: "Zygo Blaxell" <ce3g8jdj@umail.furryterror.org>,
	<linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH v2 2/4] btrfs: also validate compression levels in btrfs_compress_is_valid_type()
Date: Sun, 09 Aug 2026 05:35:46 +0200	[thread overview]
Message-ID: <DKK3JZ4VEBDZ.3TZKOIV87R4ZG@gmail.com> (raw)
In-Reply-To: <f190abba-cbe0-4ffa-a815-00286b5f0c88@suse.com>

[-- Attachment #1: Type: text/plain, Size: 1382 bytes --]

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 [...]

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-08-09  3:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-09  1:50 [PATCH v2 0/4] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-09  1:50 ` [PATCH v2 1/4] btrfs: export btrfs_match_compress_type(), move it to compression.h koraynilay
2026-08-09  1:50 ` [PATCH v2 2/4] btrfs: also validate compression levels in btrfs_compress_is_valid_type() koraynilay
2026-08-09  2:53   ` Qu Wenruo
2026-08-09  3:35     ` koraynilay [this message]
2026-08-09  4:07       ` Qu Wenruo
2026-08-09  1:50 ` [PATCH v2 3/4] btrfs: add per-inode compression levels in xattrs koraynilay
2026-08-09  2:55   ` Qu Wenruo
2026-08-09  3:50     ` koraynilay
2026-08-09  4:05       ` Qu Wenruo
2026-08-11  2:55     ` koraynilay
2026-08-11  3:21       ` Qu Wenruo
2026-08-11  3:40         ` koraynilay
2026-08-11 12:47         ` koraynilay
2026-08-09  1:50 ` [PATCH v2 4/4] btrfs: support inheritance for per-inode compression levels koraynilay
2026-08-09  3:03   ` Qu Wenruo

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=DKK3JZ4VEBDZ.3TZKOIV87R4ZG@gmail.com \
    --to=koray.fra@gmail.com \
    --cc=ce3g8jdj@umail.furryterror.org \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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