From: Stefano Garzarella <sgarzare@redhat.com>
To: Norbert Szetei <norbert@doyensec.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, John Villamil <john@doyensec.com>
Subject: Re: [BUG] vsock: refcount_t saturation and OOM via buffer size invariant inversion
Date: Wed, 8 Apr 2026 10:01:04 +0200 [thread overview]
Message-ID: <adYKERRYwzMIhZAl@sgarzare-redhat> (raw)
In-Reply-To: <C918071D-C036-4FD3-BD64-16C8E143479F@doyensec.com>
On Mon, Apr 06, 2026 at 08:36:16PM +0200, Norbert Szetei wrote:
>Hi Stefano,
>
>I like option 1 the most, as it is the most straightforward way to fix
>the issue. I am including the patch below. This fixes the clamping
>mismatch, but as you pointed out, it won't solve the root problem
>regarding the issue to arbitrarily set a maximum buffer value.
>
>Since VSOCK uses a unified buffer size rather than separating read and
>write buffers like the core stack, introducing a vsock-specific sysctl
>(e.g., net.vmw_vsock.buffer_max_size) seems the cleanest approach to me.
>I was also considering net.core.wmem_max/rmem_max, but mapping to those
>feels less natural.
I would prefer to stop to add custom sysctl/sockopt for vsock and start
to reuse the common ones, so if net.core.wmem_max/rmem_max can be used
in some way, maybe we can try that path first and fallback to a custom
one if we see it isn't doable.
>
>If you agree with the vsock-specific sysctl, or have a different
>suggestion, let me know and I will send a follow-up patch for that.
>Thanks.
>
>Best, Norbert
>
>-- >8 --
>From f5d160167c862c7f2ad6e6a1d4181d01997b683a Mon Sep 17 00:00:00 2001
>From: Norbert Szetei <norbert@doyensec.com>
>Date: Mon, 6 Apr 2026 19:52:52 +0200
>Subject: [PATCH] vsock: fix buffer size clamping order
>
>In vsock_update_buffer_size(), the buffer size was being clamped to the
>maximum first, and then to the minimum. If a user sets a minimum buffer
>size larger than the maximum, the minimum check overrides the maximum
>check, inverting the constraint.
>
>This breaks the intended socket memory boundaries by allowing the
>vsk->buffer_size to grow beyond the configured vsk->buffer_max_size.
>
>Fix this by checking the minimum first, and then the maximum. This
>ensures the buffer size never exceeds the buffer_max_size.
Please add a Fixes tag here, that should be:
Fixes: b9f2b0ffde0c ("vsock: handle buffer_size sockopts in the core")
For virtio transport it was pre-existing of that commit IIUC, but
doesn't metter since these changes will not apply without that commit,
so should be fine.
Please add also a Suggested-by.
>
>Signed-off-by: Norbert Szetei <norbert@doyensec.com>
>---
> net/vmw_vsock/af_vsock.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index d912ed2f012a..08f4dfb9782c 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -1951,12 +1951,12 @@ static void vsock_update_buffer_size(struct vsock_sock *vsk,
> const struct vsock_transport *transport,
> u64 val)
> {
>- if (val > vsk->buffer_max_size)
>- val = vsk->buffer_max_size;
>-
> if (val < vsk->buffer_min_size)
> val = vsk->buffer_min_size;
>
>+ if (val > vsk->buffer_max_size)
>+ val = vsk->buffer_max_size;
>+
The patch itself LGTM!
Thanks,
Stefano
prev parent reply other threads:[~2026-04-08 8:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 17:28 [BUG] vsock: refcount_t saturation and OOM via buffer size invariant inversion Norbert Szetei
2026-03-31 12:37 ` Stefano Garzarella
2026-04-06 18:41 ` Norbert Szetei
2026-04-06 20:04 ` [PATCH v2 net] vsock: fix buffer size clamping order Norbert Szetei
2026-04-07 0:37 ` Jakub Kicinski
2026-04-08 8:05 ` Stefano Garzarella
[not found] ` <C918071D-C036-4FD3-BD64-16C8E143479F@doyensec.com>
2026-04-08 8:01 ` Stefano Garzarella [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adYKERRYwzMIhZAl@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=john@doyensec.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=norbert@doyensec.com \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox