All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <gabriel@krisman.be>
To: "Ömer Mete Kaya" <omermetekaya0@gmail.com>, axboe@kernel.dk
Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Ömer Mete Kaya" <omermetekaya0@gmail.com>
Subject: Re: [PATCH] io_uring: fix out-of-bounds bvec access in io_vec_fill_kern_bvec
Date: Thu, 01 Oct 2026 11:36:18 -0400	[thread overview]
Message-ID: <87se2pwhzh.fsf@mailhost.krisman.be> (raw)
In-Reply-To: <20261001143003.755790-1-omermetekaya0@gmail.com>

Ömer Mete Kaya <omermetekaya0@gmail.com> writes:

> for_each_mp_bvec() dereferences src_bvec[bi_idx] in the loop condition
> before the body is entered, with no guard against bi_idx reaching
> imu->nr_bvecs. iov_kern_bvec_size() stops iterating when i reaches
> imu->nr_bvecs even if bi_size is still non-zero, so the fill loop can
> walk past the end of the bvec array and overrun res_bvec[].
>
> Open-code the loop with an explicit bi_idx < imu->nr_bvecs check before
> the dereference, matching the termination condition in
> iov_kern_bvec_size().

Do you have a reproducer?  This should be checked in iov_kern_bvec_size.
We make sure it doesn't go through imu->len which should match bv_len,
IIUC.

>
> Fixes: 1045afae4b88 ("io_uring: support vectored kernel fixed buffer")
> Signed-off-by: Ömer Mete Kaya <omermetekaya0@gmail.com>
> ---
>  io_uring/rsrc.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c
> index 51b46e624..3d29a0c7b 100644
> --- a/io_uring/rsrc.c
> +++ b/io_uring/rsrc.c
> @@ -1614,8 +1614,13 @@ static int io_vec_fill_kern_bvec(int ddir, struct iov_iter *iter,
>  		struct bio_vec bv;
>
>  		bvec_iter_advance(src_bvec, &bi, offset);
> -		for_each_mp_bvec(bv, src_bvec, bi, bi)
> +		while (bi.bi_size) {

bi.bi_size is the first condition of for_each_mp_bvec.  Do you really
need an open coded loop?  If there is an issue, can we just add the
check below?

> +			if (bi.bi_idx >= imu->nr_bvecs)
> +				return -EFAULT;

> +			bv = mp_bvec_iter_bvec(src_bvec, bi);
>  			res_bvec[res_idx++] = bv;
> +			bvec_iter_advance_single(src_bvec, &bi, bv.bv_len);
> +		}
>  		total_len += iov_len;
>  	}
>  	iov_iter_bvec(iter, ddir, res_bvec, res_idx, total_len);
> --
> 2.55.0
>

-- 
Gabriel Krisman Bertazi

  reply	other threads:[~2026-10-01 15:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 14:23 [PATCH] io_uring: fix out-of-bounds bvec access in io_vec_fill_kern_bvec Ömer Mete Kaya
2026-10-01 15:36 ` Gabriel Krisman Bertazi [this message]
2026-10-01 19:55   ` Ömer Mete Kaya
2026-10-02  6:04     ` Ming Lei
2026-10-02 14:55       ` Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87se2pwhzh.fsf@mailhost.krisman.be \
    --to=gabriel@krisman.be \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=omermetekaya0@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.