hv_sock: Return -EIO for malformed/short packets
Subsystems (7)
Dexuan Cui
maintainerPATCH 1/1 hv_sock: Return -EIO for malformed/short packets
Commit f63152958994 fixes a regression, however it fails to report an error for malformed/short packets -- normally we should never see such packets, but let's report an error for them just in case.
---
Commit f63152958994 is currently only in net.git's master branch.
net/vmw_vsock/hyperv_transport.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
net/vmw_vsock/hyperv_transport.c +19 -10
@@ -704,18 +704,27 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)if (hvs->recv_desc) {/* Here hvs->recv_data_len is 0, so hvs->recv_desc must * be NULL unless it points to the 0-byte-payload FIN -* packet: see hvs_update_recv_data(). +* packet or a malformed/short packet: see +* hvs_update_recv_data(). * -* Here all the payload has been dequeued, but -* hvs_channel_readable_payload() still returns 1, -* because the VMBus ringbuffer's read_index is not -* updated for the FIN packet: hvs_stream_dequeue() -> -* hv_pkt_iter_next() updates the cached priv_read_index -* but has no opportunity to update the read_index in -* hv_pkt_iter_close() as hvs_stream_has_data() returns -* 0 for the FIN packet, so it won't get dequeued. +* If hvs->recv_desc points to the FIN packet, here all +* the payload has been dequeued and the peer_shutdown +* flag is set, but hvs_channel_readable_payload() still +* returns 1, because the VMBus ringbuffer's read_index +* is not updated for the FIN packet: +* hvs_stream_dequeue() -> hv_pkt_iter_next() updates +* the cached priv_read_index but has no opportunity to +* update the read_index in hv_pkt_iter_close() as +* hvs_stream_has_data() returns 0 for the FIN packet, +* so it won't get dequeued. +* +* In case hvs->recv_desc points to a malformed/short +* packet, return -EIO. */ -return 0 ; +if (hvs->vsk->peer_shutdown &SEND_SHUTDOWN ) +return 0 ; +else +return -EIO ; } hvs->recv_desc =hv_pkt_iter_first (hvs->chan);
Signature · 1 line
2.49.0
Stefano Garzarella
maintainerQuoted 40 lines · Dexuan Cui
Commit
f63152958994fixes a regression, however it fails to report an error for malformed/short packets -- normally we should never see such packets, but let's report an error for them just in case.Fixes f63152958994 ("hv_sock: Report EOF instead of -EIO for FIN")Signed-off-by Dexuan Cui <[email protected]>---
Commit
f63152958994is currently only in net.git's master branch.
net/vmw_vsock/hyperv_transport.c| 29 +++++++++++++++++++----------1 file changed, 19 insertions(+), 10 deletions(-)net/vmw_vsock/hyperv_transport.c +8
-9@@ -704,18 +704,27 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)if (hvs->recv_desc) {/* Here hvs->recv_data_len is 0, so hvs->recv_desc must * be NULL unless it points to the 0-byte-payload FIN -* packet: see hvs_update_recv_data(). +* packet or a malformed/short packet: see +* hvs_update_recv_data(). * -* Here all the payload has been dequeued, but -* hvs_channel_readable_payload() still returns 1, -* because the VMBus ringbuffer's read_index is not -* updated for the FIN packet: hvs_stream_dequeue() -> -* hv_pkt_iter_next() updates the cached priv_read_index -* but has no opportunity to update the read_index in -* hv_pkt_iter_close() as hvs_stream_has_data() returns -* 0 for the FIN packet, so it won't get dequeued. +* If hvs->recv_desc points to the FIN packet, here all +* the payload has been dequeued and the peer_shutdown +* flag is set, but hvs_channel_readable_payload() still +* returns 1, because the VMBus ringbuffer's read_index +* is not updated for the FIN packet: +* hvs_stream_dequeue() -> hv_pkt_iter_next() updates
net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 724
Quoted 10 lines
net/vmw_vsock/hyperv_transport.c +8
-1+* the cached priv_read_index but has no opportunity to +* update the read_index in hv_pkt_iter_close() as +* hvs_stream_has_data() returns 0 for the FIN packet, +* so it won't get dequeued. +* +* In case hvs->recv_desc points to a malformed/short +* packet, return -EIO. */ -return 0 ; +if (hvs->vsk->peer_shutdown &SEND_SHUTDOWN )
We can access vsk directly, I mean vsk->peer_shutdown.
net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 726
Quoted 2 lines
net/vmw_vsock/hyperv_transport.c +2
-0+return 0 ; + else
nit: we usually avoid the else if the other branch returns early, and maybe have the error returned first, so it's more clear when reading the comment on top. I mean something like this:
if (!(vsk->peer_shutdown & SEND_SHUTDOWN)) return -EIO; return 0;
BTW, not a strong opinion on that.
The rest, LGTM!
Thanks,
Stefano
Dexuan Cui
maintainerQuoted 19 lines
From: Stefano Garzarella <[email protected]>
Sent: Wednesday, April 22, 2026 2:40 AM
...net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 724
Quoted 1 line
net/vmw_vsock/hyperv_transport.c +1
-0+if (hvs->vsk->peer_shutdown &SEND_SHUTDOWN )We can access
vskdirectly, I meanvsk->peer_shutdown.net/vmw_vsock/hyperv_transport.c static s64 hvs_stream_has_data(struct vsock_sock *vsk) · line 726
Quoted 2 lines
net/vmw_vsock/hyperv_transport.c +2
-0+return 0 ; + elsenit: we usually avoid the
elseif the other branch returns early, and maybe have the error returned first, so it's more clear when reading the comment on top. I mean something like this:if (!(vsk->peer_shutdown & SEND_SHUTDOWN)) return -EIO; return 0;
Quoted 6 lines
BTW, not a strong opinion on that.
The rest, LGTM!
Thanks,
Stefano
Thank you Stefano! I'll post v2 later today.
Dexuan Cui
maintainerQuoted 4 lines
From: Dexuan Cui
Sent: Wednesday, April 22, 2026 11:15 AM
...
Thank you Stefano! I'll post v2 later today.
Posted v2:
https://lore.kernel.org/linux-hyperv/[email protected]/T/#u