[syzbot] KASAN: stack-out-of-bounds Read in iov_iter_revert

95 views
Skip to first unread message

syzbot

unread,
Aug 12, 2021, 9:43:18 AM8/12/21
to asml.s...@gmail.com, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 1746f4db5135 Merge tag 'orphans-v5.14-rc6' of git://git.ke..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=111065fa300000
kernel config: https://syzkaller.appspot.com/x/.config?x=e3a20bae04b96ccd
dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953
compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=119dcaf6300000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=120d216e300000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+967169...@syzkaller.appspotmail.com

==================================================================
BUG: KASAN: stack-out-of-bounds in iov_iter_revert lib/iov_iter.c:1093 [inline]
BUG: KASAN: stack-out-of-bounds in iov_iter_revert+0x803/0x900 lib/iov_iter.c:1033
Read of size 8 at addr ffffc9000cf478b0 by task syz-executor673/8439

CPU: 0 PID: 8439 Comm: syz-executor673 Not tainted 5.14.0-rc5-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:105
print_address_description.constprop.0.cold+0xf/0x309 mm/kasan/report.c:233
__kasan_report mm/kasan/report.c:419 [inline]
kasan_report.cold+0x83/0xdf mm/kasan/report.c:436
iov_iter_revert lib/iov_iter.c:1093 [inline]
iov_iter_revert+0x803/0x900 lib/iov_iter.c:1033
io_write+0x57b/0xed0 fs/io_uring.c:3459
io_issue_sqe+0x28c/0x6920 fs/io_uring.c:6181
__io_queue_sqe+0x1ac/0xf00 fs/io_uring.c:6464
io_queue_sqe fs/io_uring.c:6507 [inline]
io_submit_sqe fs/io_uring.c:6662 [inline]
io_submit_sqes+0x63ea/0x7bc0 fs/io_uring.c:6778
__do_sys_io_uring_enter+0xb03/0x1d40 fs/io_uring.c:9389
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x43f8a9
Code: 28 c3 e8 1a 15 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffcc6759968 EFLAGS: 00000246 ORIG_RAX: 00000000000001aa
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 000000000043f8a9
RDX: 0000000000000000 RSI: 00000000000052fe RDI: 0000000000000003
RBP: 00007ffcc6759988 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffcc6759990
R13: 0000000000000000 R14: 00000000004ae018 R15: 0000000000400488


addr ffffc9000cf478b0 is located in stack of task syz-executor673/8439 at offset 152 in frame:
io_write+0x0/0xed0 fs/io_uring.c:3335

this frame has 3 objects:
[48, 56) 'iovec'
[80, 120) '__iter'
[160, 288) 'inline_vecs'

Memory state around the buggy address:
ffffc9000cf47780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
ffffc9000cf47800: 00 00 00 f1 f1 f1 f1 00 00 00 f2 f2 f2 00 00 00
>ffffc9000cf47880: 00 00 f2 f2 f2 f2 f2 00 00 00 00 00 00 00 00 00
^
ffffc9000cf47900: 00 00 00 00 00 00 00 f3 f3 f3 f3 00 00 00 00 00
ffffc9000cf47980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
syzbot can test patches for this issue, for details see:
https://goo.gl/tpsmEJ#testing-patches

Pavel Begunkov

unread,
Aug 12, 2021, 10:30:42 AM8/12/21
to syzbot, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On 8/12/21 2:43 PM, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 1746f4db5135 Merge tag 'orphans-v5.14-rc6' of git://git.ke..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=111065fa300000
> kernel config: https://syzkaller.appspot.com/x/.config?x=e3a20bae04b96ccd
> dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=119dcaf6300000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=120d216e300000
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+967169...@syzkaller.appspotmail.com

I believe, was already discovered and sent out, let's try v2:

#syz test: https://github.com/isilence/linux.git truncate
--
Pavel Begunkov


syzbot

unread,
Aug 12, 2021, 4:36:08 PM8/12/21
to asml.s...@gmail.com, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+967169...@syzkaller.appspotmail.com

Tested on:

commit: bff2c168 io_uring: don't retry with truncated iter
git tree: https://github.com/isilence/linux.git truncate
kernel config: https://syzkaller.appspot.com/x/.config?x=730106bfb5bf8ace
dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953
compiler: Debian clang version 11.0.1-2, GNU ld (GNU Binutils for Debian) 2.35.1

Note: testing is done by a robot and is best-effort only.

Pavel Begunkov

unread,
Aug 22, 2021, 8:24:49 PM8/22/21
to syzbot, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On 8/12/21 2:43 PM, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 1746f4db5135 Merge tag 'orphans-v5.14-rc6' of git://git.ke..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=111065fa300000
> kernel config: https://syzkaller.appspot.com/x/.config?x=e3a20bae04b96ccd
> dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.1
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=119dcaf6300000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=120d216e300000
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+967169...@syzkaller.appspotmail.com

#syz test: https://github.com/isilence/linux.git syztest_trunc2
--
Pavel Begunkov

syzbot

unread,
Aug 22, 2021, 8:44:04 PM8/22/21
to asml.s...@gmail.com, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+967169...@syzkaller.appspotmail.com

Tested on:

commit: b917c794 io_uring: fix revert truncated vecs
git tree: https://github.com/isilence/linux.git syztest_trunc2
kernel config: https://syzkaller.appspot.com/x/.config?x=4aa932b5eaeee9ef
dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953

Lee Jones

unread,
Nov 3, 2021, 1:01:27 PM11/3/21
to syzbot, asml.s...@gmail.com, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Good afternoon Pavel,
As you can see in the 'dashboard link' above this bug also affects
android-5-10 which is currently based on v5.10.75.

I see that the back-port of this patch failed in v5.10.y:

https://lore.kernel.org/stable/1631525...@kroah.com/

And after solving the build-error by back-porting both:

2112ff5ce0c11 iov_iter: track truncated size
89c2b3b749182 io_uring: reexpand under-reexpanded iters

I now see execution tripping the WARN() in iov_iter_revert():

if (WARN_ON(unroll > MAX_RW_COUNT))
return

Am I missing any additional patches required to fix stable/v5.10.y?

Any help would be gratefully received.

Kind regards,
Lee

--
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog

Pavel Begunkov

unread,
Nov 8, 2021, 10:29:50 AM11/8/21
to Lee Jones, syzbot, ax...@kernel.dk, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On 11/3/21 17:01, Lee Jones wrote:
> Good afternoon Pavel,
>
>> syzbot has tested the proposed patch and the reproducer did not trigger any issue:
>>
>> Reported-and-tested-by: syzbot+967169...@syzkaller.appspotmail.com
>>
>> Tested on:
>>
>> commit: bff2c168 io_uring: don't retry with truncated iter
>> git tree: https://github.com/isilence/linux.git truncate
>> kernel config: https://syzkaller.appspot.com/x/.config?x=730106bfb5bf8ace
>> dashboard link: https://syzkaller.appspot.com/bug?extid=9671693590ef5aad8953
>> compiler: Debian clang version 11.0.1-2, GNU ld (GNU Binutils for Debian) 2.35.1
>>
>> Note: testing is done by a robot and is best-effort only.
>
> As you can see in the 'dashboard link' above this bug also affects
> android-5-10 which is currently based on v5.10.75.
>
> I see that the back-port of this patch failed in v5.10.y:
>
> https://lore.kernel.org/stable/1631525...@kroah.com/
>
> And after solving the build-error by back-porting both:
>
> 2112ff5ce0c11 iov_iter: track truncated size
> 89c2b3b749182 io_uring: reexpand under-reexpanded iters
>
> I now see execution tripping the WARN() in iov_iter_revert():
>
> if (WARN_ON(unroll > MAX_RW_COUNT))
> return
>
> Am I missing any additional patches required to fix stable/v5.10.y?

Is it the same syz test? There was a couple more patches for
IORING_SETUP_IOPOLL, but strange if that's not the case.


fwiw, Jens decided to replace it with another mechanism shortly
after, so it may be a better idea to backport those. Jens,
what do you think?


commit 8fb0f47a9d7acf620d0fd97831b69da9bc5e22ed
Author: Jens Axboe <ax...@kernel.dk>
Date: Fri Sep 10 11:18:36 2021 -0600

iov_iter: add helper to save iov_iter state

commit cd65869512ab5668a5d16f789bc4da1319c435c4
Author: Jens Axboe <ax...@kernel.dk>
Date: Fri Sep 10 11:19:14 2021 -0600

io_uring: use iov_iter state save/restore helpers


--
Pavel Begunkov

Jens Axboe

unread,
Nov 8, 2021, 10:41:54 AM11/8/21
to Pavel Begunkov, Lee Jones, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Yes, I think backporting based on the save/restore setup is the
sanest way by far.

--
Jens Axboe

Lee Jones

unread,
Nov 9, 2021, 8:33:37 AM11/9/21
to Jens Axboe, Pavel Begunkov, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
Would you be kind enough to attempt to send these patches to Stable?

When I tried to back-port them, the second one gave me trouble. And
without the in depth knowledge of the driver/subsystem that you guys
have, I found it almost impossible to resolve all of the conflicts:

diff --cc fs/io_uring.c
index 104dff9c71314,25bda8a5a4e5d..0000000000000
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@@ -2567,57 -2603,20 +2568,64 @@@ static void io_complete_rw_common(struc
}

#ifdef CONFIG_BLOCK
-static bool io_resubmit_prep(struct io_kiocb *req)
+static bool io_resubmit_prep(struct io_kiocb *req, int error)
{
- struct io_async_rw *rw = req->async_data;
+ struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs;
+ ssize_t ret = -ECANCELED;
+ struct iov_iter iter;
+ int rw;
+
++<<<<<<< HEAD
+ if (error) {
+ ret = error;
+ goto end_req;
+ }
+
+ switch (req->opcode) {
+ case IORING_OP_READV:
+ case IORING_OP_READ_FIXED:
+ case IORING_OP_READ:
+ rw = READ;
+ break;
+ case IORING_OP_WRITEV:
+ case IORING_OP_WRITE_FIXED:
+ case IORING_OP_WRITE:
+ rw = WRITE;
+ break;
+ default:
+ printk_once(KERN_WARNING "io_uring: bad opcode in resubmit %d\n",
+ req->opcode);
+ goto end_req;
+ }

+ if (!req->async_data) {
+ ret = io_import_iovec(rw, req, &iovec, &iter, false);
+ if (ret < 0)
+ goto end_req;
+ ret = io_setup_async_rw(req, iovec, inline_vecs, &iter, false);
+ if (!ret)
+ return true;
+ kfree(iovec);
+ } else {
+ return true;
+ }
+end_req:
+ req_set_fail_links(req);
+ return false;
++=======
+ if (!rw)
+ return !io_req_prep_async(req);
+ iov_iter_restore(&rw->iter, &rw->iter_state);
+ return true;
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)
}
+#endif

-static bool io_rw_should_reissue(struct io_kiocb *req)
+static bool io_rw_reissue(struct io_kiocb *req, long res)
{
+#ifdef CONFIG_BLOCK
umode_t mode = file_inode(req->file)->i_mode;
- struct io_ring_ctx *ctx = req->ctx;
+ int ret;

if (!S_ISBLK(mode) && !S_ISREG(mode))
return false;
@@@ -3268,13 -3307,20 +3276,23 @@@ static int io_setup_async_rw(struct io_
const struct iovec *fast_iov,
struct iov_iter *iter, bool force)
{
- if (!force && !io_op_defs[req->opcode].needs_async_setup)
+ if (!force && !io_op_defs[req->opcode].needs_async_data)
return 0;
if (!req->async_data) {
++<<<<<<< HEAD
+ if (__io_alloc_async_data(req))
++=======
+ struct io_async_rw *iorw;
+
+ if (io_alloc_async_data(req)) {
+ kfree(iovec);
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)
return -ENOMEM;
- }

io_req_map_rw(req, iovec, fast_iov, iter);
+ iorw = req->async_data;
+ /* we've copied and mapped the iter, ensure state is saved */
+ iov_iter_save_state(&iorw->iter, &iorw->iter_state);
}
return 0;
}
@@@ -3417,18 -3443,28 +3436,43 @@@ static int io_read(struct io_kiocb *req
struct kiocb *kiocb = &req->rw.kiocb;
struct iov_iter __iter, *iter = &__iter;
struct io_async_rw *rw = req->async_data;
++<<<<<<< HEAD
+ ssize_t io_size, ret, ret2;
+ bool no_async;
++=======
+ bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
+ struct iov_iter_state __state, *state;
+ ssize_t ret, ret2;
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

- if (rw) {
+ if (rw)
iter = &rw->iter;
++<<<<<<< HEAD
+
+ ret = io_import_iovec(READ, req, &iovec, iter, !force_nonblock);
+ if (ret < 0)
+ return ret;
+ io_size = iov_iter_count(iter);
+ req->result = io_size;
+ ret = 0;
++=======
+ state = &rw->iter_state;
+ /*
+ * We come here from an earlier attempt, restore our state to
+ * match in case it doesn't. It's cheap enough that we don't
+ * need to make this conditional.
+ */
+ iov_iter_restore(iter, state);
+ iovec = NULL;
+ } else {
+ ret = io_import_iovec(READ, req, &iovec, iter, !force_nonblock);
+ if (ret < 0)
+ return ret;
+ state = &__state;
+ iov_iter_save_state(iter, state);
+ }
+ req->result = iov_iter_count(iter);
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

/* Ensure we clear previously set non-block flag */
if (!force_nonblock)
@@@ -3436,15 -3472,17 +3480,23 @@@
else
kiocb->ki_flags |= IOCB_NOWAIT;

+
/* If the file doesn't support async, just async punt */
- if (force_nonblock && !io_file_supports_nowait(req, READ)) {
- ret = io_setup_async_rw(req, iovec, inline_vecs, iter, true);
- return ret ?: -EAGAIN;
- }
+ no_async = force_nonblock && !io_file_supports_async(req->file, READ);
+ if (no_async)
+ goto copy_iov;

++<<<<<<< HEAD
+ ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), io_size);
+ if (unlikely(ret))
+ goto out_free;
++=======
+ ret = rw_verify_area(READ, req->file, io_kiocb_ppos(kiocb), req->result);
+ if (unlikely(ret)) {
+ kfree(iovec);
+ return ret;
+ }
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

ret = io_iter_do_read(req, iter);

@@@ -3457,68 -3491,78 +3509,133 @@@
/* IOPOLL retry should happen for io-wq threads */
if (!force_nonblock && !(req->ctx->flags & IORING_SETUP_IOPOLL))
goto done;
- /* no retry on NONBLOCK nor RWF_NOWAIT */
- if (req->flags & REQ_F_NOWAIT)
+ /* no retry on NONBLOCK marked file */
+ if (req->file->f_flags & O_NONBLOCK)
goto done;
++<<<<<<< HEAD
+ /* some cases will consume bytes even on error returns */
+ iov_iter_revert(iter, io_size - iov_iter_count(iter));
+ ret = 0;
+ goto copy_iov;
+ } else if (ret < 0) {
+ /* make sure -ERESTARTSYS -> -EINTR is done */
+ goto done;
+ }
+
+ /* read it all, or we did blocking attempt. no retry. */
+ if (!iov_iter_count(iter) || !force_nonblock ||
+ (req->file->f_flags & O_NONBLOCK) || !(req->flags & REQ_F_ISREG))
+ goto done;
++=======
+ ret = 0;
+ } else if (ret == -EIOCBQUEUED) {
+ goto out_free;
+ } else if (ret <= 0 || ret == req->result || !force_nonblock ||
+ (req->flags & REQ_F_NOWAIT) || !need_read_all(req)) {
+ /* read all, failed, already did sync or don't want to retry */
+ goto done;
+ }
+
+ /*
+ * Don't depend on the iter state matching what was consumed, or being
+ * untouched in case of error. Restore it and we'll advance it
+ * manually if we need to.
+ */
+ iov_iter_restore(iter, state);
+
+ ret2 = io_setup_async_rw(req, iovec, inline_vecs, iter, true);
+ if (ret2)
+ return ret2;
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

- iovec = NULL;
+ io_size -= ret;
+copy_iov:
+ ret2 = io_setup_async_rw(req, iovec, inline_vecs, iter, true);
+ if (ret2) {
+ ret = ret2;
+ goto out_free;
+ }
+ if (no_async)
+ return -EAGAIN;
rw = req->async_data;
++<<<<<<< HEAD
+ /* it's copied and will be cleaned with ->io */
+ iovec = NULL;
+ /* now use our persistent iterator, if we aren't already */
+ iter = &rw->iter;
+retry:
+ rw->bytes_done += ret;
+ /* if we can retry, do so with the callbacks armed */
+ if (!io_rw_should_retry(req)) {
+ kiocb->ki_flags &= ~IOCB_WAITQ;
+ return -EAGAIN;
+ }
+
/*
- * Now use our persistent iterator and state, if we aren't already.
- * We've restored and mapped the iter to match.
+ * Now retry read with the IOCB_WAITQ parts set in the iocb. If we
+ * get -EIOCBQUEUED, then we'll get a notification when the desired
+ * page gets unlocked. We can also get a partial read here, and if we
+ * do, then just retry at the new offset.
*/
- if (iter != &rw->iter) {
- iter = &rw->iter;
+ ret = io_iter_do_read(req, iter);
+ if (ret == -EIOCBQUEUED) {
+ ret = 0;
+ goto out_free;
+ } else if (ret > 0 && ret < io_size) {
+ /* we got some bytes, but not all. retry. */
+ kiocb->ki_flags &= ~IOCB_WAITQ;
+ goto retry;
+ }
++=======
++ /*
++ * Now use our persistent iterator and state, if we aren't already.
++ * We've restored and mapped the iter to match.
++ */
++ if (iter != &rw->iter) {
++ iter = &rw->iter;
+ state = &rw->iter_state;
+ }
+
+ do {
+ /*
+ * We end up here because of a partial read, either from
+ * above or inside this loop. Advance the iter by the bytes
+ * that were consumed.
+ */
+ iov_iter_advance(iter, ret);
+ if (!iov_iter_count(iter))
+ break;
+ rw->bytes_done += ret;
+ iov_iter_save_state(iter, state);
+
+ /* if we can retry, do so with the callbacks armed */
+ if (!io_rw_should_retry(req)) {
+ kiocb->ki_flags &= ~IOCB_WAITQ;
+ return -EAGAIN;
+ }
+
+ /*
+ * Now retry read with the IOCB_WAITQ parts set in the iocb. If
+ * we get -EIOCBQUEUED, then we'll get a notification when the
+ * desired page gets unlocked. We can also get a partial read
+ * here, and if we do, then just retry at the new offset.
+ */
+ ret = io_iter_do_read(req, iter);
+ if (ret == -EIOCBQUEUED)
+ return 0;
+ /* we got some bytes, but not all. retry. */
+ kiocb->ki_flags &= ~IOCB_WAITQ;
+ iov_iter_restore(iter, state);
+ } while (ret > 0);
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)
done:
- kiocb_done(kiocb, ret, issue_flags);
+ kiocb_done(kiocb, ret, cs);
+ ret = 0;
out_free:
- /* it's faster to check here then delegate to kfree */
+ /* it's reportedly faster than delegating the null check to kfree() */
if (iovec)
kfree(iovec);
- return 0;
+ return ret;
}

static int io_write_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
@@@ -3545,16 -3578,24 +3662,37 @@@ static int io_write(struct io_kiocb *re
struct kiocb *kiocb = &req->rw.kiocb;
struct iov_iter __iter, *iter = &__iter;
struct io_async_rw *rw = req->async_data;
++<<<<<<< HEAD
+ ssize_t ret, ret2, io_size;
++=======
+ bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK;
+ struct iov_iter_state __state, *state;
+ ssize_t ret, ret2;
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

- if (rw) {
+ if (rw)
iter = &rw->iter;
++<<<<<<< HEAD
+
+ ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
+ if (ret < 0)
+ return ret;
+ io_size = iov_iter_count(iter);
+ req->result = io_size;
++=======
+ state = &rw->iter_state;
+ iov_iter_restore(iter, state);
+ iovec = NULL;
+ } else {
+ ret = io_import_iovec(WRITE, req, &iovec, iter, !force_nonblock);
+ if (ret < 0)
+ return ret;
+ state = &__state;
+ iov_iter_save_state(iter, state);
+ }
+ req->result = iov_iter_count(iter);
+ ret2 = 0;
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)

/* Ensure we clear previously set non-block flag */
if (!force_nonblock)
@@@ -3610,14 -3656,14 +3748,20 @@@
if ((req->ctx->flags & IORING_SETUP_IOPOLL) && ret2 == -EAGAIN)
goto copy_iov;
done:
- kiocb_done(kiocb, ret2, issue_flags);
+ kiocb_done(kiocb, ret2, cs);
} else {
copy_iov:
++<<<<<<< HEAD
+ /* some cases will consume bytes even on error returns */
+ iov_iter_revert(iter, io_size - iov_iter_count(iter));
++=======
+ iov_iter_restore(iter, state);
+ if (ret2 > 0)
+ iov_iter_advance(iter, ret2);
++>>>>>>> cd65869512ab5 (io_uring: use iov_iter state save/restore helpers)
ret = io_setup_async_rw(req, iovec, inline_vecs, iter, false);
- return ret ?: -EAGAIN;
+ if (!ret)
+ return -EAGAIN;
}
out_free:
/* it's reportedly faster than delegating the null check to kfree() */

Lee Jones

unread,
Dec 15, 2021, 3:07:02 AM12/15/21
to Jens Axboe, Pavel Begunkov, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
Any movement on this chaps?

Not sure I am able to do this back-port without your help.

Pavel Begunkov

unread,
Dec 15, 2021, 6:16:11 AM12/15/21
to Lee Jones, Jens Axboe, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
Apologies, slipped from my attention, we'll backport it,
and thanks for the reminder


--
Pavel Begunkov

Lee Jones

unread,
Dec 16, 2021, 12:03:00 PM12/16/21
to Pavel Begunkov, Jens Axboe, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
Excellent. Thanks Pavel.

Lee Jones

unread,
Feb 22, 2022, 11:48:40 AM2/22/22
to Pavel Begunkov, Jens Axboe, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
Has this now been back-ported to Stable?

If so, would you be kind enough to provide the SHA1?

Thanks.

--
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services

Lee Jones

unread,
Mar 21, 2022, 6:52:52 AM3/21/22
to Pavel Begunkov, Jens Axboe, syzbot, io-u...@vger.kernel.org, linux-...@vger.kernel.org, syzkall...@googlegroups.com, Greg Kroah-Hartman
On Wed, 15 Dec 2021, Pavel Begunkov wrote:

Looks as though these are still missing from Stable.

Is this still your plan?

--
Lee Jones [李琼斯]
Principal Technical Lead - Developer Services
Reply all
Reply to author
Forward
0 new messages