deepin-kernel/fs/cachefiles
Zizhi Wo 60c0eeab69 cachefiles: Fix the incorrect return value in __cachefiles_write()
[ Upstream commit 6b89819b06d8d339da414f06ef3242f79508be5e ]

In __cachefiles_write(), if the return value of the write operation > 0, it
is set to 0. This makes it impossible to distinguish scenarios where a
partial write has occurred, and will affect the outer calling functions:

 1) cachefiles_write_complete() will call "term_func" such as
netfs_write_subrequest_terminated(). When "ret" in __cachefiles_write()
is used as the "transferred_or_error" of this function, it can not
distinguish the amount of data written, makes the WARN meaningless.

 2) cachefiles_ondemand_fd_write_iter() can only assume all writes were
successful by default when "ret" is 0, and unconditionally return the full
length specified by user space.

Fix it by modifying "ret" to reflect the actual number of bytes written.
Furthermore, returning a value greater than 0 from __cachefiles_write()
does not affect other call paths, such as cachefiles_issue_write() and
fscache_write().

Fixes: 047487c947 ("cachefiles: Implement the I/O routines")
Signed-off-by: Zizhi Wo <wozizhi@huawei.com>
Link: https://lore.kernel.org/20250703024418.2809353-1-wozizhi@huaweicloud.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit bc016b7842f65cc7fab76fb6326f5109b2e1bb38)
2025-07-28 15:19:05 +08:00
..
Kconfig cachefiles: notify the user daemon when looking up cookie 2022-05-18 00:11:17 +08:00
Makefile cachefiles: notify the user daemon when looking up cookie 2022-05-18 00:11:17 +08:00
cache.c cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() 2024-12-10 20:39:33 +08:00
daemon.c cachefiles: Parse the "secctx" immediately 2025-01-24 10:13:49 +08:00
error_inject.c fs/cachefiles: simplify one-level sysctl registration for cachefiles_sysctls 2023-04-13 11:49:35 -07:00
interface.c cachefiles: Fix NULL pointer dereference in object->file 2025-02-18 11:53:09 +08:00
internal.h cachefiles: Parse the "secctx" immediately 2025-01-24 10:13:49 +08:00
io.c cachefiles: Fix the incorrect return value in __cachefiles_write() 2025-07-28 15:19:05 +08:00
key.c cachefiles: Implement key to filename encoding 2022-01-07 13:42:16 +00:00
main.c cachefiles: Implement object lifecycle funcs 2022-01-07 13:42:08 +00:00
namei.c cachefiles: fix dentry leak in cachefiles_open_file() 2024-12-10 20:42:33 +08:00
ondemand.c cachefiles: Fix the incorrect return value in __cachefiles_write() 2025-07-28 15:19:05 +08:00
security.c cachefiles: Parse the "secctx" immediately 2025-01-24 10:13:49 +08:00
volume.c cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() 2024-12-10 20:39:33 +08:00
xattr.c cachefiles: Fix non-taking of sb_writers around set/removexattr 2024-12-10 20:41:45 +08:00