Patch "cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter()" has been added to the 6.11-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter()

to the 6.11-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     cachefiles-fix-incorrect-length-return-value-in-cach.patch
and it can be found in the queue-6.11 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 50fdd5362264a39e5ba84d35e6fdeb67bdad0099
Author: Zizhi Wo <wozizhi@xxxxxxxxxx>
Date:   Thu Nov 7 19:06:45 2024 +0800

    cachefiles: Fix incorrect length return value in cachefiles_ondemand_fd_write_iter()
    
    [ Upstream commit 10c35abd35aa62c9aac56898ae0c63b4d7d115e5 ]
    
    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@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20241107110649.3980193-2-wozizhi@xxxxxxxxxx
    Reviewed-by: David Howells <dhowells@xxxxxxxxxx>
    Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c
index 470c966583850..bdd321017f1c4 100644
--- a/fs/cachefiles/ondemand.c
+++ b/fs/cachefiles/ondemand.c
@@ -61,7 +61,7 @@ static ssize_t cachefiles_ondemand_fd_write_iter(struct kiocb *kiocb,
 	struct cachefiles_object *object = kiocb->ki_filp->private_data;
 	struct cachefiles_cache *cache = object->volume->cache;
 	struct file *file = object->file;
-	size_t len = iter->count;
+	size_t len = iter->count, aligned_len = len;
 	loff_t pos = kiocb->ki_pos;
 	const struct cred *saved_cred;
 	int ret;
@@ -70,7 +70,7 @@ static ssize_t cachefiles_ondemand_fd_write_iter(struct kiocb *kiocb,
 		return -ENOBUFS;
 
 	cachefiles_begin_secure(cache, &saved_cred);
-	ret = __cachefiles_prepare_write(object, file, &pos, &len, len, true);
+	ret = __cachefiles_prepare_write(object, file, &pos, &aligned_len, len, true);
 	cachefiles_end_secure(cache, saved_cred);
 	if (ret < 0)
 		return ret;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux