Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iomap: adjust read range correctly for non-block-aligned positions

iomap_adjust_read_range() assumes that the position and length passed in
are block-aligned. This is not always the case however, as shown in the
syzbot generated case for erofs. This causes too many bytes to be
skipped for uptodate blocks, which results in returning the incorrect
position and length to read in. If all the blocks are uptodate, this
underflows length and returns a position beyond the folio.

Fix the calculation to also take into account the block offset when
calculating how many bytes can be skipped for uptodate blocks.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Tested-by: syzbot@syzkaller.appspotmail.com
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Joanne Koong and committed by
Christian Brauner
7aa6bc3e ca82a7ea

+13 -6
+13 -6
fs/iomap/buffered-io.c
··· 240 240 * to avoid reading in already uptodate ranges. 241 241 */ 242 242 if (ifs) { 243 - unsigned int i; 243 + unsigned int i, blocks_skipped; 244 244 245 245 /* move forward for each leading block marked uptodate */ 246 - for (i = first; i <= last; i++) { 246 + for (i = first; i <= last; i++) 247 247 if (!ifs_block_is_uptodate(ifs, i)) 248 248 break; 249 - *pos += block_size; 250 - poff += block_size; 251 - plen -= block_size; 252 - first++; 249 + 250 + blocks_skipped = i - first; 251 + if (blocks_skipped) { 252 + unsigned long block_offset = *pos & (block_size - 1); 253 + unsigned bytes_skipped = 254 + (blocks_skipped << block_bits) - block_offset; 255 + 256 + *pos += bytes_skipped; 257 + poff += bytes_skipped; 258 + plen -= bytes_skipped; 253 259 } 260 + first = i; 254 261 255 262 /* truncate len if we find any trailing uptodate block(s) */ 256 263 while (++i <= last) {