* [PATCH net v3 0/2] vsock/virtio: fix msg_iter desync on transmission failure @ 2026-06-22 22:27 Octavian Purdila 2026-06-22 22:27 ` [PATCH net v3 1/2] iov_iter: export iov_iter_restore Octavian Purdila 2026-06-22 22:27 ` [PATCH net v3 2/2] vsock/virtio: restore msg_iter on transmission failure Octavian Purdila 0 siblings, 2 replies; 5+ messages in thread From: Octavian Purdila @ 2026-06-22 22:27 UTC (permalink / raw) To: netdev Cc: Alexander Viro, Andrew Morton, Arseniy Krasnov, David S. Miller, Eric Dumazet, Eugenio Pérez, Jakub Kicinski, Jason Wang, kvm, linux-block, linux-fsdevel, linux-kernel, Michael S. Tsirkin, Paolo Abeni, Simon Horman, Stefan Hajnoczi, Stefano Garzarella, virtualization, Xuan Zhuo, Jens Axboe, Octavian Purdila This series fixes a msg_iter desync issue in the virtio vsock transport that can lead to warnings and eventual -ENOMEM under specific failure scenarios (e.g. partial GUP failure during MSG_ZEROCOPY transmission). To fix this, we need to restore the msg_iter state on transmission failure. However, since virtio vsock transport can be built as a module, we first need to export iov_iter_restore. Patch 1 exports iov_iter_restore. Patch 2 implements the msg_iter restoration in virtio vsock. Changes in v3: - Use EXPORT_SYMBOL_GPL (Jens) Changes in v2: - Use iov_iter_savestate()/iov_iter_restore() (Stefano) - Use a single restore point (Stefano) - Reverse xmas tree (Stefano) - Added comments in the code (Stefano) v2: https://lore.kernel.org/all/20260613000953.467473-1-tavip@google.com/ v1: https://lore.kernel.org/all/20260609004809.1285028-1-tavip@google.com/ Octavian Purdila (2): iov_iter: export iov_iter_restore vsock/virtio: restore msg_iter on transmission failure lib/iov_iter.c | 1 + net/vmw_vsock/virtio_transport_common.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) -- 2.55.0.rc0.799.gd6f94ed593-goog ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v3 1/2] iov_iter: export iov_iter_restore 2026-06-22 22:27 [PATCH net v3 0/2] vsock/virtio: fix msg_iter desync on transmission failure Octavian Purdila @ 2026-06-22 22:27 ` Octavian Purdila 2026-06-23 22:28 ` sashiko-bot 2026-06-25 10:43 ` Christian Brauner 2026-06-22 22:27 ` [PATCH net v3 2/2] vsock/virtio: restore msg_iter on transmission failure Octavian Purdila 1 sibling, 2 replies; 5+ messages in thread From: Octavian Purdila @ 2026-06-22 22:27 UTC (permalink / raw) To: netdev Cc: Alexander Viro, Andrew Morton, Arseniy Krasnov, David S. Miller, Eric Dumazet, Eugenio Pérez, Jakub Kicinski, Jason Wang, kvm, linux-block, linux-fsdevel, linux-kernel, Michael S. Tsirkin, Paolo Abeni, Simon Horman, Stefan Hajnoczi, Stefano Garzarella, virtualization, Xuan Zhuo, Jens Axboe, Octavian Purdila Export iov_iter_restore so that it can be used by modules. This is needed by the virtio vsock transport (which can be built as a module) to restore the msg_iter state when transmission fails. Acked-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Octavian Purdila <tavip@google.com> --- lib/iov_iter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 273919b161617..f5df63961fb24 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1491,6 +1491,7 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) i->__iov -= state->nr_segs - i->nr_segs; i->nr_segs = state->nr_segs; } +EXPORT_SYMBOL_GPL(iov_iter_restore); /* * Extract a list of contiguous pages from an ITER_FOLIOQ iterator. This does -- 2.55.0.rc0.799.gd6f94ed593-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v3 1/2] iov_iter: export iov_iter_restore 2026-06-22 22:27 ` [PATCH net v3 1/2] iov_iter: export iov_iter_restore Octavian Purdila @ 2026-06-23 22:28 ` sashiko-bot 2026-06-25 10:43 ` Christian Brauner 1 sibling, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-06-23 22:28 UTC (permalink / raw) To: Octavian Purdila; +Cc: kvm Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: Pre-existing issues: - [High] Exporting `iov_iter_restore` exposes a pre-existing logic error where restoring an `ITER_KVEC` iterator falsely triggers a `WARN_ON_ONCE`. -- commit b7b5854a768fd37654ad61552651a21df8d14c8f Author: Octavian Purdila <tavip@google.com> iov_iter: export iov_iter_restore Export iov_iter_restore so that it can be used by modules. This is needed by the virtio vsock transport to restore the msg_iter state when transmission fails. > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 273919b161617..f5df63961fb24 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1491,6 +1491,7 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) > i->__iov -= state->nr_segs - i->nr_segs; > i->nr_segs = state->nr_segs; > } > +EXPORT_SYMBOL_GPL(iov_iter_restore); [Severity: High] This isn't a bug introduced by this patch, but exporting this function to modules exposes a pre-existing issue when restoring an ITER_KVEC iterator. Looking at iov_iter_restore() in lib/iov_iter.c: void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) { if (WARN_ON_ONCE(!iov_iter_is_bvec(i) && !iter_is_iovec(i) && !iter_is_ubuf(i)) && !iov_iter_is_kvec(i)) return; Because !iov_iter_is_kvec(i) is placed outside the WARN_ON_ONCE() parentheses, restoring an ITER_KVEC evaluates to WARN_ON_ONCE(true) && false. This safely skips the early return, but still incorrectly triggers the warning, which can lead to a panic on systems with panic_on_warn enabled. Since ITER_KVEC is often used for kernel-originated network and storage data, does exporting this to modules like virtio vsock create a risk of falsely triggering warnings or a denial of service condition? -- Sashiko AI review · https://sashiko.dev/#/patchset/20260622222757.2130402-1-tavip@google.com?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v3 1/2] iov_iter: export iov_iter_restore 2026-06-22 22:27 ` [PATCH net v3 1/2] iov_iter: export iov_iter_restore Octavian Purdila 2026-06-23 22:28 ` sashiko-bot @ 2026-06-25 10:43 ` Christian Brauner 1 sibling, 0 replies; 5+ messages in thread From: Christian Brauner @ 2026-06-25 10:43 UTC (permalink / raw) To: Octavian Purdila Cc: netdev, Alexander Viro, Andrew Morton, Arseniy Krasnov, David S. Miller, Eric Dumazet, Eugenio Pérez, Jakub Kicinski, Jason Wang, kvm, linux-block, linux-fsdevel, linux-kernel, Michael S. Tsirkin, Paolo Abeni, Simon Horman, Stefan Hajnoczi, Stefano Garzarella, virtualization, Xuan Zhuo, Jens Axboe > Export iov_iter_restore so that it can be used by modules. > > This is needed by the virtio vsock transport (which can be built as a > module) to restore the msg_iter state when transmission fails. > > Acked-by: Stefano Garzarella <sgarzare@redhat.com> > Signed-off-by: Octavian Purdila <tavip@google.com> > > diff --git a/lib/iov_iter.c b/lib/iov_iter.c > index 273919b16161..f5df63961fb2 100644 > --- a/lib/iov_iter.c > +++ b/lib/iov_iter.c > @@ -1491,6 +1491,7 @@ void iov_iter_restore(struct iov_iter *i, struct iov_iter_state *state) > i->__iov -= state->nr_segs - i->nr_segs; > i->nr_segs = state->nr_segs; > } > +EXPORT_SYMBOL_GPL(iov_iter_restore); At least only export it for the module that really needs it. For example, see: EXPORT_SYMBOL_FOR_MODULES(__kernel_write, "autofs4"); -- Christian Brauner <brauner@kernel.org> ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v3 2/2] vsock/virtio: restore msg_iter on transmission failure 2026-06-22 22:27 [PATCH net v3 0/2] vsock/virtio: fix msg_iter desync on transmission failure Octavian Purdila 2026-06-22 22:27 ` [PATCH net v3 1/2] iov_iter: export iov_iter_restore Octavian Purdila @ 2026-06-22 22:27 ` Octavian Purdila 1 sibling, 0 replies; 5+ messages in thread From: Octavian Purdila @ 2026-06-22 22:27 UTC (permalink / raw) To: netdev Cc: Alexander Viro, Andrew Morton, Arseniy Krasnov, David S. Miller, Eric Dumazet, Eugenio Pérez, Jakub Kicinski, Jason Wang, kvm, linux-block, linux-fsdevel, linux-kernel, Michael S. Tsirkin, Paolo Abeni, Simon Horman, Stefan Hajnoczi, Stefano Garzarella, virtualization, Xuan Zhuo, Jens Axboe, Octavian Purdila, syzbot+28e5f3d207b14bae122a When transmission fails in virtio_transport_send_pkt_info, the msg_iter might have been partially advanced. If we don't restore it, the next attempt to send data will use an incorrect iterator state, leading to desync and warnings like "send_pkt() returns 0, but X expected". Specifically, this can happen in the following scenario, triggered by the syzkaller repro: 1. A write-only VMA (PROT_WRITE only) is partially populated by a prior TUN write that failed with -EIO but still faulted in some pages). 2. A vsock sendmmsg call with MSG_ZEROCOPY requests transmission of a buffer from this VMA. 3. The first packet (64KB) is sent successfully because the pages are populated. 4. The second packet allocation fails because GUP fast pins the first page but GUP slow fails on the next unpopulated page due to PROT_WRITE-only permissions. 5. The iterator is advanced by the partially successful GUP (68KB total advanced: 64KB from first packet + 4KB from second), but the send loop breaks and only reports 64KB sent. This creates a 4KB desync. 6. The next retry starts with a non-zero iov_offset, disabling zerocopy and falling back to copy mode. 7. In copy mode, the transmission succeeds for the next packets but exhausts the iterator early because of the desync. 8. The final retry sees an empty iterator but zerocopy is re-enabled (offset resets). It attempts to send the remaining bytes with zerocopy but pins 0 pages, creating an empty packet. 9. The transport sends the empty packet, triggering the warning because the returned bytes (header only) do not match the expected payload size. 10. The loop continues to spin, allocating ubuf_info each time, eventually exhausting sysctl_optmem_max and returning -ENOMEM to userspace. Restore msg_iter to its original state before the packet allocation and transmission attempt if they fail. Fixes: e0718bd82e27 ("vsock: enable setting SO_ZEROCOPY") Reported-by: syzbot+28e5f3d207b14bae122a@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=28e5f3d207b14bae122a Assisted-by: gemini:gemini-3.1-pro Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Octavian Purdila <tavip@google.com> --- net/vmw_vsock/virtio_transport_common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 09475007165b3..35fd4094d771d 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -295,6 +295,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, u32 max_skb_len = VIRTIO_VSOCK_MAX_PKT_BUF_SIZE; u32 src_cid, src_port, dst_cid, dst_port; const struct virtio_transport *t_ops; + struct iov_iter_state msg_iter_state; struct virtio_vsock_sock *vvs; struct ubuf_info *uarg = NULL; u32 pkt_len = info->pkt_len; @@ -368,8 +369,17 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, struct sk_buff *skb; size_t skb_len; + /* Save iterator state in case allocation or transmission fails + * so we can restore it and retry. + */ + if (info->msg) + iov_iter_save_state(&info->msg->msg_iter, &msg_iter_state); + skb_len = min(max_skb_len, rest_len); + /* Note: virtio_transport_alloc_skb() can advance info->msg->msg_iter + * even if it fails (e.g. partial GUP success). + */ skb = virtio_transport_alloc_skb(info, skb_len, can_zcopy, uarg, src_cid, src_port, @@ -399,6 +409,9 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk, break; } while (rest_len); + if (info->msg && ret < 0) + iov_iter_restore(&info->msg->msg_iter, &msg_iter_state); + virtio_transport_put_credit(vvs, rest_len); /* msg_zerocopy_realloc() initializes the ubuf_info refcnt to 1. -- 2.55.0.rc0.799.gd6f94ed593-goog ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-06-25 10:43 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-06-22 22:27 [PATCH net v3 0/2] vsock/virtio: fix msg_iter desync on transmission failure Octavian Purdila 2026-06-22 22:27 ` [PATCH net v3 1/2] iov_iter: export iov_iter_restore Octavian Purdila 2026-06-23 22:28 ` sashiko-bot 2026-06-25 10:43 ` Christian Brauner 2026-06-22 22:27 ` [PATCH net v3 2/2] vsock/virtio: restore msg_iter on transmission failure Octavian Purdila
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.