Skip to content

Commit 3d1d4aa

Browse files
committed
cachefiles: Fix signed/unsigned mixup
In __cachefiles_prepare_write(), the start and pos variables were made unsigned 64-bit so that the casts in the checking could be got rid of - which should be fine since absolute file offsets can't be negative, except that an error code may be obtained from vfs_llseek(), which *would* be negative. This breaks the error check. Fix this for now by reverting pos and start to be signed and putting back the casts. Unfortunately, the error value checks cannot be replaced with IS_ERR_VALUE() as long might be 32-bits. Fixes: 7097c96 ("cachefiles: Fix __cachefiles_prepare_write()") Reported-by: Simon Horman <horms@kernel.org> Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202401071152.DbKqMQMu-lkp@intel.com/ Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Simon Horman <horms@kernel.org> Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> cc: Yiqun Leng <yqleng@linux.alibaba.com> cc: Jia Zhu <zhujia.zj@bytedance.com> cc: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org
1 parent 807c6d0 commit 3d1d4aa

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/cachefiles/io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
522522
bool no_space_allocated_yet)
523523
{
524524
struct cachefiles_cache *cache = object->volume->cache;
525-
unsigned long long start = *_start, pos;
525+
loff_t start = *_start, pos;
526526
size_t len = *_len;
527527
int ret;
528528

@@ -556,7 +556,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
556556
cachefiles_trace_seek_error);
557557
return pos;
558558
}
559-
if (pos >= start + *_len)
559+
if ((u64)pos >= (u64)start + *_len)
560560
goto check_space; /* Unallocated region */
561561

562562
/* We have a block that's at least partially filled - if we're low on
@@ -575,7 +575,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object,
575575
cachefiles_trace_seek_error);
576576
return pos;
577577
}
578-
if (pos >= start + *_len)
578+
if ((u64)pos >= (u64)start + *_len)
579579
return 0; /* Fully allocated */
580580

581581
/* Partially allocated, but insufficient space: cull. */

0 commit comments

Comments
 (0)