From nobody Sun Jun 21 06:31:01 2026 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC45539A05E for ; Mon, 6 Apr 2026 20:04:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775505887; cv=none; b=NBglTzP/UW5+utvRcvXHlE/D+FNtFQ3sJC3IUEGisHZLytVLNi+W8qXGlCT9ZeLyUUENFNW8iMwU1qnuTjM0zGqG+kMp6pMgxG+JN0TXgaLBh4Rxup5jBqe4el16JJZy5B8J4q62lEVw8+8spzjd7Cjt1FiHOccQe4GkryawnPA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775505887; c=relaxed/simple; bh=BVBjRU8R+cBS4ShnNkWw2geTEpx0uy5I1ASSk5q7N0Q=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=tIoCDlkQj+6vWNpq6CZmTm9p3ICQNZvQ9tpGLLp3iif4CIedZoBZKzmXoUAGUPh/O3Pzih/hf9hWq4XADz/6ckRUxiPkfJlsWe5Mobdh6ieZaaTORZTJepxNJjn6DbxcgLB1IzG4yY+69T8jr/9wZfUKGFizOe832+zsatyC1U8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=doyensec.com; spf=pass smtp.mailfrom=doyensec.com; dkim=pass (2048-bit key) header.d=doyensec.com header.i=@doyensec.com header.b=Rm5zPFW1; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=doyensec.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=doyensec.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=doyensec.com header.i=@doyensec.com header.b="Rm5zPFW1" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-6634bb959a2so5724630a12.1 for ; Mon, 06 Apr 2026 13:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=doyensec.com; s=google; t=1775505879; x=1776110679; darn=vger.kernel.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=B9PRdhuyqvsBKCnvXw6TdIqodY8RtCaLeWXlPrboPE4=; b=Rm5zPFW1N3wjm+LIHnpf1YFOgtdJ79iHQko0Oi7x4raXhqsj42qzC+I9ddYTVYxOGe sIgUlBYBFuwQkKTtCELYXU/T4byWoVqCibYRQEUeXQrjsPMAlyrrUQaC9G0GFt6rtG3Q 5cxGBrFwRE8xo7DeZ/8Kp+tqxpu6i7h+xQokVzsDKdhsBI0oyXMQUxwdfJ0WniPnFDgX ZByArLtn4ofTCx8OMQ0bzvNRq5+p10lB74JQx5+r3plM59hBFy/9hZBjMqMYMfWRGbm/ 4I34FYuyxBFftPHZFiBad8O7kCNicO3djN4vteKg97wAlc4jgLpVvQjaZpqGETxlln1M 3u/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775505879; x=1776110679; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=B9PRdhuyqvsBKCnvXw6TdIqodY8RtCaLeWXlPrboPE4=; b=kcGcgiTK190SjXfkf5eViGrudUKHqsxMiUCUbuuk2NkrK3n3Zm5SkJ+Jsm+gEUYgRc 45Wz+7AjGI8380vghLBurXqQKfyunSW+TsWaWs5ZiaNzk/a3zQjTJ2LNCo2dSaLLu9H8 E57L8t3tEcGBGkltOpaTvEYO6ecXBGh6YvkBe1c0pRpiWvZIV2TH7ydYGSeIOdU1EThi z7DeGLcT7dh1t9z7igxufsw2mzOEBPRQHiaLKGbc+2qHcCNYhg2LzVcNSS+syBdEGC4D S1OdW8aBC1A+/hOaEC/aGdYdeLHynfeNiKxMUpLCVopLeIjRdBgm+m6+RkFjyq83szII mAag== X-Forwarded-Encrypted: i=1; AJvYcCV0hvk7aPC/qfTv9XKXmm2yPsbzmqIPXzbW3kRxVXiJLtGsZOMobAmPQuIJeosbUbNnE0iQbJnbYLFjiH8=@vger.kernel.org X-Gm-Message-State: AOJu0YzHghVdap5o+vJxLLzfLsgANM/iRr7wtkFLh/oVzwdw+CK3jBpF w4XY7r4H7eKKUoVCko1ClExgzOKxisrPAqwxevgjr1QN67bnGNtrD1ZXN7zWpnQlB84= X-Gm-Gg: AeBDiesdUw2BBfOK/ErEd7/4tcIwzBUCMZYsuqBW8kzfGWW+JKyIPCviG29S0OKT1Xl Pf9guePDZ6XtQ9NpPLX5/Q9vWzZi4vzilsaR3RNcPat+c7crDO8mrldiTLd8Kqhybrba9cg+Uw7 DIm2A4I4mw9R3YwfPw105UMuoTRJMnOOSCdaGRZQ56zOih1vGuCpZRCcfiqAugjCkM/mGb2czFa IeMsLEinZSKEURHIOycIqJE7Bnr/bOYpab2ctD4ZNFjJf0P/cVtRthF/W67FhFYY3GHbpG0Ebry IWnkgQAoKVCPbj6iHD5XShUZpp+h4NN0qC9fTNbghzWJSNCN3ypSfZBUpjaC3ggg3MKU3dAoyCo d3DudogQKW0Q/GIP7BFv3yAVIASKfc4UlGsgbdAuPmFbwcDpaQKKOJakHPOy2xmCBLpiZ0u+Bt9 WyD5ApKxg/4OXkeVm3J5K0GTVqFtL5ue9lPY7Eu3cFS7/H3/EMm6nZem+CQjj+3/vdBYtLqtLvS t9P X-Received: by 2002:a17:907:bac1:b0:b97:1d24:bfd1 with SMTP id a640c23a62f3a-b9c672fd90fmr578171566b.13.1775505879255; Mon, 06 Apr 2026 13:04:39 -0700 (PDT) Received: from smtpclient.apple (83.10.27.44.ipv4.supernova.orange.pl. [83.10.27.44]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9c3c9721absm497776766b.6.2026.04.06.13.04.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2026 13:04:38 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.4\)) Subject: [PATCH v2 net] vsock: fix buffer size clamping order From: Norbert Szetei In-Reply-To: <102981F1-2CAE-481F-8FAE-4F3085E25E89@doyensec.com> Date: Mon, 6 Apr 2026 22:04:26 +0200 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 Content-Transfer-Encoding: quoted-printable Message-Id: <69317E49-40AA-4985-8A4E-447C58665A68@doyensec.com> References: <523A8D3C-F4D9-43DD-A3A6-01C9EC335656@doyensec.com> <102981F1-2CAE-481F-8FAE-4F3085E25E89@doyensec.com> To: Stefano Garzarella X-Mailer: Apple Mail (2.3826.700.81.1.4) Content-Type: text/plain; charset="utf-8" Hi, v2: fix indentation/whitespace issues in the previous patch. -- >8 -- From f5d160167c862c7f2ad6e6a1d4181d01997b683a Mon Sep 17 00:00:00 2001 From: Norbert Szetei 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. Signed-off-by: Norbert Szetei --- 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_s= ock *vsk, const struct vsock_transport *transport, u64 val) { - if (val > vsk->buffer_max_size) - val =3D vsk->buffer_max_size; - if (val < vsk->buffer_min_size) val =3D vsk->buffer_min_size; =20 + if (val > vsk->buffer_max_size) + val =3D vsk->buffer_max_size; + if (val !=3D vsk->buffer_size && transport && transport->notify_buffer_size) transport->notify_buffer_size(vsk, &val); --=20 2.53.0 > On Apr 6, 2026, at 20:41, Norbert Szetei wrote: >=20 > Hi Stefano, >=20 > 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. >=20 > 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. >=20 > 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. >=20 > Best, Norbert >=20 > -- >8 -- > From f5d160167c862c7f2ad6e6a1d4181d01997b683a Mon Sep 17 00:00:00 2001 > From: Norbert Szetei > Date: Mon, 6 Apr 2026 19:52:52 +0200 > Subject: [PATCH] vsock: fix buffer size clamping order >=20 > 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. >=20 > This breaks the intended socket memory boundaries by allowing the > vsk->buffer_size to grow beyond the configured vsk->buffer_max_size. >=20 > Fix this by checking the minimum first, and then the maximum. This > ensures the buffer size never exceeds the buffer_max_size. >=20 > Signed-off-by: Norbert Szetei > --- > net/vmw_vsock/af_vsock.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) >=20 > 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 =3D vsk->buffer_max_size; > - > if (val < vsk->buffer_min_size) > val =3D vsk->buffer_min_size; > + if (val > vsk->buffer_max_size) > + val =3D vsk->buffer_max_size; > + > if (val !=3D vsk->buffer_size && > transport && transport->notify_buffer_size) > transport->notify_buffer_size(vsk, &val); > --=20 > 2.53.0 >=20 >> On Mar 31, 2026, at 14:37, Stefano Garzarella wrot= e: >>=20 >> On Tue, Mar 24, 2026 at 06:28:12PM +0100, Norbert Szetei wrote: >>> Hello, >>>=20 >>> we have discovered a bug in AF_VSOCK where an unprivileged user can byp= ass socket >>> memory constraints. This leads to refcount_t saturation and OOM. While >>> refcount_t prevents a true UAF by saturating, the resulting state trigg= ers >>> kernel warnings and kernel panic, depending on the setup. >>>=20 >>> In vsock_connectible_setsockopt(), the SO_VM_SOCKETS_BUFFER_MIN_SIZE and >>> SO_VM_SOCKETS_BUFFER_MAX_SIZE options are used to update the buffer's m= inimum >>> and maximum values independently. >>>=20 >>> The vsock_update_buffer_size() function clamps the buffer size to the m= aximum >>> first, then the minimum: >>>=20 >>> // https://github.com/torvalds/linux/blob/c369299895a591d96745d6492d488= 8259b004a9e/net/vmw_vsock/af_vsock.c#L1950 >>> if (val > vsk->buffer_max_size) >>> val =3D vsk->buffer_max_size; >>>=20 >>> if (val < vsk->buffer_min_size) >>> val =3D vsk->buffer_min_size; >>>=20 >>> vsk->buffer_size =3D val; >>>=20 >>> By setting buffer_min_size to a large value, the second clamp overrides= the >>> first, forcing vsk->buffer_size to exceed the intended maximum. The tra= nsport >>> layer then uses this value, allowing unbounded SKB allocation that satu= rates the >>> 32-bit sk_wmem_alloc refcount. >>>=20 >>> The fix should ensure that SO_VM_SOCKETS_BUFFER_MIN_SIZE cannot be used= to set a >>> value higher than the current buffer_max_size. Conversely, >>> SO_VM_SOCKETS_BUFFER_MAX_SIZE should not be allowed to be set lower tha= n the >>> current buffer_min_size. >>=20 >> Okay, but that wouldn't change much. As long as the user sets the maximu= m to match the minimum you set in the POC, it behaves exactly the same way,= right? >>=20 >> Maybe we should add a sysctl to set a global upper bound, but this is an= other problem, I agree that we should improve the kernel behavior around mi= n/max. I see 3 options: >>=20 >> 1. Just invert the checks, fist check for min, then for max. >>=20 >> 2. Simply adjust the min and max values so that they make sense. For exa= mple, if the minimum value being set is greater than the maximum, the kerne= l could adjust the maximum to the same value. However, this would not chang= e the behavior of your POC. >>=20 >> 3. Force the minimum to be less than or equal to the maximum. This, howe= ver, would require a certain order when setting the minimum and maximum, es= pecially relative to the default. For example, if you increase the minimum = beyond the default maximum, you must adjust the maximum first; conversely, = if you want to set the maximum below the default minimum, you must adjust t= he minimum first. >>=20 >> I'm more into 1 or 2. 3 IMO is too much. >>=20 >> Do you want to send a patch? >>=20 >> Thanks, >> Stefano >=20 >=20