]> git.hungrycats.org Git - linux/commit
btrfs: props: validate compression property values strictly 6.18/topics/compress-fixes
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 19 Jul 2026 18:33:53 +0000 (14:33 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Wed, 16 Sep 2026 21:39:58 +0000 (17:39 -0400)
commit9c9c3acd96e0c4c00924e7e2b6911686ee34b303
treec3d37522d2ba7040f83ce7a894868d7ddadd18c8
parent0b207d2b9a8a51b4a67ff5f451e1e46fb59bf1a2
btrfs: props: validate compression property values strictly

The btrfs.compression property validator matches only the algorithm
name prefix, so values like "zstdgarbage" or "zstd:banana" are accepted
and stored verbatim.  Now that ":level" suffixes are meaningful,
validate new values strictly:  accept exactly an algorithm name,
optionally followed by a ":level" suffix that btrfs_compress_str2level()
can parse, mirroring the mount option validation from commit
b98b20830057 ("btrfs: reject invalid compression level").  Out of range
levels are clamped, also matching the mount options.  "no" and "none"
are accepted as before.  Embedded NUL bytes are rejected before parsing
the length-delimited xattr value:  otherwise the temporary
NUL-terminated suffix buffer would let a value such as "zstd:3" followed
by a NUL and junk pass validation and be stored verbatim.

Values stored by old kernels are not affected:  property loading goes
through the apply hook, which remains permissive, so existing inodes
with sloppy stored values keep working; only new setxattr calls see the
stricter checks.

This is a user-visible behavior change:  applications that set malformed
property values, which were previously accepted and ignored, will now
receive EINVAL.  It is split into its own commit so that it can be
accepted or rejected independently of per-inode compression level
support.

Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Assisted-by: Claude:claude-fable-5
Assisted-by: Codex:gpt-5
fs/btrfs/props.c