Re: slab-out-of-bounds in iov_iter_revert()

From: Al Viro
Date: Thu Sep 17 2020 - 12:46:48 EST

On Thu, Sep 17, 2020 at 10:10:27AM -0400, Qian Cai wrote:

> [ 81.942909] generic_file_read_iter+0x23b/0x4b0
> [ 81.942918] fuse_file_read_iter+0x280/0x4e0 [fuse]
> [ 81.942931] ? fuse_direct_IO+0xd30/0xd30 [fuse]
> [ 81.942949] ? _raw_spin_lock_irqsave+0x80/0xe0
> [ 81.942957] ? timerqueue_add+0x15e/0x280
> [ 81.942960] ? _raw_spin_lock_irqsave+0x80/0xe0
> [ 81.942966] new_sync_read+0x3b7/0x620
> [ 81.942968] ? __ia32_sys_llseek+0x2e0/0x2e0

Interesting... Basic logics in there:
->direct_IO() might consume more (on iov_iter_get_pages()
and friends) than it actually reads. We want to revert the
excess. Suppose by the time we call ->direct_IO() we had
N bytes already consumed and C bytes left. We expect that
after ->direct_IO() returns K, we have C' bytes left, N + (C - C')
consumed and N + K out of those actually read. So we revert by
C - K - C'. You end up trying to revert beyond the beginning.

Use of iov_iter_truncate() is problematic here, since it
changes the amount of data left without having consumed anything.
Basically, it changes the position of end, and the logics in the
caller expects that to remain unchanged. iov_iter_reexpand() use
should restore the position of end.

How much IO does it take to trigger that on your reproducer?