Skip to content

Commit 60b3ca9

Browse files
committed
Merge fix/hv_sock_eio/6.18 into v6.18.26
* commit 'e256ef5ed9ce517323be79ad3268ec698533dca3': hv_sock: Return -EIO for malformed/short packets hv_sock: Report EOF instead of -EIO for FIN
2 parents 75cc5eb + e256ef5 commit 60b3ca9

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

net/vmw_vsock/hyperv_transport.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -694,17 +694,38 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg,
694694
static s64 hvs_stream_has_data(struct vsock_sock *vsk)
695695
{
696696
struct hvsock *hvs = vsk->trans;
697-
bool need_refill;
698697
s64 ret;
699698

700699
if (hvs->recv_data_len > 0)
701700
return hvs->recv_data_len;
702701

703702
switch (hvs_channel_readable_payload(hvs->chan)) {
704703
case 1:
705-
need_refill = !hvs->recv_desc;
706-
if (!need_refill)
707-
return -EIO;
704+
if (hvs->recv_desc) {
705+
/* Here hvs->recv_data_len is 0, so hvs->recv_desc must
706+
* be NULL unless it points to the 0-byte-payload FIN
707+
* packet or a malformed/short packet: see
708+
* hvs_update_recv_data().
709+
*
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.
723+
*/
724+
if (!(vsk->peer_shutdown & SEND_SHUTDOWN))
725+
return -EIO;
726+
727+
return 0;
728+
}
708729

709730
hvs->recv_desc = hv_pkt_iter_first(hvs->chan);
710731
if (!hvs->recv_desc)

0 commit comments

Comments
 (0)