From 84ab1889e1f32cf7423a3e893e1bcddec44653eb Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Tue, 9 Jan 2024 10:02:00 -0800 Subject: [PATCH] UPSTREAM: ANDROID: fuse-bpf: Fix the issue of abnormal lseek system calls fuse_lseek_backing was returning the offset as an int, which would then be treated as an ERR if in the range 4G-4096 and 4G. Although the call would appear to work correctly, the file position would be incorrect according to a subsequent fseek with SEEK_CUR. Based on a change by chenyuwen who found and fixed this issue. Bug: 319219307 Change-Id: I3aef5fb22751a72ce2bd7674ee081956a89fc752 Signed-off-by: chenyuwen Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index 859114b13508..e9533afd5961 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -454,23 +454,26 @@ int fuse_lseek_backing(struct fuse_bpf_args *fa, struct file *file, loff_t offse struct file *backing_file = fuse_file->backing_file; loff_t ret; - /* TODO: Handle changing of the file handle */ if (offset == 0) { if (whence == SEEK_CUR) { flo->offset = file->f_pos; - return flo->offset; + return 0; } if (whence == SEEK_SET) { flo->offset = vfs_setpos(file, 0, 0); - return flo->offset; + return 0; } } inode_lock(file->f_inode); backing_file->f_pos = file->f_pos; ret = vfs_llseek(backing_file, fli->offset, fli->whence); - flo->offset = ret; + + if (!IS_ERR(ERR_PTR(ret))) { + flo->offset = ret; + ret = 0; + } inode_unlock(file->f_inode); return ret; }