From patchwork Sun Mar 5 20:06:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 64337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1513963wrd; Sun, 5 Mar 2023 12:12:07 -0800 (PST) X-Google-Smtp-Source: AK7set8AgvlZuT0nHJC4GOqAAbfVEv0wA1uLKN8QydF1uMA9ltjepbw9qEzbZruSERRhwzHQDfsx X-Received: by 2002:a17:907:1c0e:b0:8b1:78b6:4b3c with SMTP id nc14-20020a1709071c0e00b008b178b64b3cmr11236304ejc.73.1678047127158; Sun, 05 Mar 2023 12:12:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678047127; cv=none; d=google.com; s=arc-20160816; b=oTYo7k7soSLaHnRGuB0DP5tVRehAkbmrpM9ojP7hkrnFrsCztJ2UsTKyNxL9jj8jey QMg0+aCq9/rKAdwgsC8q2/1jZd6DvwjTyHQa0m3xy0Gr3TPKR7hhEoXUuHPYtVtFy0qQ 7K8GU6zWS4cWncSNbLJt4svvr6zFBrUti2p1y0Rowpr9lTFaW+1cAitUEzemVdRKK1PQ sPhia5KFY34FZFe4QCpPlWEM1wUBMzAk6S+pVfZK89c3DOmFzfWsJoowEpVe3qunoCf/ B20LZlSxJsxm1P9HfYORo58rQsj2X2fZ76twu6yeI5FdJvK//ch5Pwuo8cpQZ098anZ6 o5uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=OP9Q+D6ddKpeccLb8Rmg9aPK4JcBMYN/s1rz2P24TnQ=; b=LPyI3+AKfc98Mj6fCeVq4EaT7du5bM4fguvKI6p40UB24oYZgNRf9x3zmrBh2nqgyb 8MPOUScBpdhPGL27OcrI16BvE884B9Pbs3sp0eEceNhyjqk0hGUL3wQ/muhtKh4H/YOJ LwuVfwy/afPfGKMLtZBIFKWCdj6uxav6B+S6Ejd16SYH1vPZSjp2RK58SlyeBExzetyJ EWhJUzOPRJ1/Fecq+qVSZBIBjF7MimZTFdSaosn7M28eSGRqkQu9Ueo5ePOxl4gUedew 2PoNXotMIEwnciACXcJOpda1RnbA3MAzKOKVuqx9r3bvLbsVHb3SXen0x8OMMCK//RXV cRUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=pvRXfzfY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020a170906541500b008e86646e6bdsi8213989ejo.1008.2023.03.05.12.11.43; Sun, 05 Mar 2023 12:12:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=pvRXfzfY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbjCEUJZ (ORCPT + 99 others); Sun, 5 Mar 2023 15:09:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbjCEUJX (ORCPT ); Sun, 5 Mar 2023 15:09:23 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 116FE6EBD; Sun, 5 Mar 2023 12:09:22 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 6D6655FD04; Sun, 5 Mar 2023 23:09:20 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1678046960; bh=OP9Q+D6ddKpeccLb8Rmg9aPK4JcBMYN/s1rz2P24TnQ=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=pvRXfzfYGzpc+pLpl2XVgBwgUqDIDKDVwBu61NuJw6pFIFzwQ4JMJ989jxq6qWvwN VoVc15b+2FrAtp9/WVnm7jC5rhl8b3mMuS5/oxY1tMM8+8Kh3AvIYBgMXWbq8HyIhA Cz+O6dfugq9AI4+y6liW4YAguudzQBIpmFbJ/LgjswJv9eu+yvJyQDium+NNcgat3y GIevkso0bdj7Rg1/FJIwjXB/GUoomtoYx4x7aTb+nAh71laGR11mgOdjmeja9G1AOL rFaKu+YfWjTXQyIcLocFUIEdke9//kdGTc70SQheIYP64wSLHaouTAOSm6YlcJCM9N i+iegLpyxz8pw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 5 Mar 2023 23:09:19 +0300 (MSK) Message-ID: <4a3f3978-1093-4c0a-663f-28d77eeb0806@sberdevices.ru> Date: Sun, 5 Mar 2023 23:06:26 +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 v2 1/4] 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/05 16:13:00 #20917262 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759559944561149924?= X-GMAIL-MSGID: =?utf-8?q?1759559944561149924?= 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 a1581c77cf84..2e2a773df5c1 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); vvs->rx_bytes -= len; vvs->fwd_cnt += len; } From patchwork Sun Mar 5 20:07:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 64340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1519063wrd; Sun, 5 Mar 2023 12:29:34 -0800 (PST) X-Google-Smtp-Source: AK7set9MdRFuHfFXeE974He/R/edyi5FFPqJrqLFk90CS++gsuArbrCm9g0v3Lp+8Y7zdQJiLGvP X-Received: by 2002:a17:907:5cb:b0:8b1:3a23:8ec7 with SMTP id wg11-20020a17090705cb00b008b13a238ec7mr11214526ejb.43.1678048174107; Sun, 05 Mar 2023 12:29:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678048174; cv=none; d=google.com; s=arc-20160816; b=XSp8GLwex78YTnueD9OTM+YjRv3F0VXHYJPt0vAint//VTiyURy7R6SU8JrQ+XPt/S uOhuUgG/4uJbuXkippeTOqIwo/ns8nPWfTjdxWz0Tmk/kGNKgYBew33RVz5MwcZff8RX 2s0kXuD4h53Rg5+r0BqqfX0PA3C6HvmEWmchU01rfo1PtX4mjQ5OzM9O633LG7dsySp5 34x6fx5eQQ/olCIIwc+oW1k9CerISctSkbEm2DKxTQB14DtA9CQ10g9p/K6jULqyPnMm x/J3Jp/tRyDpGWq9VEBoyywqmqB1vzkNWSEvtA7xNKWXtZgak1JfaEAi7GVFFTBYWSVu M7aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=B1csgoVu7NP3tPpJfIEd1Is03PuaIF7WOwsc6mPxpMo=; b=BypCA8CgTEIm+LiPD14J7cQf+rtshzUCPe0CP8WUtD87k4O/tz/mOe36H1UgJYmSbu /gULHqHnCMRQMljeliJXtvQ+rUObzUySjaGwTBpl0Xl2tjz1gq+SRYuEUMDPKDOCtjKE aJa8/LV3scrplpEJ4JBJnCEfUMHDud2eCTyCyvv+VOY7afoNrCZznwbmnRSZiSAtfDhL GZVrVVICmNa6M0SEKtKQ9SEjsfqXoX1sdFQ6LkvHMXfIM+Bn5yEmx3M/+mW6cQIo2QkA Cx5MbMBql1cx3yAVjosYjHAXLoiirhVpVA+l1SX7dzalK67ob723gcvB7w92gtegwnUp Q+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=fVvC+MKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020aa7d296000000b004c0cee0afb2si9033830edq.536.2023.03.05.12.29.10; Sun, 05 Mar 2023 12:29:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=fVvC+MKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjCEUKg (ORCPT + 99 others); Sun, 5 Mar 2023 15:10:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229494AbjCEUKe (ORCPT ); Sun, 5 Mar 2023 15:10:34 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30A2710AAE; Sun, 5 Mar 2023 12:10:33 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 8E2FF5FD04; Sun, 5 Mar 2023 23:10:31 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1678047031; bh=B1csgoVu7NP3tPpJfIEd1Is03PuaIF7WOwsc6mPxpMo=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=fVvC+MKyIZIBUwCzPm2zEXoiwyd8w/QY/cclz8FOwtxtnXszutBjkx1wN6ZMznZj4 +fruQpxq8fHvs3lr9H8eppemU45eIWUbLxt0lGlaOC3uDc1KXIZ9kqJFiaK1T+EOLn WE1Myu76V+gulNQGeL4/Np7FDfShWKxYtZIURCJVYH0a0Nb8SCdhbJo8vlLKo2uWic ZJUcsi49mTEXxiuZjBrFi8xT/7sU1XdvKEU6gxE0/PIM2+ds89uwYIbIUlOro5PBkA 7RylTG0PXAIVLfXtM8NoFOq901Fj4KTlKGdboetrSRmk4fMkGI1vMZnczkvkx4lFoZ joyzO4NT1unLQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 5 Mar 2023 23:10:31 +0300 (MSK) Message-ID: Date: Sun, 5 Mar 2023 23:07:37 +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 v2 2/4] virtio/vsock: remove all data from sk_buff 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/05 16:13:00 #20917262 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759561042313815067?= X-GMAIL-MSGID: =?utf-8?q?1759561042313815067?= 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 2e2a773df5c1..30b0539990ba 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -466,7 +466,6 @@ 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); } spin_lock_bh(&vvs->rx_lock); @@ -484,6 +483,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk, msg->msg_flags |= MSG_EOR; } + skb_pull(skb, skb->len); virtio_transport_dec_rx_pkt(vvs, skb); kfree_skb(skb); } From patchwork Sun Mar 5 20:08:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 64338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1514663wrd; Sun, 5 Mar 2023 12:14:12 -0800 (PST) X-Google-Smtp-Source: AK7set+eKlJhm62EtAq69+7zi3GaSKpiI3SA3Ue7jKwbD0S1YRM7vZLkz7OiZpT3pOGnOdUPOGPm X-Received: by 2002:aa7:c242:0:b0:4ab:4c5e:b0ed with SMTP id y2-20020aa7c242000000b004ab4c5eb0edmr7221813edo.21.1678047252671; Sun, 05 Mar 2023 12:14:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678047252; cv=none; d=google.com; s=arc-20160816; b=yOKUO4Mj0fgogBl94RYfh6wFEnzljxL5CoWeNaF4D/PHHR93a5glYBB3N8SOZw2itP vhU+ewrChM2dH9G4703Mn+j5cgvIuflSnfEp+8BCB8wQPriTwWKmLigLj2ir+LK5w+Iq m8L0imQgqzzLi7BojKO6gd8sqWjmI1F4kOp6zCzaMXIFRgLGTFhdz5hmAdDrfYbRyN4U 1vU2ICeHSFbe6vPpIJWF/7PK6vIW/1AZPn07kLqBY4am4w2o9NkSF24XFmC6dU0uWVfU TGTWVBRiZWHzvJsUGhDCLmcknI682CX/3pG5KG222bNuDpLK7s8GEUYbAk9Lax91CBUv sLLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=L7Da6J5rFTLCyGxPPlCQpR06uIFFfMTCDUQ95Mc4yIg=; b=lTm3Rn7B6tEgh+OmTdt+a6M8CW40TXJoNaWXBrAr9kCVbDj5fUfTeW21v/4uaSzuRQ JbJeNv4vE2hDCixFfj6BLOw/CUPe66vYi1RkBW1LuwY1+23k6I5veeTQsEshTddAz5Yd Y/JuFpm4YScZN7NKLaMhmxRcL2pKHgJo1O34zEIHQHgSZ5VvQCLA3Fq7C1Plxaj7o69K RLh2UPsErXSvhddxJpi9WbPDC/n1py0hAkxL6B8ti8nd3Cr3nyveh7E1CNXTb94pFC9/ YIg0cU6mxJwU7ukmgjAf03oStp9gG0bO0md/3jN6i8UmCTvk0r5w7RSfs5wS8w1qLnYO DEAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=sAYdmP2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n16-20020aa7db50000000b004ce1d99975bsi3775105edt.93.2023.03.05.12.13.49; Sun, 05 Mar 2023 12:14:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=sAYdmP2F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjCEULl (ORCPT + 99 others); Sun, 5 Mar 2023 15:11:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229688AbjCEULk (ORCPT ); Sun, 5 Mar 2023 15:11:40 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDD0917CDD; Sun, 5 Mar 2023 12:11:33 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0E01A5FD04; Sun, 5 Mar 2023 23:11:32 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1678047092; bh=L7Da6J5rFTLCyGxPPlCQpR06uIFFfMTCDUQ95Mc4yIg=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=sAYdmP2FkWe3wXhXTMZu6zuZLixtYz3kfbiRaUzkwIJKRmHsdp26jhM7OHQx/iSNd n0G8Xbk2uvUUruBpIw5WTl9Rjg3NZkSYLkZPo1Z3+gDbSLvqf8uiD1U61X1t7XYX8t EvPlzNk5v9YyfmmEQ/8WgRdy3AHYX10hkcPSdJF6Yq7pC/XxCLZpjtPziLcpuWMZnU m1+dSW8I+Cq8tMA/TpzhNBBC+At2IHavY9xQ/fpuofE2G/QoHX3K0KawRb3M4xIG1Y ErLqdyDkQ7uihZJyZVjJifcTWOWyvdWh3rA7gmL9kaf7RVt1fuE2YYjUMFiVHoNpGe JU65c1wBdgALA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 5 Mar 2023 23:11:31 +0300 (MSK) Message-ID: Date: Sun, 5 Mar 2023 23:08:38 +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 v2 3/4] virtio/vsock: free skb on data copy failure 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/05 16:13:00 #20917262 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759560076042661942?= X-GMAIL-MSGID: =?utf-8?q?1759560076042661942?= This fixes two things in case when 'memcpy_to_msg()' fails: 1) Update credit parameters of the socket, like this skbuff was copied to user successfully. This is needed because when skbuff was received it's length was used to update 'rx_bytes', thus when we drop skbuff here, we must account rest of it's data in 'rx_bytes'. 2) Free skbuff which was removed from socket's queue. Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") Signed-off-by: Arseniy Krasnov --- net/vmw_vsock/virtio_transport_common.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 30b0539990ba..ffb1af4f2b52 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -379,8 +379,12 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk, spin_unlock_bh(&vvs->rx_lock); err = memcpy_to_msg(msg, skb->data, bytes); - if (err) + if (err) { + skb_pull(skb, skb->len); + virtio_transport_dec_rx_pkt(vvs, skb); + consume_skb(skb); goto out; + } spin_lock_bh(&vvs->rx_lock); From patchwork Sun Mar 5 20:09:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 64344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1526564wrd; Sun, 5 Mar 2023 12:57:08 -0800 (PST) X-Google-Smtp-Source: AK7set8GKhCje6dWPqiofhjjsnCTygG0qtJn4Y/QONbU+V9/7aNkoFl29UjhbxQ//B3SJTs+bUbW X-Received: by 2002:a17:902:708c:b0:19a:9686:ea8b with SMTP id z12-20020a170902708c00b0019a9686ea8bmr8186457plk.28.1678049828387; Sun, 05 Mar 2023 12:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678049828; cv=none; d=google.com; s=arc-20160816; b=AAJICCbxFZxbUYKE3Rj16FpXcQlALWw56hiTLvoVpSylEyWYwY2LOU1zBLwOadyjUA OL6e7rAp87wPklAsxJMq4OcdGluFgYqp8L7jbNwfJeLyWumImMZbOyhuVCQmAWt6K2nl hIchYdlCi8sq32qebgdsGVawBrZP42EoBhXiiDmUFo+q5HrRHSt8qCoUW10KTTvcwgc6 YbZcH9Q5Nw4rD5m0orJmJhAtcU96//zrVxWxwdOlI40SGIfdR+h/50u3UtEFyQ+peYMn G8zewWShnitf34PYzM9QOUh0zMlEtMqApbD/DX4qbH2eBr0d0McelNd07uRixDfh4ebz hGMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:subject:from:cc:to :in-reply-to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=LBlyx/TJwFonLBm4/UgbK3j5G7h+oxv2IfiFYdPacyQ=; b=V5U+AFcK0tr7RuDvxOs+JhNdBR3r4+4dh+x3RUmDihMkP8AqRf83cmq0DxFkSH9yvk z1TsweMB5udDFk8OwWb7QXa2p/dWQKlnSZXgGz+tqlDC4HZmurMWKcQ3/SwSaaQI07ub N9aUL3aFbhiPDuPSVid8J6V2+feVCkyEQ384ak7hia2Lz+S43imQMQRiBO9UP93/bTa+ PQ+aLYuMdLgEqmjlT/4uwVkJ/SlzEMRFHRp0TJqwDIPjy4DS+Cqu+CxfCOa3WWm5PcgH 01OHTFiuvvFx3NdlP4MNXs0E1fJNsjqe0pCdw4/ep/ICo7/8+PD80as6tcuDmm5vng/U 6SJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Ufyh+Um3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a1709026b0a00b00186892f9f29si7717825plk.488.2023.03.05.12.56.54; Sun, 05 Mar 2023 12:57:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=Ufyh+Um3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229742AbjCEUMt (ORCPT + 99 others); Sun, 5 Mar 2023 15:12:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbjCEUMr (ORCPT ); Sun, 5 Mar 2023 15:12:47 -0500 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50CC816891; Sun, 5 Mar 2023 12:12:46 -0800 (PST) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B88B55FD04; Sun, 5 Mar 2023 23:12:44 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1678047164; bh=LBlyx/TJwFonLBm4/UgbK3j5G7h+oxv2IfiFYdPacyQ=; h=Message-ID:Date:MIME-Version:To:From:Subject:Content-Type; b=Ufyh+Um3BnhTeU4iJIGmbF32wZXu2nh7hbxlNDCDYDjZk6CW95jlcZzVg8HmUlED1 IzuDAqifRJeIbCMQ1yENpcmoHesh6ADUFZtQyxLMGPX+wYuuRUY/fZd2TISEynOQ4T nFq7aX/MnjIBtD71GhYyeUBir+NI+qyY+K8kMHkJ6Wguhgx8K7ptM59q0xPhQ45nnO rZytQjJzr0JRvflPoQXfN/LLyZjCglfrnFUIm8ZPo2ttSmzSjKS7PXVRG5DgRhCunb wHLaV+Mscmb0GuLN8BRHTWtNv/frAgO9xUidKM4FbnWVAv5BBAJ8K9bSiR+1F6oEQC o73ge+Tal2PmQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sun, 5 Mar 2023 23:12:44 +0300 (MSK) Message-ID: <33c2a09f-7f0e-d416-8009-bbb6a67ec752@sberdevices.ru> Date: Sun, 5 Mar 2023 23:09:50 +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 v2 4/4] test/vsock: invalid buffer tests 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/05 16:13:00 #20917262 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759562777237136574?= X-GMAIL-MSGID: =?utf-8?q?1759562777237136574?= This adds STREAM and SEQPACKET tests for invalid buffer handling. It tries to read data to NULL buffer (data already presents in socket's queue), on fail kernel will free skbuff with data and next read with MSG_DONTWAIT flag must return EAGAIN which means that skbuff was dropped and socket's queue is empty. Signed-off-by: Arseniy Krasnov --- tools/testing/vsock/vsock_test.c | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c index 67e9f9df3a8c..a17794a2d66c 100644 --- a/tools/testing/vsock/vsock_test.c +++ b/tools/testing/vsock/vsock_test.c @@ -860,6 +860,102 @@ static void test_stream_poll_rcvlowat_client(const struct test_opts *opts) close(fd); } +static void test_inv_buf_client(const struct test_opts *opts, bool stream) +{ + unsigned char data[512] = {0}; + ssize_t ret; + int fd; + + if (stream) + fd = vsock_stream_connect(opts->peer_cid, 1234); + else + fd = vsock_seqpacket_connect(opts->peer_cid, 1234); + + if (fd < 0) { + perror("connect"); + exit(EXIT_FAILURE); + } + + control_expectln("SENDDONE"); + + /* Use invalid buffer here. */ + ret = recv(fd, NULL, sizeof(data), 0); + if (ret != -1) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", ret); + exit(EXIT_FAILURE); + } + + if (errno != ENOMEM) { + fprintf(stderr, "unexpected recv(2) errno %d\n", errno); + exit(EXIT_FAILURE); + } + + /* Now use valid buffer, but socket's queue must be empty. */ + ret = recv(fd, data, sizeof(data), MSG_DONTWAIT); + if (ret != -1) { + fprintf(stderr, "expected recv(2) failure, got %zi\n", ret); + exit(EXIT_FAILURE); + } + + if (errno != EAGAIN) { + fprintf(stderr, "unexpected recv(2) errno %d\n", errno); + exit(EXIT_FAILURE); + } + + control_writeln("DONE"); + + close(fd); +} + +static void test_inv_buf_server(const struct test_opts *opts, bool stream) +{ + unsigned char data[512] = {0}; + ssize_t res; + int fd; + + if (stream) + fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL); + else + fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL); + + if (fd < 0) { + perror("accept"); + exit(EXIT_FAILURE); + } + + res = send(fd, data, sizeof(data), 0); + if (res != sizeof(data)) { + fprintf(stderr, "unexpected send(2) result %zi\n", res); + exit(EXIT_FAILURE); + } + + control_writeln("SENDDONE"); + + control_expectln("DONE"); + + close(fd); +} + +static void test_stream_inv_buf_client(const struct test_opts *opts) +{ + test_inv_buf_client(opts, true); +} + +static void test_stream_inv_buf_server(const struct test_opts *opts) +{ + test_inv_buf_server(opts, true); +} + +static void test_seqpacket_inv_buf_client(const struct test_opts *opts) +{ + test_inv_buf_client(opts, false); +} + +static void test_seqpacket_inv_buf_server(const struct test_opts *opts) +{ + test_inv_buf_server(opts, false); +} + static struct test_case test_cases[] = { { .name = "SOCK_STREAM connection reset", @@ -920,6 +1016,16 @@ static struct test_case test_cases[] = { .run_client = test_seqpacket_bigmsg_client, .run_server = test_seqpacket_bigmsg_server, }, + { + .name = "SOCK_STREAM test invalid buffer", + .run_client = test_stream_inv_buf_client, + .run_server = test_stream_inv_buf_server, + }, + { + .name = "SOCK_SEQPACKET test invalid buffer", + .run_client = test_seqpacket_inv_buf_client, + .run_server = test_seqpacket_inv_buf_server, + }, {}, };