From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ABC43ED10D for ; Tue, 14 Apr 2026 16:10:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776183036; cv=none; b=aba7bFRNxIVrGmAz7mwRKGkEd3vsSQXvXQmP2hJ4xmjbBQoOmoU8L3Ig+z2JwNxgdie+nBI0qb24nS6MLYAhO6wXGSoodlbrWe12KwA9Fx4IyneJkqphAIPoXOtHuysrYY2B+jrSdhikjArNOQULlqi96TdrsHNr0iegD2fsdg4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776183036; c=relaxed/simple; bh=jtcpbJn9RIdJlr0hVO963zpJX/82bBkk/hi4mZSImLE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X4Lzh5hqWHzUUoIeRWLbhpwy9ZU41QR6rEjUE1ZJ7wVD91DXDZhbupOPX9JTxte6Nh0+Y3C4W96gIxYXhozYpe9CB0KQd3AOVhFDTzkw1NdFbGoZkdk3kkLG/5X+Lsek/DX57YhkeQldPja/bzoHHO8LPMCVl2/Jywwo6e6fBr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WrxdQ8zd; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hJJ2T3f2; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WrxdQ8zd"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hJJ2T3f2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776183034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=WrxdQ8zdlZQkxM35azZWPSGWn1S2Q98Voe9tLapSHEPemlHPk4Tc66U5kkmYSZnsKUG2vU 4DSVOItTCpBp9loDVFhaa0OiEnAHrmMF8qmp2E6dm7yp7VDjFaID5Rg0hu3VbZ+40wTRGs Wm9EMAIa+mfJYFzdXIr3qGj4Am5Rt2U= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-498-hGPFzISnM02zNUeoqKB1Sw-1; Tue, 14 Apr 2026 12:10:30 -0400 X-MC-Unique: hGPFzISnM02zNUeoqKB1Sw-1 X-Mimecast-MFC-AGG-ID: hGPFzISnM02zNUeoqKB1Sw_1776183029 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d7d0947aeso961876f8f.3 for ; Tue, 14 Apr 2026 09:10:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776183029; x=1776787829; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=hJJ2T3f2Zam6T20AAqDBmgX8BWH53DXbJXAdHDKMrpfSERy0VwfHy4aRieMjFiDBOb VARpsmbc3fiaExISRehlrqqePwAyo5xDCzX2Eh1Yoof2DgxzYxXv2BkHl5hsbG5cGBO1 U3lc5FanUERYTTk5yfn7fmK+/xBYvaFx02jZ6A1poTVCtIds+I+lK0Vc3PMCxpBYB8kE V/Gppu8z/7+wbLVUPSHeVjU0UgFFH6BoR6jLUFXJjn7fYY39cAuzOp7LpAGWyYVRWAS6 52i3c30YqC/KYrollK3KsqopkbXtIl8XEvA3GwJ98DKIwOg4ZvcZi1SD2goMSu7ZeAeG ScHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776183029; x=1776787829; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=T4qpSiwLjabUf/q5/q3aDN7iNzObMaLZodRYuDBTSlw=; b=gERNpxZxwrwa9p6wMXisqPQDKLR6y8REDSj0mW6XiVAEs0jRxDiFPttPEtdS8xs3MG BWK+os4ToPBAmlU/pKiei+dec+Ayi9BPxjkVTb5SN1VQvDVUaZw2FVrK3PdNmV8r1qHV Jeo/t2/4GOTef64fwmf3IHGrLQNXn+pf/WBnh/X+pJ5CDuN2TP8xlayhX0aENWRAZ7UK fNhOdiVdu7u/JNpAOBX6//PWKhCOT75tFYWUk0vNyZ7LGSHuFmhwuPOdmi3KqZAvg4yP h9Wa0pyuKPtgy4pP98tQ4duhKsoTkIaXefDi7UFuTdHaD4dxgHBmghs2nZEO6o91q7Yq YXAQ== X-Forwarded-Encrypted: i=1; AFNElJ9aZkkkEhA61GAGDwZc2ryPnhGMGTcT0GC+f9J2nwXifWO2sJNlklKL+dE5jdXPpm76ccqAyBuhD1Aez64=@vger.kernel.org X-Gm-Message-State: AOJu0YzHB5TYK8StztYYRxN+RbmAt0gOw/TqBRle/MCrTrx/8hZsOaKZ aT+2aCR5OfWugLEAm6Daqa+Gl8mkvrHzVwyMVtTjmV99A3dzBOHdZW1/23lfiKCOrT0jurxLZ/X Mmd/J5NTS2JBbkLJKqDpEHec8gnD0C+dLASvqR1hsf6LMxxc+d8DiHObf7Wio8PIxuw== X-Gm-Gg: AeBDievd9Id5jDR5dMkcyWwvo4g0Gb+THHFcX/uUvSxaMwXvujg2gcJmh1/tE2mT2YK +KCFXzdu+2/XzGKqAsP0Owp+jwGR4/qk6/Lf+1LgUfBL13v499h5yPd2RuKbqRuUGmaTycUSWTW 5Xrh0pmadL4UPRdKdePHJuGHfysJfRqg85tQpvqdQ7sOV4ypJrYoGdRqzSwl6Zm7Kew5KIAy9B8 VANF/dxh9e8Cg5/UajUeOVAqXI1i1PznocYycN14w6EpjIzDpgT+Uzvm8SV05NkeR11yhg+te+h buaHq28ZiKJd6uEuLwSIG+7q8xR6EP6uhx9PgfV1+oOYjkVlCm0rM8vJUqFD5hTuT5eYp6FKbEK QYm8rKE32EDbROmq/jyRowk7NoIleIHeFFNqzb4ayh+7+4FFxO9PnYgyaCTvi X-Received: by 2002:a05:6000:1ac5:b0:43c:fa96:d939 with SMTP id ffacd0b85a97d-43d6429c737mr27847311f8f.22.1776183029366; Tue, 14 Apr 2026 09:10:29 -0700 (PDT) X-Received: by 2002:a05:6000:1ac5:b0:43c:fa96:d939 with SMTP id ffacd0b85a97d-43d6429c737mr27847250f8f.22.1776183028882; Tue, 14 Apr 2026 09:10:28 -0700 (PDT) Received: from lleonard-thinkpadx1carbongen13.rmtit.csb ([176.206.19.176]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d63dec090sm43035268f8f.12.2026.04.14.09.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 09:10:28 -0700 (PDT) From: Luigi Leonardi Date: Tue, 14 Apr 2026 18:10:23 +0200 Subject: [PATCH net v3 3/3] vsock/test: add MSG_PEEK after partial recv test Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260414-fix_peek-v3-3-e7daead49f83@redhat.com> References: <20260414-fix_peek-v3-0-e7daead49f83@redhat.com> In-Reply-To: <20260414-fix_peek-v3-0-e7daead49f83@redhat.com> To: Stefan Hajnoczi , Stefano Garzarella , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Arseniy Krasnov Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luigi Leonardi X-Mailer: b4 0.14.3 Add a test that verifies MSG_PEEK works correctly after a partial recv(). This is to test a bug that was present in the `virtio_transport_stream_do_peek()` when computing the number of bytes to copy: After a partial read, the peek function didn't take into consideration the number of bytes that were already read. So peeking the whole buffer would cause an out-of-bounds read, that resulted in a -EFAULT. This test does exactly this: do a partial recv on a buffer, then try to peek the whole buffer content. Signed-off-by: Luigi Leonardi --- tools/testing/vsock/vsock_test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index bdb0754965df..ab387a13f0ae 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -346,6 +346,38 @@ static void test_stream_msg_peek_server(const struct test_opts *opts) return test_msg_peek_server(opts, false); } +static void test_stream_peek_after_recv_server(const struct test_opts *opts) +{ + unsigned char buf_normal[MSG_PEEK_BUF_LEN]; + unsigned char buf_peek[MSG_PEEK_BUF_LEN]; + int fd; + + fd = vsock_stream_accept(VMADDR_CID_ANY, opts->peer_port, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_writeln("SRVREADY"); + + /* Partial recv to advance offset within the skb */ + recv_buf(fd, buf_normal, 1, 0, 1); + + /* Ask more bytes than available */ + recv_buf(fd, buf_peek, sizeof(buf_peek), MSG_PEEK, sizeof(buf_peek) - 1); + + /* Recv rest of the data */ + recv_buf(fd, buf_normal, sizeof(buf_normal) - 1, 0, sizeof(buf_normal) - 1); + + /* Compare full peek and normal read. */ + if (memcmp(buf_peek, buf_normal, sizeof(buf_peek) - 1)) { + fprintf(stderr, "Full peek data mismatch\n"); + exit(EXIT_FAILURE); + } + + close(fd); +} + #define SOCK_BUF_SIZE (2 * 1024 * 1024) #define SOCK_BUF_SIZE_SMALL (64 * 1024) #define MAX_MSG_PAGES 4 @@ -2509,6 +2541,11 @@ static struct test_case test_cases[] = { .run_client = test_stream_tx_credit_bounds_client, .run_server = test_stream_tx_credit_bounds_server, }, + { + .name = "SOCK_STREAM MSG_PEEK after partial recv", + .run_client = test_stream_msg_peek_client, + .run_server = test_stream_peek_after_recv_server, + }, {}, }; -- 2.53.0