Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp722598pxv; Fri, 9 Jul 2021 07:36:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1/5pkolq6qX8cHRclLbX4Q6CrtLIzQPGqRgKN0PyCJzsH5xVMTdvcwXhCSrqRwwOAaxyu X-Received: by 2002:a17:906:490b:: with SMTP id b11mr13760741ejq.185.1625841369850; Fri, 09 Jul 2021 07:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625841369; cv=none; d=google.com; s=arc-20160816; b=kRDS31wWZO71kS5JL4RuZox3CBrnQn/TCdUl6mGShfisW5H3UUlmvR+xzNK5zIdVDQ j1zWA4QEDdf+L6baZL9YX295dNwpFmeT40avWa3p8cA5bHSl181FMtmcAt7rpScHjmPh HusagMtzEv2sdfhOZvrk1vFTzaunRHQ8pUq7FTBJ07NFpBQ/M6ngP+1eMVtXsBYNxHfq 9Ln1p1+wPPjioVzW2QUWqUujvUT9YQuTSScovUOs2fsO6p+Tk0fYYAqLC9BIVEtdpBqu nAusQS4KEJpbi7s/7IEYUrEvmyR1bVk+4gTc3G5QJb/3ERa0gZrkuggZMVBfSqnjJaaF lkeA== 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=Of8sTWUpYkw8uHoUjgY7rFsK+OTOd/MVYUUYb7dwPKE=; b=cWX6r1PqO8uEFArk/mBiTj5WxjwQUY5WavnVIJeSrX1Jm+0mQ94oOIgzwKvWLsROQr ja8PHxlYpzk2anZE9qXPKaeM9K2hU4x/3wzUXqzbBr/iqJoHByM8AaGuZzVFEXq8ulLh gAsd25aZDiGDSLatORr5INmOKZjBTaU4g6ObnqJ/lhVa73f8c+ooGIAJwHW6/Y0dlOhn nevsU22j7eQo2tanB+RlQhcNeFBht2l2Ckj4xfe1DlVIWzI8OwKMczeqs4ooo+Fr/hIx t7Uqpq5GK3Ty3E0ADPEx9CnPQIau8GR1PTusfMYJi6s1XEXWkdibSloZti7sduiclNmf YcEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Dam8JlEJ; 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 h18si7476805edq.346.2021.07.09.07.35.46; Fri, 09 Jul 2021 07:36:09 -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=Dam8JlEJ; 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 S231993AbhGIOhg (ORCPT + 99 others); Fri, 9 Jul 2021 10:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbhGIOhg (ORCPT ); Fri, 9 Jul 2021 10:37:36 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63E3DC0613DD; Fri, 9 Jul 2021 07:34:51 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id o5so16581239ejy.7; Fri, 09 Jul 2021 07:34:51 -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=Of8sTWUpYkw8uHoUjgY7rFsK+OTOd/MVYUUYb7dwPKE=; b=Dam8JlEJ+8i+TF+EyE6l3aDaaPK1jI26C7teqf6yuMEpnVLtpgIebGm/kystU1ncsV fsjQMpeJaw/ZCCnP+Gdaadf5k7/jsrk8I55uFgWRdCNEvZW/IpS7n4MwCaZQ2Fd3VIh/ F993Xg7sUIf8Cd/OWkzyGTY1OuoKGWyNcxHvHbkuCbcNOwTwi5DRHjaA6JS5eQMmWiPT Q6UnTdMTKUEwIz37n1jJkglzWaf9VtSn4dt0tXg6lXQdN4+V9CMwpJxvmVmI1BVFusYM HS6VovNhI5NrKiQxILIrwpZ+TH6wy+lP/5IOXN/Zlp9WKMPmiIWwxKwE8+ma6iBbMU5S b+WA== 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=Of8sTWUpYkw8uHoUjgY7rFsK+OTOd/MVYUUYb7dwPKE=; b=nOzW8hKji/V5lEnWPy3yNXvutXRS1qQx3H2IhLavFl9997+XOWth9W5xrqdeEAEInd 2Yws32GHQGht6h5ubmhDP6w7QhdQMtj7y4HQKyRSLvTNl/uVlwSLtCtUrfS0vjTXmKed 73IvlDFHPXgf1GYCEJAPO7/RAG67VTz+bSM/o2Kf9NuvVRjc+I82aTEZhT1r9H4LYgTd KyHVqXc6mjs23KcaXjRDo94TekkNpT7eiiEb/5wpmMAo1jeXjOwlQ43Vp6yVPGtzlvNh zj2sWyBPwggXJaMWqmIZ8DbYO4dNEOXdlJdaNG3AaA2j1sxAzIxuDHJsRlSKTKQrTXoZ rHpg== X-Gm-Message-State: AOAM532mmoMTIxsj6K9ZvMXU5Pbgg8peiuIegmf9UsgPJPRlF2Jr42ad OxWcJTDRuh/wGvVMCdYw7LqTTrN4vhl2imNGpaQ= X-Received: by 2002:a17:906:bc84:: with SMTP id lv4mr12289770ejb.493.1625841289853; Fri, 09 Jul 2021 07:34:49 -0700 (PDT) MIME-Version: 1.0 References: <20210709062943.101532-1-ilias.apalodimas@linaro.org> In-Reply-To: <20210709062943.101532-1-ilias.apalodimas@linaro.org> From: Alexander Duyck Date: Fri, 9 Jul 2021 07:34:38 -0700 Message-ID: Subject: Re: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets To: Ilias Apalodimas Cc: 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 Thu, Jul 8, 2021 at 11:30 PM 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; > > 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; > } > > /* > -- > 2.32.0.rc0 > This is probably the cleanest approach with the least amount of change, but one thing I am concerned with in this approach is that we end up having to dirty a cacheline that I am not sure is otherwise touched during skb cleanup. I am not sure if that will be an issue or not. If it is then an alternative or follow-on patch could move the pp_recycle flag into the skb_shared_info flags itself and then make certain that we clear it around the same time we are setting shinfo->dataref to 1. Otherwise this looks good to me. Reviewed-by: Alexander Duyck