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