]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter()
authorZizhi Wo <wozizhi@huawei.com>
Thu, 7 Nov 2024 11:06:45 +0000 (19:06 +0800)
committerChristian Brauner <brauner@kernel.org>
Mon, 11 Nov 2024 13:39:37 +0000 (14:39 +0100)
commit10c35abd35aa62c9aac56898ae0c63b4d7d115e5
tree089f6195fd3fc2aba0ab1073d8cef3e266e413be
parent9b8e8091c86391333d217e837883a729b9cebac7
cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter()

cachefiles_ondemand_fd_write_iter() function first aligns "pos" and "len"
to block boundaries. When calling __cachefiles_write(), the aligned "pos"
is passed in, but "len" is the original unaligned value(iter->count).
Additionally, the returned length of the write operation is the modified
"len" aligned by block size, which is unreasonable.

The alignment of "pos" and "len" is intended only to check whether the
cache has enough space. But the modified len should not be used as the
return value of cachefiles_ondemand_fd_write_iter() because the length we
passed to __cachefiles_write() is the previous "len". Doing so would result
in a mismatch in the data written on-demand. For example, if the length of
the user state passed in is not aligned to the block size (the preread
scene/DIO writes only need 512 alignment/Fault injection), the length of
the write will differ from the actual length of the return.

To solve this issue, since the __cachefiles_prepare_write() modifies the
size of "len", we pass "aligned_len" to __cachefiles_prepare_write() to
calculate the free blocks and use the original "len" as the return value of
cachefiles_ondemand_fd_write_iter().

Fixes: c8383054506c ("cachefiles: notify the user daemon when looking up cookie")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Link: https://lore.kernel.org/r/20241107110649.3980193-2-wozizhi@huawei.com
Reviewed-by: David Howells <dhowells@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/cachefiles/ondemand.c