]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
f2fs: explicitly null-terminate the xattr list
authorEric Biggers <ebiggers@google.com>
Tue, 7 Nov 2023 04:44:34 +0000 (20:44 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Jan 2024 22:52:27 +0000 (14:52 -0800)
commit e26b6d39270f5eab0087453d9b544189a38c8564 upstream.

When setting an xattr, explicitly null-terminate the xattr list.  This
eliminates the fragile assumption that the unused xattr space is always
zeroed.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/f2fs/xattr.c

index 797ac505a075ad075237af6cca20b0c1707288f2..1a18936bc583bd5bfa843b6d6f13ff6be5c348e1 100644 (file)
@@ -745,6 +745,12 @@ static int __f2fs_setxattr(struct inode *inode, int index,
                memcpy(pval, value, size);
                last->e_value_size = cpu_to_le16(size);
                new_hsize += newsize;
+               /*
+                * Explicitly add the null terminator.  The unused xattr space
+                * is supposed to always be zeroed, which would make this
+                * unnecessary, but don't depend on that.
+                */
+               *(u32 *)((u8 *)last + newsize) = 0;
        }
 
        error = write_all_xattrs(inode, new_hsize, base_addr, ipage);