From patchwork Fri Mar 3 22:00:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13159601 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66FEFC61DA3 for ; Sat, 4 Mar 2023 00:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbjCDADe (ORCPT ); Fri, 3 Mar 2023 19:03:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbjCDAD1 (ORCPT ); Fri, 3 Mar 2023 19:03:27 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6AFCEB5B; Fri, 3 Mar 2023 16:03:24 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 9AF045FD07; Sat, 4 Mar 2023 01:03:03 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1677880983; bh=frCKZPP6m8x+qRpvRirAieIO1yh96VlFuo704GZeY9s=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=cGtGBFy5msWICxW4y6khtiH1JVQNSZwvxRsX+IqOM68bj+KdDPgGWyyeDe9IcIz2f 8qhLUdqp6eqfynBXq+2ILY9587Jr53gCbo7pvaAiQfQ50EL3WwZqZ5dkQMQw6lEkQB XGq60vcicDf093jolZfRbKacBMLcjAh7gL3GxVU+tovlAtB+gAExF7B2ORTcifxrDs S3JqI4uendMn9j3GuGXG/KVsf2rwWHviYV7EORGk8e2fVXUX9H882J0DnV6MDIVl0H 2sgBYGvqEeIA00kkCyNW7nQN9TGEMUMV+iwE22/rPU3YP3MzNjYzoGPyLm99E27SOS 03G3HBX9T2QGA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 4 Mar 2023 01:03:03 +0300 (MSK) Message-ID: <482863e2-217d-364f-2710-c1cbfd5db4e9@sberdevices.ru> Date: Sat, 4 Mar 2023 01:00:13 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 1/3] test/vsock: SOCK_SEQPACKET 'rx_bytes'/'fwd_cnt' bug reproducer X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/03 17:09:00 #20912733 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC virtio/vsock: replace virtio_vsock_pkt with sk_buff Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 4 +++ tools/testing/vsock/vsock_test.c | 44 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index a1581c77cf84..77bb1cad8471 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -256,6 +256,10 @@ static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs, int len; len = skb_headroom(skb) - sizeof(struct virtio_vsock_hdr) - skb->len; + + if (len < 0) + pr_emerg("Negative len %i\n", len); + vvs->rx_bytes -= len; vvs->fwd_cnt += len; } diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 67e9f9df3a8c..2651de2aedc9 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -860,7 +860,51 @@ static void test_stream_poll_rcvlowat_client(const struct test_opts *opts) close(fd); } +static void test_seqpacket_rxbytes_client(const struct test_opts *opts) +{ + unsigned char data[256]; + int fd; + + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + send(fd, data, sizeof(data), 0); + + control_writeln("CLISENT"); + + close(fd); + + exit(0); +} + +static void test_seqpacket_rxbytes_server(const struct test_opts *opts) +{ + unsigned char data[8]; + int fd; + + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + control_expectln("CLISENT"); + read(fd, data, sizeof(data)); + + close(fd); + + exit(0); +} + static struct test_case test_cases[] = { + { + .name = "SOCK_SEQPACKET negative 'rx_bytes'", + .run_client = test_seqpacket_rxbytes_client, + .run_server = test_seqpacket_rxbytes_server, + }, { .name = "SOCK_STREAM connection reset", .run_client = test_stream_connection_reset, From patchwork Fri Mar 3 22:01:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13159599 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B507EC678D5 for ; Sat, 4 Mar 2023 00:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229861AbjCDAD3 (ORCPT ); Fri, 3 Mar 2023 19:03:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjCDAD1 (ORCPT ); Fri, 3 Mar 2023 19:03:27 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6B95EC71; Fri, 3 Mar 2023 16:03:24 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id C4DB85FD19; Sat, 4 Mar 2023 01:04:24 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1677881064; bh=Icgy8iDTd8OsLA0qcC7gyzpquMde/dsgpaxAtiinzyo=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=bBOOyNLjfdEd0XdCMzLE+adQMP36CslJqEklfr63E9CrBCwE6EPFLDpSGUbxhL+uE 9+PiLk1FV2GDtqjPqDFZhIg9QtlwRlt5ffO5bDFsFU4HM8OlZNEtc/J84NUP7l+Pc4 SpnxpNF9BMGvHtU0nMzUNVS7IhmokX9C192mwi5QnMRRtVn9V28NNMDo/WntG8EZSn 5vFsK6X30TEm+YiDW1Glcdu5N2Rmxg4eKiaiFr0At5F0G1M+khWOoKcVGq6uAJTq40 9UPgdHM50t3WUIWQhZpBxdypTIfTymbanNevw8AHi1nlqx5eFE8f+VEBuIicdNQYyr diI7J7Ow17ieA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 4 Mar 2023 01:04:24 +0300 (MSK) Message-ID: <0ec95196-7445-b183-022d-fd3e1e1a7529@sberdevices.ru> Date: Sat, 4 Mar 2023 01:01:34 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 2/3] virtio/vsock: fix 'rx_bytes'/'fwd_cnt' calculation X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/03 17:09:00 #20912733 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Substraction of 'skb->len' is redundant here: 'skb_headroom()' is delta between 'data' and 'head' pointers, e.g. it is number of bytes returned to user (of course accounting size of header). 'skb->len' is number of bytes rest in buffer. Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 77bb1cad8471..d80075e1db42 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -255,7 +255,7 @@ static void virtio_transport_dec_rx_pkt(struct virtio_vsock_sock *vvs, { int len; - len = skb_headroom(skb) - sizeof(struct virtio_vsock_hdr) - skb->len; + len = skb_headroom(skb) - sizeof(struct virtio_vsock_hdr); if (len < 0) pr_emerg("Negative len %i\n", len); From patchwork Fri Mar 3 22:02:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13159598 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD07EC61DA3 for ; Sat, 4 Mar 2023 00:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229679AbjCDAD2 (ORCPT ); Fri, 3 Mar 2023 19:03:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjCDAD1 (ORCPT ); Fri, 3 Mar 2023 19:03:27 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B655FEB50; Fri, 3 Mar 2023 16:03:24 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 64FE45FD2E; Sat, 4 Mar 2023 01:05:19 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1677881119; bh=e3N0YJ0uSXUIygh8I5oRxE8zPq5uyuoYZQhh7v2tXp4=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=bEKaIMcFKwNSwUf9ShSc9fH+vHOfHn84oXfVs+JOqa0cEqfp4DbzYMC15A03tDHh7 3v8S32KaH1beaxPMyp9BAsCkFOIDPQE3uYbdSi1f91YijkE0i12Sb4P9g/0juaDv7p t+PPLZFt25ogbsBqHiFLgSXQxtnWJyQMWGEr+zGDMnNV0XRoOatBiaFk5NdmwD6Zc+ ZofIZ1tbuPzNdzvdiyYZrj4fsAx+DBzK+696tpxVcqEwjuqL7JZtmtlJya0RUUOKY8 xnr2wdKaseE7+hMynk9xbG8GfX//9I9aFR0SjPKXfDZOEZMjTk7Y6MhRKdrJJFB4n5 4LTocHToMBjEw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 4 Mar 2023 01:05:19 +0300 (MSK) Message-ID: Date: Sat, 4 Mar 2023 01:02:29 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Content-Language: en-US In-Reply-To: To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Bobby Eshleman CC: , , , , , , From: Arseniy Krasnov Subject: [RFC PATCH v1 3/3] virtio/vsock: remove all data from sk_buff X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/03/03 17:09:00 #20912733 X-KSMG-AntiVirus-Status: Clean, skipped Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC In case of SOCK_SEQPACKET all sk_buffs are used once - after read some data from it, it will be removed, so user will never read rest of the data. Thus we need to update credit parameters of the socket like whole sk_buff is read - so call 'skb_pull()' for the whole buffer. Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index d80075e1db42..bbcf331b6ad6 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -470,7 +470,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, dequeued_len = err; } else { user_buf_len -= bytes_to_copy; - skb_pull(skb, bytes_to_copy); + skb_pull(skb, skb->len); } spin_lock_bh(&vvs->rx_lock);