Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp813727rwl; Wed, 29 Mar 2023 08:48:33 -0700 (PDT) X-Google-Smtp-Source: AKy350aHeg4llxWb9yAKAP3HeGTkE6yMaHiBxZf/VttFshfDoB4ygi3J/J1zBLIdoIUAyq4ZnyKS X-Received: by 2002:a17:907:a50d:b0:878:481c:c49b with SMTP id vr13-20020a170907a50d00b00878481cc49bmr24391842ejc.1.1680104913316; Wed, 29 Mar 2023 08:48:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680104913; cv=none; d=google.com; s=arc-20160816; b=hohz+COdpnupX/FjpsXGB1z9KWlANRtjdbWb8v+2/tJSTjEV6Ze3mH6Dt85nGFSvHc 01q2VxuG+eQykcMXwzcAwlP5WrTBF7hoj30wjgeI59ftl5BzbJvXY2vIbnLGPWsagmJg asI9bjN5SOG5NNH3TR+q3vuGkaRSgfEA6UwWM29XrReMiLRL5IV4A/k24jp44cfEIYgI vk8WF9RiaIlL/Zh1akoPE2nPBZ21PpYFkS+YXyLFAhjAXPLrcw77y+fkjeQmKNYYf/25 cwlNWiwscyU/CUIlK2aw+xjnxIe2hQbJAVJVXM43dGGaKvjXPLgxOEQAYi1n1KQapEW7 7vsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZB9Gng/bSJbqymM4NvT3ASIykRxYTVJWxfwiTANs0tE=; b=mJnrr2yuiriECJxoulhlUkYX9r+z5pX/CezviImv7BPTf0POzW1IeNyTUzUqNtsY93 ppdFcKIuLw63ygnzTxD5MdigXpYYcDlUR4G2/qFYWVRnWwP+zKEjJbwXK0byWxJv5v0a 5I7X6DUuot7kiEVd0ybbsqi0gh9KZ63daqASioIgM64AUEJtLTd9RLsvz6RPBQ19Yiua u680HEBX0pg0BNyDmJ9cyF8ZTdm3Mxw0Mbp9Qte7zlkSBMxnMBbQcwEWQyTjLJrk/TDo VQbULJfuy9QI9NxiF/yLP0HNMVW5q7a/+PIn7nYsw50WK3eCcarqQP0zJ3Ags8+ai+LD L81g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TG78JGz1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gy19-20020a170906f25300b00925de8df75asi32045432ejb.75.2023.03.29.08.48.08; Wed, 29 Mar 2023 08:48:33 -0700 (PDT) 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=@gmail.com header.s=20210112 header.b=TG78JGz1; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230096AbjC2PoY (ORCPT + 99 others); Wed, 29 Mar 2023 11:44:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229873AbjC2PoX (ORCPT ); Wed, 29 Mar 2023 11:44:23 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2176530E6; Wed, 29 Mar 2023 08:44:19 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id kc4so15307503plb.10; Wed, 29 Mar 2023 08:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680104658; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZB9Gng/bSJbqymM4NvT3ASIykRxYTVJWxfwiTANs0tE=; b=TG78JGz17hb6VNnIiomQZ2TwfThSO+UL/u1S2kq52LkivTs4Ew+wpK+fYDv89fOSUD w3bIzUbJAYlSfF0sHONJLTI27QBHb+cNZwZ/miFycaxLlDRAlMlOtbBkLS+LS3mn2DGK q9yoqy8vdfwnriqnwq2dJJmm3/ikZiHUjVA4dj290dU0lZBA4diLTLEc15meIT8gjuMh tz5PPvHT6JuTkanNDGOv2s+FfKgqcP1ox+nCDFjbedI2yXfJrWzcBY0lemxzsMfoKFo0 mtuITW4gRKGYdelhQSwUDLRhqmTaciOa0AzqUeco38aM6bGiDLZVoEYuX4If8x4FOuiL dIOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680104658; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZB9Gng/bSJbqymM4NvT3ASIykRxYTVJWxfwiTANs0tE=; b=N3l3FcXf/zia5k3TD2+hFsg3DpHRKfxyowriEKll6Lyn2tOQndcfMIACk5m7VC04ay GyZB66YA05sEpbQhiXr6xnky5P1crJ4j2fm57QHjtC7yckNuYijcxUQGC+z/67qV/Rrr sJCZr0rqQP5nXGuxGwV/vYPdLPjO1XWYFFqloBVBX4/nErX0LId+ujiBR8wK7v4zBRR+ plgpoX4V87QLhCNkrpnVUUr7XbYLwFtvlW8LiFJS1ZWQILOIrfk3RGOZ5XBQiFV122Tj /7Fg+JaMZVYsdOrWSwTYLdzBg8/3YJcGtqT8aEEPId0q8J/C5yiORrDQwOWFn+EkvYqs S8vg== X-Gm-Message-State: AAQBX9c1vwuL07lOkfNORAIuuTMUmNkdibkqW2IkV+Yx3nsH1nJBwLcX pNzDcZAmQdVR1jlQBt+kwas= X-Received: by 2002:a17:902:d10c:b0:1a0:5524:eb8e with SMTP id w12-20020a170902d10c00b001a05524eb8emr15955262plw.68.1680104658419; Wed, 29 Mar 2023 08:44:18 -0700 (PDT) Received: from localhost (c-73-164-155-12.hsd1.wa.comcast.net. [73.164.155.12]) by smtp.gmail.com with ESMTPSA id b4-20020a170902a9c400b0019f3da8c2a4sm23112731plr.69.2023.03.29.08.44.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 08:44:17 -0700 (PDT) Date: Sat, 18 Mar 2023 17:50:10 +0000 From: Bobby Eshleman To: Stefano Garzarella Cc: Bobby Eshleman , Stefan Hajnoczi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Cong Wang Subject: Re: [PATCH net v2] virtio/vsock: fix leaks due to missing skb owner Message-ID: References: <20230327-vsock-fix-leak-v2-1-f6619972dee0@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=1.9 required=5.0 tests=DATE_IN_PAST_96_XX,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * 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 On Wed, Mar 29, 2023 at 09:16:19AM +0200, Stefano Garzarella wrote: > On Tue, Mar 28, 2023 at 04:29:09PM +0000, Bobby Eshleman wrote: > > This patch sets the skb owner in the recv and send path for virtio. > > > > For the send path, this solves the leak caused when > > virtio_transport_purge_skbs() finds skb->sk is always NULL and therefore > > never matches it with the current socket. Setting the owner upon > > allocation fixes this. > > > > For the recv path, this ensures correctness of accounting and also > > correct transfer of ownership in vsock_loopback (when skbs are sent from > > one socket and received by another). > > > > Fixes: 71dc9ec9ac7d ("virtio/vsock: replace virtio_vsock_pkt with sk_buff") > > Signed-off-by: Bobby Eshleman > > Reported-by: Cong Wang > > Link: https://lore.kernel.org/all/ZCCbATwov4U+GBUv@pop-os.localdomain/ > > --- > > Changes in v2: > > - virtio/vsock: add skb_set_owner_r to recv_pkt() > > - Link to v1: https://lore.kernel.org/r/20230327-vsock-fix-leak-v1-1-3fede367105f@bytedance.com > > --- > > net/vmw_vsock/virtio_transport_common.c | 5 +++++ > > 1 file changed, 5 insertions(+) > > > > diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c > > index 957cdc01c8e8..900e5dca05f5 100644 > > --- a/net/vmw_vsock/virtio_transport_common.c > > +++ b/net/vmw_vsock/virtio_transport_common.c > > @@ -94,6 +94,9 @@ virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *info, > > info->op, > > info->flags); > > > > + if (info->vsk) > > + skb_set_owner_w(skb, sk_vsock(info->vsk)); > > + > > return skb; > > > > out: > > @@ -1294,6 +1297,8 @@ void virtio_transport_recv_pkt(struct virtio_transport *t, > > goto free_pkt; > > } > > > > + skb_set_owner_r(skb, sk); > > + > > vsk = vsock_sk(sk); > > > > lock_sock(sk); > > Can you explain why we are using skb_set_owner_w/skb_set_owner_r? > > I'm a little concerned about 2 things: > - skb_set_owner_r() documentation says: "Stream and sequenced > protocols can't normally use this as they need to fit buffers in > and play with them." > - they increment sk_wmem_alloc and sk_rmem_alloc that we never used > (IIRC) > > For the long run, I think we should manage memory better, and using > socket accounting makes sense to me, but since we now have a different > system (which we have been carrying around since the introduction of > vsock), I think this change is a bit risky, especially as a fix. > > So my suggestion is to use skb_set_owner_sk_safe() for now, unless I > missed something about why to use skb_set_owner_w/skb_set_owner_r. > I think that makes sense. I was honestly unaware of skb_set_owner_sk_safe(), but given the reasons you stated and after reading its code, I agree it is a better fit in light of vsock's different accounting scheme. I'll switch it over in v3. Best, Bobby