* [PATCH] btrfs: props: validate property values loaded from disk
@ 2026-11-12 22:33 Qu Wenruo
2026-11-17 6:19 ` Johannes Thumshirn
0 siblings, 1 reply; 2+ messages in thread
From: Qu Wenruo @ 2026-11-12 22:33 UTC (permalink / raw)
To: linux-btrfs; +Cc: Sashiko
Sashiko reported an out-of-bounds read during prop_compression_apply().
It only checks the length for "no" and "none", but not for "lzo", "zlib"
and "zstd". A crafted or corrupted image with a short value such as "lz"
makes strncmp() read past the end of the buffer.
Normally a prop is validated before applying, but that only applies to
set and inherit paths, not the loading-from-disk path.
Hardening the behavior by calling handler->validate() for non-empty values
before applying them, the same as the set and inherit paths do. Invalid
values are skipped with a warning.
This may cause a behavior change: validate also rejects compression on
inodes that cannot be compressed (NODATACOW or NODATASUM). Such an inode
with an existing compression xattr, e.g. one set before "chattr +C" on
an empty file, used to get BTRFS_INODE_COMPRESS applied on load. Now the
property is skipped with a warning.
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://sashiko.dev/#/bug/linux-c5d0a07b-d18d-495f-96b7-9dadef420b95
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/props.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/fs/btrfs/props.c b/fs/btrfs/props.c
index 7cc82366a1df..271f169aa5b0 100644
--- a/fs/btrfs/props.c
+++ b/fs/btrfs/props.c
@@ -273,6 +273,21 @@ static void inode_prop_iterator(void *ctx,
struct btrfs_root *root = BTRFS_I(inode)->root;
int ret;
+ /*
+ * The value comes from disk and is not trustworthy, nor NUL terminated.
+ * An empty value is valid and just resets the property to defaults.
+ */
+ if (len > 0) {
+ ret = handler->validate(BTRFS_I(inode), value, len);
+ if (unlikely(ret)) {
+ btrfs_warn(root->fs_info,
+ "invalid prop %s for ino %llu (root %llu): %d",
+ handler->xattr_name, btrfs_ino(BTRFS_I(inode)),
+ btrfs_root_id(root), ret);
+ return;
+ }
+ }
+
ret = handler->apply(BTRFS_I(inode), value, len);
if (unlikely(ret))
btrfs_warn(root->fs_info,
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs: props: validate property values loaded from disk
2026-11-12 22:33 [PATCH] btrfs: props: validate property values loaded from disk Qu Wenruo
@ 2026-11-17 6:19 ` Johannes Thumshirn
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Thumshirn @ 2026-11-17 6:19 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs, Sashiko
On Fri, Nov 13, 2026 at 09:03:10AM +1030, Qu Wenruo wrote:
> This may cause a behavior change: validate also rejects compression on
> inodes that cannot be compressed (NODATACOW or NODATASUM). Such an inode
> with an existing compression xattr, e.g. one set before "chattr +C" on
> an empty file, used to get BTRFS_INODE_COMPRESS applied on load. Now the
> property is skipped with a warning.
Which I think is the correct thing to do either way, so:
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-17 6:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 22:33 [PATCH] btrfs: props: validate property values loaded from disk Qu Wenruo
2026-11-17 6:19 ` Johannes Thumshirn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox