@@ -694,17 +694,38 @@ static ssize_t hvs_stream_enqueue(struct vsock_sock *vsk, struct msghdr *msg,
694694static 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