Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp390661pxv; Thu, 15 Jul 2021 06:42:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVZF/qTir9A2GZJ0pkz1sa88/Ae5pqH4lznvrMGsXoisJ0zxoTxZfVFmo5I8YBXVFMKo3R X-Received: by 2002:a17:906:d977:: with SMTP id rp23mr5676327ejb.512.1626356554932; Thu, 15 Jul 2021 06:42:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626356554; cv=none; d=google.com; s=arc-20160816; b=HxkMlmJOvUAyc/MnVwipt23YFjVBOREPnv0+VqfxmNFvEuypzCbodPSwhqURqrznvL CuMGVDuPY0mmSBIa2gK/DYPaxRzR9743oFdSnhq7IgFcVrqV+2CSwJ82zsZU30oRzWH3 h9crO52D8OvsjUhrs/ZLYUu3BshHL23zFjdOopzpTnJ/fzc+cs0d0tObocDlU+pj+wqO m1HrFvqg1EhAZtAsvWyUV0QY1Tvvgcw4XojPNVUSrvCryoqXIdfwtj+opqrFcpqNgj03 bbElmQtwyxPv/btX6cDBXvNYAw0RpN9AP6EdiHqSuPoGqmbJVMMVwyIKfWaPKHdc13qv /a/A== 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=zLbz9Om8YwfCedcIibToMxrf3a5LzyV5p0V0SRKWaOE=; b=NofzA+jjX3y8sBUX4yK2SNwi4CIVwjgzI4/lUxyt4uMtO03gn5W8ncyznnkDRG/mdE TAWHiVl6jm0Xj902bGDOb933+CR70pHiWNCW4+mxFKFgkrmacnQJX6YGvGG7P8Vl74+g 07jFfctj1IEwEpUchquzrzH3waMaSy+ae5igsM2O290PvkKowPpXfqRzYf1pX/Pm8JoH flchCjXdc6gk7hFilHgCEtJC0XLRLFRVquv9yhitrcxDiLsjl5aENydnt9dYZCzTLUWa uyUlj9guw16qrs7hDYrexk3PQu60IWtmJQvsiBzila5NSbDRhy73FLqBgQvYk1NH27Oh mOZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NYQjawfL; 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 w25si7488492edq.408.2021.07.15.06.42.12; Thu, 15 Jul 2021 06:42:34 -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=NYQjawfL; 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 S240864AbhGOKDk (ORCPT + 99 others); Thu, 15 Jul 2021 06:03:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233629AbhGOKDj (ORCPT ); Thu, 15 Jul 2021 06:03:39 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E6EC06175F for ; Thu, 15 Jul 2021 03:00:45 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id g5so8085164ybu.10 for ; Thu, 15 Jul 2021 03:00: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=zLbz9Om8YwfCedcIibToMxrf3a5LzyV5p0V0SRKWaOE=; b=NYQjawfLIf9gL9Sic9FgZzcxVAnjibSHyOgm2MN+ZpERD41dML7PynkJm605Vn9xsZ stN6ACVBVwMJtlRSbHTY8H2hRSnlcHaHt5Twl7b9TMMUlMjJDWl4eNqzcNWYJKg6UOVP K+y6lwx61HQnp08s73+zWywYd92QT9PgBDTzsVCslhcXkRvj6d8/V7okioWHKggct18j jGUpJOipWbe9gtBs8gy0gEl2XWekA2BJqjCYwjrXr+MltP9ZLyl7mH8zupVfPh/DhkEo xVhfhHEdXPTZY6FWrkpt77H2taPAOVzF35LR0wqRL5kIztUqzB/5PtRvJFfWo3siBH5T fQtA== 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=zLbz9Om8YwfCedcIibToMxrf3a5LzyV5p0V0SRKWaOE=; b=init+uNX5pnx79aKIzdq9BRM748M2dceQXGumZcHeMCGSOJzggyEAii9GNx0Gsd8p7 nz0HThRPQ5xuD+6dKUyJ61Rxj9NtEpEpVUKrT2RdUIED0fd7fpkwJwvMGarg2Ks7XQEW k7rlXwVxDPKCU0VLbe53pF8tkkeWIkwtODk3oI748WNNrwUn2Fz7PZEFJ6hP20xVqgkG nme/BkBHzHuHhFZgcMqqQstL0xjoNrcyEOstav3sGD2S9wTgJcEmknppKyCsbcb+yoEU byhsWVsgamY+Tav0/UnwrVjjCUIhYyRIulUZzVDH/rovEIVWJtRfHjpVIVmTPo4BkA31 dXXw== X-Gm-Message-State: AOAM5338QNC+bR4ZVD7bNgqMcWlcrYXjgyHoAPd5r8t+G+aLPYrA6Iv8 aRvl5sIlj8bvuZ+47KqJhiazU5OlGGA6p9j/ps2HEw== X-Received: by 2002:a25:2589:: with SMTP id l131mr4326897ybl.259.1626343244886; Thu, 15 Jul 2021 03:00:44 -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:00:08 +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 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? > > > > 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; > > } > > > > /* > >