vsock: account only unread bytes in read_skb()
Subsystems (7)
PATCH 1/1 vsock: account only unread bytes in read_skb()
After a partial stream receive, rx_bytes tracks the unread suffix while buf_used and peer credit still cover the whole packet. virtio_transport_read_skb() dequeues that packet but passes pkt_len for both counters, underflowing rx_bytes.
On a connected CID_LOCAL stream with an SK_SKB verdict, a 40-byte read from a 100-byte packet made SIOCINQ report -40, an empty recv return ELOOP, and poll report the empty socket readable. After verdict detach, receiving 40 bytes wrapped the counter to zero and hid those queued bytes until one more byte arrived. The fixed run kept the counter balanced and exposed all queued data immediately.
Subtract only skb->len minus the VSOCK offset from rx_bytes. Retain the full packet length for buf_used and peer credit.
--- net/vmw_vsock/virtio_transport_common.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/vmw_vsock/virtio_transport_common.c +3 -1
@@ -1927,6 +1927,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_actostruct sock *sk =sk_vsock (vsk);struct virtio_vsock_hdr *hdr;struct sk_buff *skb; +u32 bytes_read;u32 pkt_len;int off =0 ;int err;
@@ -1946,7 +1947,8 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto vvs->msg_count--; pkt_len =le32_to_cpu (hdr->len); -virtio_transport_dec_rx_pkt (vvs, pkt_len, pkt_len); + bytes_read = skb->len -VIRTIO_VSOCK_SKB_CB (skb)->offset; +virtio_transport_dec_rx_pkt (vvs, bytes_read, pkt_len);spin_unlock_bh (&vvs->rx_lock);virtio_transport_send_credit_update (vsk);
base-commit: e23a64eb244356ee47c0620f0722d51bd88db522
Signature · 1 line
2.55.0
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 12 lines
After a partial stream receive,
rx_bytestracks the unread suffix whilebuf_usedand peer credit still cover the whole packet.virtio_transport_read_skb()dequeues that packet but passespkt_lenfor both counters, underflowingrx_bytes.On a connected
CID_LOCALstream with anSK_SKBverdict, a 40-byte read from a 100-byte packet made SIOCINQ report -40, an empty recv return ELOOP, and poll report the empty socket readable. After verdict detach, receiving 40 bytes wrapped the counter to zero and hid those queued bytes until one more byte arrived. The fixed run kept the counter balanced and exposed all queued data immediately.
Quoted 7 lines
Subtract only
skb->lenminus the VSOCK offset fromrx_bytes. Retain the full packet length forbuf_usedand peer credit.Fixes 45ca7e9f0730 ("vsock/virtio: fix `rx_bytes` accounting for stream sockets")Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Hi,
what about using vsock/virtio instead of vsock? We are changing just the virtio parts of vsock.
Quoted 36 lines · Daehyeon Ko
After a partial stream receive,
rx_bytestracks the unread suffix whilebuf_usedand peer credit still cover the whole packet.virtio_transport_read_skb()dequeues that packet but passespkt_lenfor both counters, underflowingrx_bytes.On a connected
CID_LOCALstream with anSK_SKBverdict, a 40-byte read from a 100-byte packet made SIOCINQ report -40, an empty recv return ELOOP, and poll report the empty socket readable. After verdict detach, receiving 40 bytes wrapped the counter to zero and hid those queued bytes until one more byte arrived. The fixed run kept the counter balanced and exposed all queued data immediately.Subtract only
skb->lenminus the VSOCK offset fromrx_bytes. Retain the full packet length forbuf_usedand peer credit.Fixes 45ca7e9f0730 ("vsock/virtio: fix `rx_bytes` accounting for stream sockets")Assisted-by LLMSigned-off-by Daehyeon Ko <[email protected]>---
net/vmw_vsock/virtio_transport_common.c| 4 +++-1 file changed, 3 insertions(+), 1 deletion(-)net/vmw_vsock/virtio_transport_common.c +1
-0@@ -1927,6 +1927,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_actostruct sock *sk =sk_vsock (vsk);struct virtio_vsock_hdr *hdr;struct sk_buff *skb; +u32 bytes_read;u32 pkt_len;int off =0 ;int err;
net/vmw_vsock/virtio_transport_common.c int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto · line 1949
Quoted 4 lines
net/vmw_vsock/virtio_transport_common.c +0
-1@@ -1946,7 +1947,8 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto vvs->msg_count--; pkt_len =le32_to_cpu (hdr->len); -virtio_transport_dec_rx_pkt (vvs, pkt_len, pkt_len);
maybe it's worth adding a comment? not a strong opinion.
Quoted 10 lines
net/vmw_vsock/virtio_transport_common.c +2
-0+ bytes_read = skb->len -VIRTIO_VSOCK_SKB_CB (skb)->offset; +virtio_transport_dec_rx_pkt (vvs, bytes_read, pkt_len);spin_unlock_bh (&vvs->rx_lock);virtio_transport_send_credit_update (vsk);base-commit:
e23a64eb244356ee47c0620f0722d51bd88db522Signature · 1 line
2.55.0
code LGTM!
Thanks,
Luigi
Thanks. I found this during an LLM-assisted manual source audit of VSOCK receive accounting while re-evaluating virtio_transport_read_skb() after CVE-2024-50169. I then confirmed it on vulnerable and fixed kernels using a connected CID_LOCAL stream and a real SK_SKB/SOCKMAP verdict path.
Thanks,
Daehyeon