Skip to content

Commit

Permalink
anolis: erofs: fix unexpected endless loop when read < 0
Browse files Browse the repository at this point in the history
ANBZ: torvalds#183

read is ssize_t (signed type) and size is u64. If read < 0,
read < size will never be true.

Reported-by: Liu Bo <bo.liu@linux.alibaba.com>
Reviewed-by: Jeffle Xu <jefflexu@linux.alibaba.com>
Reviewed-by: Liu Bo <bo.liu@linux.alibaba.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
  • Loading branch information
hsiangkao authored and josephhz committed Dec 23, 2021
1 parent 013a1bd commit e6b83b5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/erofs/inode.c
Expand Up @@ -484,11 +484,11 @@ static ssize_t rafs_v6_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
inode->i_size, map.m_pa, delta, size);
read = rafs_v6_read_chunk(inode->i_sb, to, map.m_pa + delta,
size, map.m_deviceid);
if (read < size) {
if (read <= 0 || read < size) {
erofs_err(inode->i_sb,
"short read %ld pos %llu size %llu @ nid %llu",
read, pos, size, EROFS_I(inode)->nid);
return -EIO;
return read < 0 ? read : -EIO;
}
iocb->ki_pos += read;
bytes += read;
Expand Down

0 comments on commit e6b83b5

Please sign in to comment.