public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] lib/iov_iter: fix bugs found via cross-function consistency review
@ 2026-03-13 18:10 Josh Law
  2026-03-13 18:10 ` [PATCH 1/7] lib/iov_iter: fix missing allocation failure check in iov_iter_extract_bvec_pages() Josh Law
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Josh Law @ 2026-03-13 18:10 UTC (permalink / raw)
  To: Andrew Morton, Alexander Viro
  Cc: linux-kernel, linux-block, linux-fsdevel, Josh Law

A systematic review of lib/iov_iter.c checking that each iterator type
is handled consistently across all functions turned up seven issues:

- Two can cause kernel oops: a missing allocation failure check in
  iov_iter_extract_bvec_pages() (NULL deref under memory pressure), and
  a missing NULL check in iov_iter_folioq_revert() (NULL deref when
  reverting past the head of a folio_queue chain).

- Two return wrong values for partially consumed iterators:
  iov_iter_single_seg_count() ignores iov_offset for folioq, and
  iov_iter_gap_alignment() ignores iov_offset for the first iovec
  segment.

- One fires a spurious WARN_ON_ONCE for kvec iterators in
  iov_iter_restore() due to a misplaced parenthesis.

- One can read out of bounds: iov_iter_alignment_iovec/bvec enter
  their do-while loops unconditionally even when count is zero.

- One is a testing gap: copy_to_user_iter_mc() lacks the
  should_fail_usercopy() check present in all other copy helpers.

All found through code review; no runtime failures were needed to
discover them.  Each patch is independent and can be applied
separately.

Josh Law (7):
  lib/iov_iter: fix missing allocation failure check in
    iov_iter_extract_bvec_pages()
  lib/iov_iter: add NULL check on folioq->prev in
    iov_iter_folioq_revert()
  lib/iov_iter: fix misplaced parenthesis in iov_iter_restore() kvec
    check
  lib/iov_iter: account for iov_offset in iov_iter_single_seg_count()
    folioq path
  lib/iov_iter: account for iov_offset in iov_iter_gap_alignment()
  lib/iov_iter: guard iov_iter_alignment() against zero-count iovec/bvec
    iterators
  lib/iov_iter: add missing should_fail_usercopy() in
    copy_to_user_iter_mc()

 lib/iov_iter.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-03-23 15:16 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 18:10 [PATCH 0/7] lib/iov_iter: fix bugs found via cross-function consistency review Josh Law
2026-03-13 18:10 ` [PATCH 1/7] lib/iov_iter: fix missing allocation failure check in iov_iter_extract_bvec_pages() Josh Law
2026-03-13 18:16   ` Caleb Sander Mateos
2026-03-13 18:20     ` Josh Law
2026-03-13 18:22       ` Caleb Sander Mateos
2026-03-13 18:10 ` [PATCH 2/7] lib/iov_iter: add NULL check on folioq->prev in iov_iter_folioq_revert() Josh Law
2026-03-13 18:10 ` [PATCH 3/7] lib/iov_iter: fix misplaced parenthesis in iov_iter_restore() kvec check Josh Law
2026-03-23 12:39   ` Christian Brauner
2026-03-23 15:16     ` Josh Law
2026-03-13 18:10 ` [PATCH 4/7] lib/iov_iter: account for iov_offset in iov_iter_single_seg_count() folioq path Josh Law
2026-03-13 18:10 ` [PATCH 5/7] lib/iov_iter: account for iov_offset in iov_iter_gap_alignment() Josh Law
2026-03-13 18:10 ` [PATCH 6/7] lib/iov_iter: guard iov_iter_alignment() against zero-count iovec/bvec iterators Josh Law
2026-03-13 18:10 ` [PATCH 7/7] lib/iov_iter: add missing should_fail_usercopy() in copy_to_user_iter_mc() Josh Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox