mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF
@ 2023-04-01  6:05 Sandeep Dhavale
  2023-04-01  6:05 ` [PATCH v1 1/2] usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF Sandeep Dhavale
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sandeep Dhavale @ 2023-04-01  6:05 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Keith Busch, Jens Axboe
  Cc: Sandeep Dhavale, kernel-team, linux-usb, linux-kernel

Since the commit 1e23db450cff ("io_uring: use iter_ubuf for single range
imports") .read_iter() can be called with iov type ITER_UBUF.
In such case dup_iter() will correctly dup but it will not allocate
any memory. But callers ffs_epfile_read_iter and ep_read_iter treat
this as a failure.

Following patches address this by checking if iter_is_ubuf().
Without the fix, async IOs from io_uring will be returned with -ENOMEM.

Sandeep Dhavale (2):
  usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF
  usb: gadgetfs: Fix ep_read_iter to handle ITER_UBUF

 drivers/usb/gadget/function/f_fs.c | 2 +-
 drivers/usb/gadget/legacy/inode.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

-- 
2.40.0.348.gf938b09366-goog


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

* [PATCH v1 1/2] usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF
  2023-04-01  6:05 [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Sandeep Dhavale
@ 2023-04-01  6:05 ` Sandeep Dhavale
  2023-04-01  6:05 ` [PATCH v1 2/2] usb: gadgetfs: Fix ep_read_iter " Sandeep Dhavale
  2023-04-01 16:08 ` [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Sandeep Dhavale @ 2023-04-01  6:05 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jens Axboe, Keith Busch
  Cc: Sandeep Dhavale, kernel-team, linux-usb, linux-kernel

iov_iter for ffs_epfile_read_iter can be ITER_UBUF with io_uring.
In that case dup_iter() does not have to allocate anything and it
can return NULL. ffs_epfile_read_iter treats this as a failure and
returns -ENOMEM. Fix it by checking if iter_is_ubuf().

Fixes: 1e23db450cff ("io_uring: use iter_ubuf for single range imports")
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 8830847fbf97..a13c946e0663 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1230,7 +1230,7 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to)
 	p->kiocb = kiocb;
 	if (p->aio) {
 		p->to_free = dup_iter(&p->data, to, GFP_KERNEL);
-		if (!p->to_free) {
+		if (!iter_is_ubuf(&p->data) && !p->to_free) {
 			kfree(p);
 			return -ENOMEM;
 		}
-- 
2.40.0.348.gf938b09366-goog


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

* [PATCH v1 2/2] usb: gadgetfs: Fix ep_read_iter to handle ITER_UBUF
  2023-04-01  6:05 [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Sandeep Dhavale
  2023-04-01  6:05 ` [PATCH v1 1/2] usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF Sandeep Dhavale
@ 2023-04-01  6:05 ` Sandeep Dhavale
  2023-04-01 16:08 ` [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Sandeep Dhavale @ 2023-04-01  6:05 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Keith Busch, Jens Axboe
  Cc: Sandeep Dhavale, kernel-team, linux-usb, linux-kernel

iov_iter for ep_read_iter can be ITER_UBUF with io_uring.
In that case dup_iter() does not have to allocate iov and it can
return NULL. Fix the assumption by checking for iter_is_ubuf()
other wise ep_read_iter can treat this as failure and return -ENOMEM.

Fixes: 1e23db450cff ("io_uring: use iter_ubuf for single range imports")
Signed-off-by: Sandeep Dhavale <dhavale@google.com>
---
 drivers/usb/gadget/legacy/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index d605bc2e7e8f..28249d0bf062 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -614,7 +614,7 @@ ep_read_iter(struct kiocb *iocb, struct iov_iter *to)
 		if (!priv)
 			goto fail;
 		priv->to_free = dup_iter(&priv->to, to, GFP_KERNEL);
-		if (!priv->to_free) {
+		if (!iter_is_ubuf(&priv->to) && !priv->to_free) {
 			kfree(priv);
 			goto fail;
 		}
-- 
2.40.0.348.gf938b09366-goog


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

* Re: [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF
  2023-04-01  6:05 [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Sandeep Dhavale
  2023-04-01  6:05 ` [PATCH v1 1/2] usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF Sandeep Dhavale
  2023-04-01  6:05 ` [PATCH v1 2/2] usb: gadgetfs: Fix ep_read_iter " Sandeep Dhavale
@ 2023-04-01 16:08 ` Jens Axboe
  2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2023-04-01 16:08 UTC (permalink / raw)
  To: Sandeep Dhavale, Greg Kroah-Hartman, Keith Busch
  Cc: kernel-team, linux-usb, linux-kernel

On 4/1/23 12:05?AM, Sandeep Dhavale wrote:
> Since the commit 1e23db450cff ("io_uring: use iter_ubuf for single range
> imports") .read_iter() can be called with iov type ITER_UBUF.
> In such case dup_iter() will correctly dup but it will not allocate
> any memory. But callers ffs_epfile_read_iter and ep_read_iter treat
> this as a failure.
> 
> Following patches address this by checking if iter_is_ubuf().
> Without the fix, async IOs from io_uring will be returned with -ENOMEM.

Looks fine to me. The dup_iter() interface is somewhat unfortunate, as
it doesn't return an error pointer. Hence NULL can be failed or success,
depending on the type. Looks like cifs is the only other user of
dup_iter(), and that checks the type first. You could do something like
that too in the gadget code. Or we could fix the API... And it is kind
of silly calling into dup_iter() when you don't need it. But for now,
this will probably suffice:

Acked-by: Jens Axboe <axboe@kernel.dk>

-- 
Jens Axboe


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

end of thread, other threads:[~2023-04-01 16:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-01  6:05 [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Sandeep Dhavale
2023-04-01  6:05 ` [PATCH v1 1/2] usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF Sandeep Dhavale
2023-04-01  6:05 ` [PATCH v1 2/2] usb: gadgetfs: Fix ep_read_iter " Sandeep Dhavale
2023-04-01 16:08 ` [PATCH v1 0/2] USB: Fixes for handling ITER_UBUF Jens Axboe

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®