Skip to content

Commit 3d1f207

Browse files
dcuikuba-moo
authored andcommitted
hv_sock: Return -EIO for malformed/short packets
Commit f631529 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. Fixes: f631529 ("hv_sock: Report EOF instead of -EIO for FIN") Cc: stable@vger.kernel.org Signed-off-by: Dexuan Cui <decui@microsoft.com> Acked-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://patch.msgid.link/20260423064811.1371749-1-decui@microsoft.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3bc06da commit 3d1f207

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

net/vmw_vsock/hyperv_transport.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -704,17 +704,26 @@ static s64 hvs_stream_has_data(struct vsock_sock *vsk)
704704
if (hvs->recv_desc) {
705705
/* Here hvs->recv_data_len is 0, so hvs->recv_desc must
706706
* be NULL unless it points to the 0-byte-payload FIN
707-
* packet: see hvs_update_recv_data().
707+
* packet or a malformed/short packet: see
708+
* hvs_update_recv_data().
708709
*
709-
* Here all the payload has been dequeued, but
710-
* hvs_channel_readable_payload() still returns 1,
711-
* because the VMBus ringbuffer's read_index is not
712-
* updated for the FIN packet: hvs_stream_dequeue() ->
713-
* hv_pkt_iter_next() updates the cached priv_read_index
714-
* but has no opportunity to update the read_index in
715-
* hv_pkt_iter_close() as hvs_stream_has_data() returns
716-
* 0 for the FIN packet, so it won't get dequeued.
710+
* If hvs->recv_desc points to the FIN packet, here all
711+
* the payload has been dequeued and the peer_shutdown
712+
* flag is set, but hvs_channel_readable_payload() still
713+
* returns 1, because the VMBus ringbuffer's read_index
714+
* is not updated for the FIN packet:
715+
* hvs_stream_dequeue() -> hv_pkt_iter_next() updates
716+
* the cached priv_read_index but has no opportunity to
717+
* update the read_index in hv_pkt_iter_close() as
718+
* hvs_stream_has_data() returns 0 for the FIN packet,
719+
* so it won't get dequeued.
720+
*
721+
* In case hvs->recv_desc points to a malformed/short
722+
* packet, return -EIO.
717723
*/
724+
if (!(vsk->peer_shutdown & SEND_SHUTDOWN))
725+
return -EIO;
726+
718727
return 0;
719728
}
720729

0 commit comments

Comments
 (0)