net/core/datagram.c | 6 ++++++ net/core/skbuff.c | 1 - 2 files changed, 6 insertions(+), 1 deletion(-)
In zerocopy_fill_skb_from_iter(), if two copy operations are performed
and the first one succeeds while the second one fails, it returns a
failure but the count in iterator has already been decremented due to
the first successful copy. This ultimately affects the local variable
rest_len in virtio_transport_send_pkt_info(), causing the remaining
count in rest_len to be greater than the actual iterator count. As a
result, packet sending operations continue even when the iterator count
is zero, which further leads to skb->len being 0 and triggers the warning
reported by syzbot [1].
Therefore, if the zerocopy operation fails, we should revert the iterator
to its original state.
The iov_iter_revert() in skb_zerocopy_iter_stream() is no longer needed
and has been removed.
[1]
'send_pkt()' returns 0, but 4096 expected
WARNING: net/vmw_vsock/virtio_transport_common.c:430 at virtio_transport_send_pkt_info+0xd1e/0xef0 net/vmw_vsock/virtio_transport_common.c:428, CPU#1: syz.0.17/5986
Call Trace:
virtio_transport_stream_enqueue net/vmw_vsock/virtio_transport_common.c:1113 [inline]
virtio_transport_seqpacket_enqueue+0x143/0x1c0 net/vmw_vsock/virtio_transport_common.c:841
vsock_connectible_sendmsg+0xabf/0x1040 net/vmw_vsock/af_vsock.c:2158
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:746
Reported-by: syzbot+28e5f3d207b14bae122a@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=28e5f3d207b14bae122a
Tested-by: syzbot+28e5f3d207b14bae122a@syzkaller.appspotmail.com
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
V1 -> V2: Remove iov_iter_revert() in skb_zerocopy_iter_stream()
net/core/datagram.c | 6 ++++++
net/core/skbuff.c | 1 -
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/core/datagram.c b/net/core/datagram.c
index c285c6465923..da10465cd8a4 100644
--- a/net/core/datagram.c
+++ b/net/core/datagram.c
@@ -748,10 +748,13 @@ int __zerocopy_sg_from_iter(struct msghdr *msg, struct sock *sk,
size_t length,
struct net_devmem_dmabuf_binding *binding)
{
+ struct iov_iter_state state;
unsigned long orig_size = skb->truesize;
unsigned long truesize;
int ret;
+ iov_iter_save_state(from, &state);
+
if (msg && msg->msg_ubuf && msg->sg_from_iter)
ret = msg->sg_from_iter(skb, from, length);
else if (binding)
@@ -759,6 +762,9 @@ int __zerocopy_sg_from_iter(struct msghdr *msg, struct sock *sk,
else
ret = zerocopy_fill_skb_from_iter(skb, from, length);
+ if (ret)
+ iov_iter_restore(from, &state);
+
truesize = skb->truesize - orig_size;
if (sk && sk->sk_type == SOCK_STREAM) {
sk_wmem_queued_add(sk, truesize);
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 5a1d123e7ef7..77ed045c28ff 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -1908,7 +1908,6 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb,
struct sock *save_sk = skb->sk;
/* Streams do not free skb on error. Reset to prev state. */
- iov_iter_revert(&msg->msg_iter, skb->len - orig_len);
skb->sk = sk;
___pskb_trim(skb, orig_len);
skb->sk = save_sk;
--
2.43.0
On Fri, 28 Nov 2025 21:35:57 +0800 Edward Adam Davis wrote: > In zerocopy_fill_skb_from_iter(), if two copy operations are performed > and the first one succeeds while the second one fails, it returns a > failure but the count in iterator has already been decremented due to > the first successful copy. This ultimately affects the local variable > rest_len in virtio_transport_send_pkt_info(), causing the remaining > count in rest_len to be greater than the actual iterator count. As a > result, packet sending operations continue even when the iterator count > is zero, which further leads to skb->len being 0 and triggers the warning > reported by syzbot [1]. Please follow the subsystem guidelines for posting patches: https://www.kernel.org/doc/html/next/process/maintainer-netdev.html Your patch breaks zerocopy tests.
On Fri, 28 Nov 2025 09:39:46 -0800, Jakub Kicinski wrote: > > In zerocopy_fill_skb_from_iter(), if two copy operations are performed > > and the first one succeeds while the second one fails, it returns a > > failure but the count in iterator has already been decremented due to > > the first successful copy. This ultimately affects the local variable > > rest_len in virtio_transport_send_pkt_info(), causing the remaining > > count in rest_len to be greater than the actual iterator count. As a > > result, packet sending operations continue even when the iterator count > > is zero, which further leads to skb->len being 0 and triggers the warning > > reported by syzbot [1]. > > Please follow the subsystem guidelines for posting patches: > https://www.kernel.org/doc/html/next/process/maintainer-netdev.html > Your patch breaks zerocopy tests. I see that they all timed out. I'm not familiar with this test, how can I get more details about it?
On Mon, 1 Dec 2025 11:41:07 +0800 Edward Adam Davis wrote: > On Fri, 28 Nov 2025 09:39:46 -0800, Jakub Kicinski wrote: > > > In zerocopy_fill_skb_from_iter(), if two copy operations are performed > > > and the first one succeeds while the second one fails, it returns a > > > failure but the count in iterator has already been decremented due to > > > the first successful copy. This ultimately affects the local variable > > > rest_len in virtio_transport_send_pkt_info(), causing the remaining > > > count in rest_len to be greater than the actual iterator count. As a > > > result, packet sending operations continue even when the iterator count > > > is zero, which further leads to skb->len being 0 and triggers the warning > > > reported by syzbot [1]. > > > > Please follow the subsystem guidelines for posting patches: > > https://www.kernel.org/doc/html/next/process/maintainer-netdev.html > > Your patch breaks zerocopy tests. > I see that they all timed out. I'm not familiar with this test, how can > I get more details about it? IIRC its was the packetdrill tests: tools/testing/selftests/net/packetdrill/tcp_fastopen_server_basic-zero-payload.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_basic.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_batch.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_client.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_closed.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_epoll_edge.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_epoll_exclusive.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_epoll_oneshot.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_fastopen-client.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_fastopen-server.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_maxfrags.pkt tools/testing/selftests/net/packetdrill/tcp_zerocopy_small.pkt If you have the packetdrill command installed those _should_ be relatively easy to run via standard kselftest commands
© 2016 - 2025 Red Hat, Inc.