Skip to content

Commit a998a7e

Browse files
nszeteigregkh
authored andcommitted
vsock: fix buffer size clamping order
commit d114bfd upstream. 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. Fixes: b9f2b0f ("vsock: handle buffer_size sockopts in the core") Suggested-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Norbert Szetei <norbert@doyensec.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://patch.msgid.link/180118C5-8BCF-4A63-A305-4EE53A34AB9C@doyensec.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Cc: Luigi Leonardi <leonardi@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 944d76f commit a998a7e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

net/vmw_vsock/af_vsock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,12 +1728,12 @@ static void vsock_update_buffer_size(struct vsock_sock *vsk,
17281728
const struct vsock_transport *transport,
17291729
u64 val)
17301730
{
1731-
if (val > vsk->buffer_max_size)
1732-
val = vsk->buffer_max_size;
1733-
17341731
if (val < vsk->buffer_min_size)
17351732
val = vsk->buffer_min_size;
17361733

1734+
if (val > vsk->buffer_max_size)
1735+
val = vsk->buffer_max_size;
1736+
17371737
if (val != vsk->buffer_size &&
17381738
transport && transport->notify_buffer_size)
17391739
transport->notify_buffer_size(vsk, &val);

0 commit comments

Comments
 (0)