f2fs: explicitly null-terminate the xattr list

commit e26b6d3927 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>
This commit is contained in:
Eric Biggers 2023-11-06 20:44:34 -08:00 committed by Greg Kroah-Hartman
parent 9153fc9664
commit 12cf91e23b
1 changed files with 6 additions and 0 deletions

View File

@ -722,6 +722,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);