Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp487414pxv; Thu, 15 Jul 2021 08:41:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxDle7xgYjL2j9zekk2KJaA+bzaJPPZwoQ36YnxyDWszvNaJtp3Frrp9x3fGTnyQNJmfzq X-Received: by 2002:a05:6638:270c:: with SMTP id m12mr4606787jav.5.1626363681444; Thu, 15 Jul 2021 08:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626363681; cv=none; d=google.com; s=arc-20160816; b=mCzLid9sr4pqlVDbyMC36j7ERzKibLhDUsCBug1jOCNX3irj8K1KYYeuzzZl3swLxP q+68MOSbxidta6varV48r+ERyL/sSW2BKyrfaEzLEHxaACx/pq2DGdetpS3jHgjKa40a atxjoNXIEZjjHBbntOa9lXgiv8E6xnIsyvnWte2pTyIHX2dmGDwrqUOHrxsZl5wuCaA2 B4N/cspCX2vYwmIqAsFXnLULjNsoLZVPF8bscixX6qvXFQExaoLl3XwNWihlpK88yqii q2fTAoXMs0Ce3MKtCdwucGPAenZCE6EQ/lFefSwC4BfMRwx1WSZCLeJDGoN3GWgj/YEE rVCw== 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=XFYcji550HYtqpGml52HF9Ker4jPqPp7oBMbaMj4XAw=; b=B5NrlvKEXZ2czvxNUlvrGKHPeZ8NNkByljfyNYLaa33zA2z2TcWIteNPiaEcE8hS63 geI1j9JbPUXj+5H9wCgvlu5KwdexvSRZ0LrcBuXIIQ+uwO5GxSlnxCm6YuK7I+rvVkOo c1+ol64DVGvTP5IQp1DQ/M6DNqNlQ1YPU5hvaI7Y3DlkNY/79nbPTezgkX8ul9g4YtEB oZF0rL3FLl1ZQqlzDxQBE1mxawe6WyvzLtPk3EEXzfc0OPGb2w0oyMZEOK2VjyQTxt32 4CinSN0ioXkLeEqeTUBjtEOrtP57/XOeiw3bbIBWaTwjjg/Pppx1qEyvmN7GRoptP70v fwhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Q5c/Ai4G"; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t3si7494515ile.109.2021.07.15.08.40.46; Thu, 15 Jul 2021 08:41:21 -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=@linaro.org header.s=google header.b="Q5c/Ai4G"; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241522AbhGOKlk (ORCPT + 99 others); Thu, 15 Jul 2021 06:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234408AbhGOKlj (ORCPT ); Thu, 15 Jul 2021 06:41:39 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1375C061760 for ; Thu, 15 Jul 2021 03:38:45 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id g19so8245955ybe.11 for ; Thu, 15 Jul 2021 03:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XFYcji550HYtqpGml52HF9Ker4jPqPp7oBMbaMj4XAw=; b=Q5c/Ai4GgArz4t67eHsHrrkbmuwf2BtOsrIrY95J4QgKeP+4J+aPiw3TdTuERQXh7a DXN7QD6MbjQ9Yogq+LCTo8ePKlu95ChrQSPQ3IE9qk0LtTkdSAKtGiE737u7gMm6/yVk LfeQlg0eTEmjOTLf7UO+ZPQStqdAtKv06w3WxKzqp/CoGLVz+sgtDPWaA4RpZprwplYT rhcfrbZBHloYZ87sJ2rPGIN4+AXKWFhfZche+6WJVkZqrIdZKOGGn829WoebmhL0l4rc Du5wIm32cNEbaltkeFkfh7TI79sptxwxDY9w5H73uF3TFjh62KMDKWIyqtNiFkt6C3Ru hcwg== 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=XFYcji550HYtqpGml52HF9Ker4jPqPp7oBMbaMj4XAw=; b=svzsPl1sAijGCHOOFtmTPJJbWo6Mzwv7cPL07iHVGf6phHsj7wLeMgxx/TaZhGOHPW zrvLcG/pddqKGqWWk70WBSgnqa2QpQ7uma8YQt88Hc9ynXwp/wAxN1EMWldVMsniyAqy hmg1z74Pp10WW6rH/1cM3Yi0uqEBcajVhFCjMCX1/iRP4s6lHxXb34+1LI2eByT9Yfbf pFqO2xJUTF/DuIicUI3M4fyBkDFu0lO5Uz+tCN2Pd40AxIz/M6x6980+j7SynrDWaZZl HFUXRbSEdbIA8VIVboTwvev0LXf1PL5ashWVFJXtH8L4rd/+0MIYUjkiW7bS4Fza3FxF 2Ong== X-Gm-Message-State: AOAM532Oz+rcI7rDv56W3Pzx6VA2XB1LY/dy4nMPm335V0nr/g3rW1X1 hyQsOqXNvd7drOomdXtv4/ILTDD+GNvSCPd+tzDAdQ== X-Received: by 2002:a25:41c7:: with SMTP id o190mr4468817yba.256.1626345525162; Thu, 15 Jul 2021 03:38:45 -0700 (PDT) MIME-Version: 1.0 References: <20210709062943.101532-1-ilias.apalodimas@linaro.org> In-Reply-To: From: Ilias Apalodimas Date: Thu, 15 Jul 2021 13:38:07 +0300 Message-ID: Subject: Re: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets To: Yunsheng Lin Cc: Networking , 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 , open list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 15 Jul 2021 at 13:00, Ilias Apalodimas wrote: > > On Thu, 15 Jul 2021 at 07:01, 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? > > > > So this would leak eventually dma mapping if the skb is cloned (and > the dataref is now +1) and we are freeing the original skb first? > Apologies for the noise, my description was not complete. The case you are thinking is clone an SKB and then expand the original? thanks /Ilias > > > > > > 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; > > > } > > > > > > /* > > >