Netdev List
 help / color / mirror / Atom feed
* [PATCH net] vsock: avoid narrowing the receive queue length to int
@ 2026-12-04 16:35 Ryosuke Iwahashi
  2026-12-04 16:37 ` netdev-bot+sinfo
  2026-12-05 16:37 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Ryosuke Iwahashi @ 2026-12-04 16:35 UTC (permalink / raw)
  To: sgarzare
  Cc: bobbyeshleman, davem, edumazet, kuba, pabeni, willemb, horms,
	virtualization, netdev, arseny.krasnov

For virtio stream sockets, vsock_connectible_has_data() returns the
number of queued bytes as an s64. If the receive queue grows beyond
INT_MAX, vsock_connectible_wait_data() can narrow that count to a
negative int. Its callers then report an error even though data is
available.

Both callers only test whether the return value is positive. Return
one when data is available, preserving the zero and error cases.

Fixes: b3f7fd54881b ("af_vsock: separate wait data loop")
Signed-off-by: Ryosuke Iwahashi <ryosuke@ikotaslabs.com>
---
 net/vmw_vsock/af_vsock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 1d7d53542724..3bfc0bf9bd1d 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -2468,7 +2468,7 @@ static int vsock_connectible_wait_data(struct sock *sk,
 	if (data < 0)
 		return -ENOMEM;

-	return data;
+	return data > 0;
 }

 static int __vsock_stream_recvmsg(struct sock *sk, struct msghdr *msg,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] vsock: avoid narrowing the receive queue length to int
  2026-12-04 16:35 [PATCH net] vsock: avoid narrowing the receive queue length to int Ryosuke Iwahashi
@ 2026-12-04 16:37 ` netdev-bot+sinfo
  2026-12-04 16:39   ` Ryosuke Iwahashi
  2026-12-05 16:37 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04 16:37 UTC (permalink / raw)
  To: Ryosuke Iwahashi
  Cc: sgarzare, bobbyeshleman, davem, edumazet, kuba, pabeni, willemb,
	horms, virtualization, netdev, arseny.krasnov

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.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

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.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] vsock: avoid narrowing the receive queue length to int
  2026-12-04 16:37 ` netdev-bot+sinfo
@ 2026-12-04 16:39   ` Ryosuke Iwahashi
  0 siblings, 0 replies; 4+ messages in thread
From: Ryosuke Iwahashi @ 2026-12-04 16:39 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: sgarzare, bobbyeshleman, davem, edumazet, kuba, pabeni, willemb,
	horms, virtualization, netdev, arseny.krasnov

I found this during an LLM-assisted review of the VSOCK code for
kernelCTF. With 2,147,549,184 bytes queued, a one-byte MSG_PEEK
returned -2147418112 on the unpatched hardened-v1-7.2-rc5 build and 1
with the patch applied.

On Fri, 04 Dec 2026 16:37:22 +0000, netdev-bot+sinfo@kernel.org wrote:
> 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.
>
>  - Whether the issue was actually triggered, or is only theoretical
>    (e.g. found by LLM and not proven at runtime). If it was triggered
>    please include the symptoms, like the stack trace or kernel messages.
>
> 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.
>
> *IMPORTANT*: If you do repost (for other reasons) - please include
> the relevant info in the cover letter or commit messages.
> --
> The evaluation is done by an LLM so it may be wrong, if you think
> that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] vsock: avoid narrowing the receive queue length to int
  2026-12-04 16:35 [PATCH net] vsock: avoid narrowing the receive queue length to int Ryosuke Iwahashi
  2026-12-04 16:37 ` netdev-bot+sinfo
@ 2026-12-05 16:37 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 16:37 UTC (permalink / raw)
  To: ryosuke
  Cc: sgarzare, bobbyeshleman, davem, edumazet, kuba, pabeni, willemb,
	horms, virtualization, netdev, arseny.krasnov

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The patch is titled "vsock: avoid narrowing the receive queue
  length to int", but it fixes only vsock_connectible_wait_data().

--

vsock: avoid narrowing the receive queue length to int

For virtio stream sockets, vsock_connectible_has_data() returns the
queued byte count as an s64. vsock_connectible_wait_data() could narrow
that count to a negative int, and its recvmsg callers would then report
an error even though data was available. The patch makes
vsock_connectible_wait_data() return 1 when data is available.

> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 1d7d53542724f..3bfc0bf9bd1de 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
> @@ -2468,7 +2468,7 @@ static int vsock_connectible_wait_data(struct sock *sk,
>  	if (data < 0)
>  		return -ENOMEM;
>  
> -	return data;
> +	return data > 0;
>  }

[Severity: Medium]
The subject says "avoid narrowing the receive queue length to int", but
the SIOCINQ ioctl in the same file appears to narrow the same value. Should
that path be fixed as well?

In vsock_do_ioctl(), arg is an int __user *:

net/vmw_vsock/af_vsock.c:vsock_do_ioctl() {
    ...
	case SIOCINQ: {
		ssize_t n_bytes;
    ...
		n_bytes = vsock_stream_has_data(vsk);
		if (n_bytes < 0) {
			ret = n_bytes;
			break;
		}
		ret = put_user(n_bytes, arg);
		break;
	}
    ...
}

The n_bytes < 0 check only rejects error values. put_user() then stores
the ssize_t into an int.

With virtio, virtio_transport_notify_buffer_size() clamps buf_alloc only
to VIRTIO_VSOCK_MAX_BUF_SIZE (0xFFFFFFFF). An unprivileged user can raise
it with SO_VM_SOCKETS_BUFFER_MAX_SIZE and SO_VM_SOCKETS_BUFFER_SIZE, so
rx_bytes can go past INT_MAX. That is the same condition this patch
handles.

When it does, can ioctl(SIOCINQ/FIONREAD) give userspace a negative or
wrapped byte count?

vsock_stream_inq_hint() in the same file already clamps the same value:

	data = vsock_stream_has_data(vsk);
	if (data < 0)
		return -1;
	if (data > 0)
		return min_t(s64, data, INT_MAX);

Would a similar clamp fit the SIOCINQ case?

This patch does fix the recvmsg error described in the commit body. The
SIOCINQ code comes from an earlier commit, so a separate patch with its
own Fixes: tag may work better. Otherwise, could the commit message say
that only the vsock_connectible_wait_data() path is covered?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/CAN2NGG68dKx9L5sezmDhBNizJVAMGUPEnY0S78---NLRa-frUA%40mail.gmail.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-05 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 16:35 [PATCH net] vsock: avoid narrowing the receive queue length to int Ryosuke Iwahashi
2026-12-04 16:37 ` netdev-bot+sinfo
2026-12-04 16:39   ` Ryosuke Iwahashi
2026-12-05 16:37 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox