]> git.hungrycats.org Git - linux/commit
btrfs: props: validate compression property values strictly misc-next/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>
Fri, 18 Sep 2026 21:36:15 +0000 (17:36 -0400)
commitea02727f2f7d0c497cc0c7350d983ec7e0a74a7c
treeabeb8cefc8a5345658b9d3e1d8f1889ad6a189ce
parent0a32bf51c5590554181172cd2bf6dc4b884fd16b
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