From: Stefano Garzarella <sgarzare@redhat.com>
To: weirongguang <weirongguang@kylinos.cn>
Cc: David Laight <david.laight.linux@gmail.com>,
Rongguang Wei <clementwei90@163.com>,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org,
virtualization@lists.linux.dev, netdev@vger.kernel.org
Subject: Re: [PATCH net v1] vsock: validate buffer min/max size in setsockopt
Date: Mon, 7 Sep 2026 10:03:38 +0200 [thread overview]
Message-ID: <ap5uSKRcfnjhXyC3@sgarzare-redhat> (raw)
In-Reply-To: <e16178ad-85c6-42da-931f-f0b2f8240828@kylinos.cn>
On Mon, Sep 07, 2026 at 03:45:54PM +0800, weirongguang wrote:
>
>
>On 2026/8/24 20:16, David Laight wrote:
>> On Mon, 24 Aug 2026 17:12:57 +0800
>> Rongguang Wei <clementwei90@163.com> wrote:
>>
>>> From: Rongguang Wei <weirongguang@kylinos.cn>
>>>
>>> SO_VM_SOCKETS_BUFFER_MIN_SIZE and SO_VM_SOCKETS_BUFFER_MAX_SIZE
>>> do not cross-validate against each other, allowing userspace to
>>> set buffer_min_size > buffer_max_size.
>>> When min > max, buffer_size is silently clamped to an incorrect
>>> value. For example, setting min=512KB then max=128 results in
>>> buffer_size=128 despite the user requesting much larger buffers
>>> via SO_VM_SOCKETS_BUFFER_SIZE.
>>>
>>> Reproduced with a test program:
>>> setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_MIN_SIZE,
>>> 512 * 1024, sizeof(int));
>>> setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_MAX_SIZE,
>>> 128, sizeof(int));
>>> // User asked for 1MB but got 128 bytes silently
>>> setsockopt(fd, AF_VSOCK, SO_VM_SOCKETS_BUFFER_SIZE,
>>> 1024 * 1024, sizeof(int));
The user set MAX_SIZE to 128, from commit d114bfdc9b76 ("vsock: fix
buffer size clamping order") this is the behavior we wanted, to ensure a
rational limit on memory usage.
>>>
>>> After that use getsockopt to get the buffer_size = 128 and
>>> buffer_min_size = 524288, buffer_max_size = 128.
>>> The buffer_min_size > buffer_max_size and the kernel accepted
>>> contradictory values without error.
>>>
>>> Add value check to fix this issue. Return -EINVAL to userspace
>>> when setting MAX_SIZE to a value smaller than the current MIN_SIZE
>>> or setting MIN_SIZE to a value larger than the current MAX_SIZE.
>>
>> That is going to break userspace that sets the minimum before the maximum
>> when the new minimum is larger than the old maximum.
>>
>> David
>>
>Hi, David.
>Thanks for pointing out the issue.
>
>Here is an alternative approach:
>instead of returning -EINVAL, automatically adjust the other value to preserve buffer_min_size <= buffer_max_size.
>The trade-off is that setting one parameter may implicitly adjust the other, but this is preferable to breaking existing applications.
>Does this approach look reasonable?
With this fix, how would that change the results of the test program you
included in the commit description?
Honestly, I don't understand what we're trying to fix.
Stefano
prev parent reply other threads:[~2026-09-07 8:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 9:12 [PATCH net v1] vsock: validate buffer min/max size in setsockopt Rongguang Wei
2026-08-24 12:16 ` David Laight
2026-08-25 2:17 ` weirongguang
2026-09-07 7:45 ` weirongguang
2026-09-07 8:03 ` 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=ap5uSKRcfnjhXyC3@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=clementwei90@163.com \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=weirongguang@kylinos.cn \
/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