Re: [PATCH] FS: fix stack-out-of-bounds wanning

From: Al Viro
Date: Mon May 08 2017 - 20:26:56 EST


On Mon, May 08, 2017 at 04:42:50PM -0700, Shaohua Li wrote:
> I'm seeing below with lastet upstream. Commit
> 5ecda13(generic_file_read_iter(): make use of iov_iter_revert())
> directly pass iter to ->direct_IO(), ->direct_io already advances count
> bytes but return -EIOCBQUEUED. In this case, count is bigger than
> iov_iter_count(iter). We really want to revert count -
> iov_iter_count(iter) instead of the opposite.

Already discussed; the patch in my tree is that braino fix + sanity check
in iov_iter_revert(), to prevent anything similar in the future.

The reason it wasn't caught in tests (without KASAN, that is) is that
to get really obvious breakage out of that, you need a short read from
->direct_IO() *and* fallback to cached read after it. -EIOCBQUEUED
obviously excludes the latter, so the bug is almost certain to remain quiet.
There is a non-zero chance of actually running into unmapped memory while
doing that iov_iter_revert(), but it's fairly low. Unfortunately, since
that allowed the damn thing to remain unnoticed...

Will be in tonight's pull request.