public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH for-5.7] io_uring: fix zero len do_splice()
@ 2020-05-04 20:00 Pavel Begunkov
  2020-05-04 20:14 ` Pavel Begunkov
  2020-05-09 16:07 ` Pavel Begunkov
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-05-04 20:00 UTC (permalink / raw)
  To: Jens Axboe, Jann Horn, io-uring, linux-kernel

do_splice() doesn't expect len to be 0. Just always return 0 in this
case as splice(2) do.

Fixes: 7d67af2c0134 ("io_uring: add splice(2) support")
Reported-by: Jann Horn <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 65458eda2127..d53a1ef2a205 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2772,16 +2772,19 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
 	struct file *out = sp->file_out;
 	unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
 	loff_t *poff_in, *poff_out;
-	long ret;
+	long ret = 0;
 
 	if (force_nonblock)
 		return -EAGAIN;
 
 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
-	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
-		return -EAGAIN;
+
+	if (sp->len) {
+		ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
+		if (force_nonblock && ret == -EAGAIN)
+			return -EAGAIN;
+	}
 
 	io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
 	req->flags &= ~REQ_F_NEED_CLEANUP;
-- 
2.24.0


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

* Re: [PATCH for-5.7] io_uring: fix zero len do_splice()
  2020-05-04 20:00 [PATCH for-5.7] io_uring: fix zero len do_splice() Pavel Begunkov
@ 2020-05-04 20:14 ` Pavel Begunkov
  2020-05-09 16:07 ` Pavel Begunkov
  1 sibling, 0 replies; 4+ messages in thread
From: Pavel Begunkov @ 2020-05-04 20:14 UTC (permalink / raw)
  To: Jens Axboe, Jann Horn, io-uring, linux-kernel, Alexander Viro,
	linux-fsdevel

On 04/05/2020 23:00, Pavel Begunkov wrote:
> do_splice() doesn't expect len to be 0. Just always return 0 in this
> case as splice(2) do.

There is a thing, splice/tee will always return success on len=0 even with
invalid fds. Fast return for len=0, should really has been done after basic
validation, but I don't want to break userspace.

Any ideas?

> 
> Fixes: 7d67af2c0134 ("io_uring: add splice(2) support")
> Reported-by: Jann Horn <[email protected]>
> Signed-off-by: Pavel Begunkov <[email protected]>
> ---
>  fs/io_uring.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 65458eda2127..d53a1ef2a205 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -2772,16 +2772,19 @@ static int io_splice(struct io_kiocb *req, bool force_nonblock)
>  	struct file *out = sp->file_out;
>  	unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
>  	loff_t *poff_in, *poff_out;
> -	long ret;
> +	long ret = 0;
>  
>  	if (force_nonblock)
>  		return -EAGAIN;
>  
>  	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
>  	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
> -	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
> -	if (force_nonblock && ret == -EAGAIN)
> -		return -EAGAIN;
> +
> +	if (sp->len) {
> +		ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
> +		if (force_nonblock && ret == -EAGAIN)
> +			return -EAGAIN;
> +	}
>  
>  	io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
>  	req->flags &= ~REQ_F_NEED_CLEANUP;
> 

-- 
Pavel Begunkov

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

* Re: [PATCH for-5.7] io_uring: fix zero len do_splice()
  2020-05-04 20:00 [PATCH for-5.7] io_uring: fix zero len do_splice() Pavel Begunkov
  2020-05-04 20:14 ` Pavel Begunkov
@ 2020-05-09 16:07 ` Pavel Begunkov
  2020-05-09 16:15   ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Pavel Begunkov @ 2020-05-09 16:07 UTC (permalink / raw)
  To: Jens Axboe, Jann Horn, io-uring, linux-kernel

On 04/05/2020 23:00, Pavel Begunkov wrote:
> do_splice() doesn't expect len to be 0. Just always return 0 in this
> case as splice(2) do.
> 

If it was missed, may you take a look? I reattached the patch btw killing
reported warnings.

---
From: Pavel Begunkov <[email protected]>
Subject: [PATCH] io_uring: fix zero len do_splice()

do_splice() doesn't expect len to be 0. Do the check in io_splice()
exactly as in sys_splice().

Fixes: 7d67af2c0134 ("io_uring: add splice(2) support")
Reported-by: Jann Horn <[email protected]>
Signed-off-by: Pavel Begunkov <[email protected]>
---
 fs/io_uring.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/io_uring.c b/fs/io_uring.c
index 65458eda2127..70d8943c337b 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -2772,16 +2772,16 @@ static int io_splice(struct io_kiocb *req, bool
force_nonblock)
 	struct file *out = sp->file_out;
 	unsigned int flags = sp->flags & ~SPLICE_F_FD_IN_FIXED;
 	loff_t *poff_in, *poff_out;
-	long ret;
+	long ret = 0;

 	if (force_nonblock)
 		return -EAGAIN;

 	poff_in = (sp->off_in == -1) ? NULL : &sp->off_in;
 	poff_out = (sp->off_out == -1) ? NULL : &sp->off_out;
-	ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);
-	if (force_nonblock && ret == -EAGAIN)
-		return -EAGAIN;
+
+	if (sp->len)
+		ret = do_splice(in, poff_in, out, poff_out, sp->len, flags);

 	io_put_file(req, in, (sp->flags & SPLICE_F_FD_IN_FIXED));
 	req->flags &= ~REQ_F_NEED_CLEANUP;
-- 
2.24.0

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

* Re: [PATCH for-5.7] io_uring: fix zero len do_splice()
  2020-05-09 16:07 ` Pavel Begunkov
@ 2020-05-09 16:15   ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-05-09 16:15 UTC (permalink / raw)
  To: Pavel Begunkov, Jann Horn, io-uring, linux-kernel

On 5/9/20 10:07 AM, Pavel Begunkov wrote:
> On 04/05/2020 23:00, Pavel Begunkov wrote:
>> do_splice() doesn't expect len to be 0. Just always return 0 in this
>> case as splice(2) do.
>>
> 
> If it was missed, may you take a look? I reattached the patch btw killing
> reported warnings.

Thanks for re-sending, I'll queue it up for 5.7.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-05-09 16:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-04 20:00 [PATCH for-5.7] io_uring: fix zero len do_splice() Pavel Begunkov
2020-05-04 20:14 ` Pavel Begunkov
2020-05-09 16:07 ` Pavel Begunkov
2020-05-09 16:15   ` Jens Axboe

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