Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp426592pxv; Thu, 15 Jul 2021 07:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwje525MHZcca7JaQ7l56qtC/3AHwGChRV/m7CXDse9EEGx6crh/CTBTyAmCOMsJTW82JFJ X-Received: by 2002:a17:907:62a7:: with SMTP id nd39mr5883627ejc.502.1626359234069; Thu, 15 Jul 2021 07:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626359234; cv=none; d=google.com; s=arc-20160816; b=CJRLR9bvuAE1H23Hl6VCXDIzpzBz2DJuj5g75sE+UUkTjTcxzzHJHVwHrv1xvgfirG ndl7sUj5nL7a1ybD1QOE7L+DHa/XJSR7XJRu6KaDGBccNr9K4lcdLUMeYOND8H/MYEuY LE/mjs3D/sdxF1hCsITLDpaIXapX9ZJcS5jlAw9D8XUYbu+igxZd2XR/FgjcukYo1Vjq mwTldNzdxKZf1m9IYL/p3nxnP/XIt3uurHARZRPoG3UtyDy8xR0J3H5odn23zrpuIsBe ZPlSeGEA24YQWdWwqcrqoQAdAOAgKI2D5iPyTfk6nVlPzzf/covON8mK9/ha6f87510B xYuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=hPi0AV58UCJPRZJrgAK/kxp1/ZQY1bqf97Po2jccYNs=; b=ft+UoXFS4FcpU853OxbVc9WVzxUwmHIoDXl85rrH8mItsdWKbwDyxNma1KWCCn7+kb gbDQb//1auckrSojyjP+e+XHLMFpr9eEn3KZS6x3xEWZUyxtXAfxVDrGgadi3yIEsGI+ oFJDVxpiFL7UB5x/2HaW5dp6y9itN4iFrtoxon71BX69n+/lALXWU1ZX7LI7+GqIr9Zs +MeYMbv2MnzpXcOkvvbxyCbOC9Gd5Pad4TLxgnb/u5+5mAV6H4HGI7VgKIUprQeOo0oU SfEo3HoPvoYGMsUNX1teyssmcsK9Te67xXMz/CHxy38yWHq7kBDvJjn9p00ruBDNYPWY +RIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LLL4gUVy; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v19si7457512ejx.308.2021.07.15.07.26.49; Thu, 15 Jul 2021 07:27:14 -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=@gmail.com header.s=20161025 header.b=LLL4gUVy; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231128AbhGOO2W (ORCPT + 99 others); Thu, 15 Jul 2021 10:28:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbhGOO2W (ORCPT ); Thu, 15 Jul 2021 10:28:22 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6D39C06175F; Thu, 15 Jul 2021 07:25:28 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id l26so8370170eda.10; Thu, 15 Jul 2021 07:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hPi0AV58UCJPRZJrgAK/kxp1/ZQY1bqf97Po2jccYNs=; b=LLL4gUVy6wLxp/YE/ivmkO8qS/9tp+5x6psoELU1VXCOGHoY2uXa0cIUuhHPInf8+i RXOn4Y/SXvp1ygUF4b9nuip+DiK2c1fsE0id24jdQz0D4e7NHD0MVtIgpbUvW94/YH18 WJQz7AzyukzPW6Bb+ppedCLiSHzl+HErzy9kl/Zz6Hzhw6dH7LP22s23/gqKh51MlZT2 YXzfstAffMcpV7Z2x1lE7oPLMAZoy1BEs0tYaWaHUnONT0sAJ4+2wDIHtlYbTQL1EuQS fmdNCbNU5DYAndiwM2W6YvYDqxcLGOIQ0DwhIvMr71q7dH3habTamd2HQaFqrWrtUOwj ENSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hPi0AV58UCJPRZJrgAK/kxp1/ZQY1bqf97Po2jccYNs=; b=mb0w+IvyhXXzIa8m2pbIGKxgep7uJoGvP04lm4feudpgtFx+tpLQmqTXpn8G3dwSVA ApCZH3wkS80qECLxGtqJMCoaH0/tEPiHJYCu/3P7LaWRZtBqxugV72c6d/ixQx1X3fa2 FakG4FXuAwriSpxp5cEdB9/iT4ODSvYFmeCbN1gq08M5uFoqKr0e3fZYbgvmUIIZeHeI oNcxGMcbJUXBrrpUhRViJtJP5mcxwQV71WoeRbILi7cNxgB52ldQ6xQmeZEP1fFedA9f C1+Ck5qKrtzChpmq62bSaHtRot3QG1snPZZ6ojHdMCuj8YFcfY9dMvUBoWkmKvslfYxX M7BA== X-Gm-Message-State: AOAM530j07FfqijVOjfPf4k49JTaoQcan42oPgV/U/p/LKC+oZV08F5V FqnsFsoXdjYfgdkQ9okPazBfwF8g/4yiX7LWsSw= X-Received: by 2002:aa7:d554:: with SMTP id u20mr7402567edr.50.1626359127039; Thu, 15 Jul 2021 07:25:27 -0700 (PDT) MIME-Version: 1.0 References: <20210709062943.101532-1-ilias.apalodimas@linaro.org> In-Reply-To: From: Alexander Duyck Date: Thu, 15 Jul 2021 07:25:16 -0700 Message-ID: Subject: Re: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets To: Yunsheng Lin Cc: Ilias Apalodimas , Netdev , Alexander Duyck , "David S. Miller" , Jakub Kicinski , Alexander Lobakin , Jonathan Lemon , Willem de Bruijn , Miaohe Lin , Guillaume Nault , Cong Wang , Jesper Dangaard Brouer , Matteo Croce , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 14, 2021 at 9:02 PM Yunsheng Lin wrote: > > On 2021/7/9 14:29, Ilias Apalodimas wrote: > > As Alexander points out, when we are trying to recycle a cloned/expanded > > SKB we might trigger a race. The recycling code relies on the > > pp_recycle bit to trigger, which we carry over to cloned SKBs. > > If that cloned SKB gets expanded or if we get references to the frags, > > call skbb_release_data() and overwrite skb->head, we are creating separate > > instances accessing the same page frags. Since the skb_release_data() > > will first try to recycle the frags, there's a potential race between > > the original and cloned SKB, since both will have the pp_recycle bit set. > > > > Fix this by explicitly those SKBs not recyclable. > > The atomic_sub_return effectively limits us to a single release case, > > and when we are calling skb_release_data we are also releasing the > > option to perform the recycling, or releasing the pages from the page pool. > > > > Fixes: 6a5bcd84e886 ("page_pool: Allow drivers to hint on SKB recycling") > > Reported-by: Alexander Duyck > > Suggested-by: Alexander Duyck > > Signed-off-by: Ilias Apalodimas > > --- > > Changes since v1: > > - Set the recycle bit to 0 during skb_release_data instead of the > > individual fucntions triggering the issue, in order to catch all > > cases > > net/core/skbuff.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index 12aabcda6db2..f91f09a824be 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -663,7 +663,7 @@ static void skb_release_data(struct sk_buff *skb) > > if (skb->cloned && > > atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1, > > &shinfo->dataref)) > > - return; > > + goto exit; > > Is it possible this patch may break the head frag page for the original skb, > supposing it's head frag page is from the page pool and below change clears > the pp_recycle for original skb, causing a page leaking for the page pool? I don't see how. The assumption here is that when atomic_sub_return gets down to 0 we will still have an skb with skb->pp_recycle set and it will flow down and encounter skb_free_head below. All we are doing is skipping those steps and clearing skb->pp_recycle for all but the last buffer and the last one to free it will trigger the recycling. > > > > skb_zcopy_clear(skb, true); > > > > @@ -674,6 +674,8 @@ static void skb_release_data(struct sk_buff *skb) > > kfree_skb_list(shinfo->frag_list); > > > > skb_free_head(skb); > > +exit: > > + skb->pp_recycle = 0; Note the path here. We don't clear skb->pp_recycle for the last buffer where "dataref == 0" until *AFTER* the head has been freed, and all clones will have skb->pp_recycle = 1 as long as they are a clone of the original skb that had it set.