mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io()
@ 2026-07-27 16:24 Caleb Sander Mateos
  2026-07-28  2:47 ` Ming Lei
  0 siblings, 1 reply; 4+ messages in thread
From: Caleb Sander Mateos @ 2026-07-27 16:24 UTC (permalink / raw)
  To: Ming Lei, Jens Axboe; +Cc: Caleb Sander Mateos, linux-block, linux-kernel

io->res is set from struct ublksrv_io_cmd's result field, which is
controlled by the ublk server process, without any validation. It's thus
possible for userspace to trigger the io->res > rq_bytes warning.
ublk_copy_user_pages() already limits the copy length to the request
data length, so drop the warning.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
---
 drivers/block/ublk_drv.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 4ca6ec738c93..4f30644756df 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
 
 	if (ublk_need_unmap_req(req)) {
 		struct iov_iter iter;
 		const int dir = ITER_SOURCE;
 
-		WARN_ON_ONCE(io->res > rq_bytes);
-
 		import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
 		return ublk_copy_user_pages(req, 0, &iter, dir);
 	}
 	return rq_bytes;
 }
-- 
2.54.0


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

* Re: [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io()
  2026-07-27 16:24 [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io() Caleb Sander Mateos
@ 2026-07-28  2:47 ` Ming Lei
  2026-07-28 18:22   ` Caleb Sander Mateos
  0 siblings, 1 reply; 4+ messages in thread
From: Ming Lei @ 2026-07-28  2:47 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

On Mon, Jul 27, 2026 at 11:24 AM Caleb Sander Mateos
<csander@purestorage.com> wrote:
>
> io->res is set from struct ublksrv_io_cmd's result field, which is
> controlled by the ublk server process, without any validation. It's thus
> possible for userspace to trigger the io->res > rq_bytes warning.
> ublk_copy_user_pages() already limits the copy length to the request
> data length, so drop the warning.
>
> Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> ---
>  drivers/block/ublk_drv.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 4ca6ec738c93..4f30644756df 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
>
>         if (ublk_need_unmap_req(req)) {
>                 struct iov_iter iter;
>                 const int dir = ITER_SOURCE;
>
> -               WARN_ON_ONCE(io->res > rq_bytes);
> -
>                 import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
>                 return ublk_copy_user_pages(req, 0, &iter, dir);
>         }
>         return rq_bytes;

The change may be fine, however access_ok() still can fail from import_ubuf(),
so can we consolidate ublk_unmap_io() a bit?


Thanks,
Ming Lei

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

* Re: [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io()
  2026-07-28  2:47 ` Ming Lei
@ 2026-07-28 18:22   ` Caleb Sander Mateos
  2026-07-29  1:56     ` Ming Lei
  0 siblings, 1 reply; 4+ messages in thread
From: Caleb Sander Mateos @ 2026-07-28 18:22 UTC (permalink / raw)
  To: Ming Lei; +Cc: Jens Axboe, linux-block, linux-kernel

On Mon, Jul 27, 2026 at 7:47 PM Ming Lei <tom.leiming@gmail.com> wrote:
>
> On Mon, Jul 27, 2026 at 11:24 AM Caleb Sander Mateos
> <csander@purestorage.com> wrote:
> >
> > io->res is set from struct ublksrv_io_cmd's result field, which is
> > controlled by the ublk server process, without any validation. It's thus
> > possible for userspace to trigger the io->res > rq_bytes warning.
> > ublk_copy_user_pages() already limits the copy length to the request
> > data length, so drop the warning.
> >
> > Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> > ---
> >  drivers/block/ublk_drv.c | 2 --
> >  1 file changed, 2 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 4ca6ec738c93..4f30644756df 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
> >
> >         if (ublk_need_unmap_req(req)) {
> >                 struct iov_iter iter;
> >                 const int dir = ITER_SOURCE;
> >
> > -               WARN_ON_ONCE(io->res > rq_bytes);
> > -
> >                 import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
> >                 return ublk_copy_user_pages(req, 0, &iter, dir);
> >         }
> >         return rq_bytes;
>
> The change may be fine, however access_ok() still can fail from import_ubuf(),
> so can we consolidate ublk_unmap_io() a bit?

Sorry, not quite sure what you mean by "consolidate". Are you saying
there should be a check of the import_ubuf() return value in
ublk_map_io() and ublk_unmap_io()?

Thanks,
Caleb

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

* Re: [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io()
  2026-07-28 18:22   ` Caleb Sander Mateos
@ 2026-07-29  1:56     ` Ming Lei
  0 siblings, 0 replies; 4+ messages in thread
From: Ming Lei @ 2026-07-29  1:56 UTC (permalink / raw)
  To: Caleb Sander Mateos; +Cc: Jens Axboe, linux-block, linux-kernel

On Tue, Jul 28, 2026 at 11:22:00AM -0700, Caleb Sander Mateos wrote:
> On Mon, Jul 27, 2026 at 7:47 PM Ming Lei <tom.leiming@gmail.com> wrote:
> >
> > On Mon, Jul 27, 2026 at 11:24 AM Caleb Sander Mateos
> > <csander@purestorage.com> wrote:
> > >
> > > io->res is set from struct ublksrv_io_cmd's result field, which is
> > > controlled by the ublk server process, without any validation. It's thus
> > > possible for userspace to trigger the io->res > rq_bytes warning.
> > > ublk_copy_user_pages() already limits the copy length to the request
> > > data length, so drop the warning.
> > >
> > > Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
> > > ---
> > >  drivers/block/ublk_drv.c | 2 --
> > >  1 file changed, 2 deletions(-)
> > >
> > > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > > index 4ca6ec738c93..4f30644756df 100644
> > > --- a/drivers/block/ublk_drv.c
> > > +++ b/drivers/block/ublk_drv.c
> > > @@ -1492,12 +1492,10 @@ static unsigned int ublk_unmap_io(bool need_map,
> > >
> > >         if (ublk_need_unmap_req(req)) {
> > >                 struct iov_iter iter;
> > >                 const int dir = ITER_SOURCE;
> > >
> > > -               WARN_ON_ONCE(io->res > rq_bytes);
> > > -
> > >                 import_ubuf(dir, u64_to_user_ptr(io->buf.addr), io->res, &iter);
> > >                 return ublk_copy_user_pages(req, 0, &iter, dir);
> > >         }
> > >         return rq_bytes;
> >
> > The change may be fine, however access_ok() still can fail from import_ubuf(),
> > so can we consolidate ublk_unmap_io() a bit?
> 
> Sorry, not quite sure what you mean by "consolidate". Are you saying
> there should be a check of the import_ubuf() return value in
> ublk_map_io() and ublk_unmap_io()?

Yeah.

Thanks,
Ming

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

end of thread, other threads:[~2026-07-29  1:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-27 16:24 [PATCH] ublk: remove WARN_ON_ONCE() in ublk_unmap_io() Caleb Sander Mateos
2026-07-28  2:47 ` Ming Lei
2026-07-28 18:22   ` Caleb Sander Mateos
2026-07-29  1:56     ` Ming Lei

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

all inboxes | Powered by JetHome®