]> git.ipfire.org Git - thirdparty/kernel/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)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 17 Nov 2023 17:30:54 +0000 (09:30 -0800)
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>
fs/f2fs/xattr.c

index 47e88b4d4e7d01aaadc38c61922060e5a8884399..a8fc2cac68799508d9a2eb83bc568a64779f1369 100644 (file)
@@ -754,6 +754,12 @@ retry:
                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);