Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp3831460pxb; Mon, 30 Aug 2021 11:40:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZrn5uNcdeniWb6HqZi4lFZr5/T30X0pIiXqqI2pXIer606uMS/eWeK7eGntFV8B98GMTI X-Received: by 2002:a17:907:1108:: with SMTP id qu8mr27140857ejb.58.1630348832644; Mon, 30 Aug 2021 11:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630348832; cv=none; d=google.com; s=arc-20160816; b=fyXuTQIo8Nd9Jyuj/RZIqLgiq6z+zUQykTxz75g1Yueyyxipwky9U7ue15xmlREf+r cINt6aS0EuFHa4wd5+LSlJhQMrNRYPjE3ZIP5J71VSvxMsYTZXNdhKtM6ouz5Jvey3co On6tIksT+qrgHxBXe9VIEjwLCUPvx6Ha+YUVlmf1VDl/lekpT1dP1PVgrEEeMvIwhKII f+u953TQu99I+C8zfDrrVB/b2A6dTcdSKEreEEDj0mNy8xPKE1MfMU6S8mkm2TKe8G21 rv9lMdI2Pw4LmMwKc7LaDBxHAODcUN+Hhte/OzJLY7CazQjfxxfEyZEq6gzkxooLlA8P gjMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=rNuHlF2j1NdIZb3G7lOsUUlHYfgunpEcyXX5fsl0zKY=; b=UIgg7AyQCJA9mndlhEtGi4X8Z1R2K1o9M5jceWPkTHKpR7YJHD4ujqD0gwwZ9k1q3n c9p5sRD776hVKvyEnu0AKQ4nfzAUA7gObiHFOjYv1O4Ptn3Gg8zAsv1/Uep5Szib1sVt l5ut85NEKk7FFFzgA+druHPSdiZU3FhKlvvqEN/O+5NmasPy8BQC/GhLXmAM2deQW0Dd Z2uhR3ubkjRqQm4fRCdiHJOAu26OCe3RFmP2fmP8v9jua3IInxFH4F6Vj8QyeT7c+n8N q6K/QN2Hc3ssCVtAYlGRzvhqvUnrkALYTke7HXOrljZEzpYQ6VSOXFT/NBmCLK13cBeu ci7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b6zPa7Hm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ak17si17250268ejc.44.2021.08.30.11.40.06; Mon, 30 Aug 2021 11:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=b6zPa7Hm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbhH3SiE (ORCPT + 99 others); Mon, 30 Aug 2021 14:38:04 -0400 Received: from relay.sw.ru ([185.231.240.75]:50372 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230181AbhH3SiD (ORCPT ); Mon, 30 Aug 2021 14:38:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:From: Subject; bh=rNuHlF2j1NdIZb3G7lOsUUlHYfgunpEcyXX5fsl0zKY=; b=b6zPa7Hm4m2J9zvFy kTsItz53p81tC193jsgr7lWHuMqISSpM7sdViYR1ieW68RjycKVTJq63e6Vbad0ftBzRY0SOfr2qE kDEm2BSjZ65v624eUGMnUN8ynqPgER+u7Wr+ikUykh35SY/H8u+1YCHLLgz6M6/cy13B6znB6tf8g =; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1mKm9Z-000FoC-L8; Mon, 30 Aug 2021 21:37:05 +0300 Subject: Re: [PATCH v2] skb_expand_head() adjust skb->truesize incorrectly From: Vasily Averin To: Eric Dumazet , Christoph Paasch , "David S. Miller" Cc: Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , netdev , linux-kernel@vger.kernel.org, kernel@openvz.org, Julian Wiedmann References: <860513d5-fd02-832b-1c4c-ea2b17477d76@virtuozzo.com> <9f0c5e45-ad79-a9ea-dab1-aeb3bc3730ae@gmail.com> Message-ID: <7d13bd9a-9597-74b2-1c9e-5fb7f8c0678a@virtuozzo.com> Date: Mon, 30 Aug 2021 21:37:04 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/30/21 9:09 PM, Vasily Averin wrote: > On 8/30/21 7:01 PM, Eric Dumazet wrote: >> On 8/29/21 5:59 AM, Vasily Averin wrote: >>> Christoph Paasch reports [1] about incorrect skb->truesize >>> after skb_expand_head() call in ip6_xmit. >>> This may happen because of two reasons: >>> - skb_set_owner_w() for newly cloned skb is called too early, >>> before pskb_expand_head() where truesize is adjusted for (!skb-sk) case. >>> - pskb_expand_head() does not adjust truesize in (skb->sk) case. >>> In this case sk->sk_wmem_alloc should be adjusted too. >>> >>> [1] https://lkml.org/lkml/2021/8/20/1082 >>> @@ -1756,9 +1756,13 @@ int pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, >>> * For the moment, we really care of rx path, or >>> * when skb is orphaned (not attached to a socket). >>> */ >>> - if (!skb->sk || skb->destructor == sock_edemux) >>> - skb->truesize += size - osize; >>> - >>> + delta = size - osize; >>> + if (!skb->sk || skb->destructor == sock_edemux) { >>> + skb->truesize += delta; >>> + } else if (update_truesize) { >> >> Unfortunately we can not always do this sk_wmem_alloc change here. >> >> Some skb have skb->sk set, but the 'reference on socket' is not through sk_wmem_alloc > > Could you please provide some example? > In past in all handeled cases we have cloned original skb and then unconditionally assigned skb sock_wfree destructor. > Do you want to say that it worked correctly somehow? > > I expected if we set sock_wfree, we have guarantee that old skb adjusted sk_wmem_alloc. > Am I wrong? > Could you please point on such case? However if it is true -- it is not enough to adjust sk_wmem_alloc for proper destructors, because another destructors may require to do something else. In this case I can check destructor first and clone skb before pskb_expand_head() call, like it was happen before. >> It seems you need a helper to make sure skb->destructor is one of >> the destructors that use skb->truesize and sk->sk_wmem_alloc >> >> For instance, skb_orphan_partial() could have been used. > > Thank you, will investigate. > Vasily Averin >