From patchwork Fri Jul 9 06:29:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 471806 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1019400jao; Thu, 8 Jul 2021 23:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4V9SI7R2N20FgdRf53SBclllLNZzgqRXu8agIicJRoagL1YUifQvohhTvaEHSLfAhz1zY X-Received: by 2002:a5d:9f4b:: with SMTP id u11mr26406318iot.144.1625812192871; Thu, 08 Jul 2021 23:29:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625812192; cv=none; d=google.com; s=arc-20160816; b=kdLxjMPk/lDU4fZfxAe/nf7b2sxKlVLdQgGTqoWRvyKUnWyOMlOzoydz0ofHFNSphh v0pExvA1RyFmPE9zm21O2Lsj6pGO++0+qZyjpgBPSEgQiiWaQQp/Kdc40uGWc0OeFTRJ AmVA5pLjt17vxe8XEiT7snBsi14NSXhyci+XUGEidQVuQj8mHjAKba10iZfBnp5A/izU qZxBKbaI4jtxQkFIjpKhYGwwwAbRhsY55A0uzxTYZRCpWcaoRs6Uoj7yaSS032VYnIv8 DpqfLu8H6yhiO/sWJrFDb/1EDrvqFpwGQZXFePAvCj+DPn8N2coow1R6peVg8gnbtvsZ Unbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=DRY3VnuG4gt8PiNy3Dy2u07H83mINghJPh114/ywsmE=; b=n4eNRDnmMkeiFp9UgobghaOFlyC7obX/bWadeH3X3rBeS+ht6XDe4uYB1t41eLhzZ0 Ftx8oatLMAPxyZzkuuLYl4daLL5z5kzmnEse5KhEKhFZCrrnMFfyfxlvoVtS0V1OV3JD m3sd28uYHiQceZriy9OYoj0EzIekqmwT+q/vE20pu06XFs7MNOa3l+v9o4JTCPY7yI+o 0s5M+t/MUf1HSz58Ana7tBtGmxoepl5gLp0Lw+ZPYckqFVMFl1dO/dfIvgOEWr5lMWcS e7ucLhzLL5U1NzcdiKEfNXcpgZpwMoZHANsdR4tklLVdtC4GxL1lzkzYvtb7QP5V7EzX hUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LI1IHMKN; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 s9si5642548ilq.3.2021.07.08.23.29.52; Thu, 08 Jul 2021 23:29:52 -0700 (PDT) Received-SPF: pass (google.com: domain of netdev-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=LI1IHMKN; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-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 S230256AbhGIGcc (ORCPT + 8 others); Fri, 9 Jul 2021 02:32:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbhGIGcc (ORCPT ); Fri, 9 Jul 2021 02:32:32 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FB7FC0613E5 for ; Thu, 8 Jul 2021 23:29:49 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id w13so5602092wmc.3 for ; Thu, 08 Jul 2021 23:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DRY3VnuG4gt8PiNy3Dy2u07H83mINghJPh114/ywsmE=; b=LI1IHMKNWDRfPUWL1KvoHyjnYq1nGzxGQVHASD1zv0oN2h44sw5Bni6kc8yypoy12i +L6UuTdqLa0jCR8Qdv74MniiSHcsel1TDiFoN/SFMsQHSZtt6M8O9MAzG219dM0ayw7N RemunQ0P7AzFDft7vPOO1WMIv4GnoRMhYeNPDrAGbT2JfgiL0bZsTB/0FUbRSAWwLW7y N9KN9udc6qUq+PdH35UqNT5U7PFCbC+T7YcyvfSVPdNAVaKGq0Yu4TwW8xhWsT8Y6TyQ +fv5yzgaDAoVM7HwJWoH6ETXH668PhMQm2Gp/yG+Rsd3mICVqS1X48yus7ugxppL3JMX oEyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DRY3VnuG4gt8PiNy3Dy2u07H83mINghJPh114/ywsmE=; b=bd2gwGumxHCGq6yBnxWSwI04DE0mWs+CUS5KYxizqMtHRbXNqNUMNj99i+7Ubsxgq2 lAdxLlU2m2ba0pCu7JibyLF1fsNiJVib9JwWU7kgyQJVhyK3fD8o9gN1+ePTsLhQb3E5 7J0ZtUtWEbQyNvSCEZjsGJjZj/Oa2ifUvFfBxCY92WXcQy//LvAQgaIYN24LYrSrhQnd agPOiJ1Emt5vDgCqi1wXAtjg0OI3kaIL6Biq/gumLSE1YuhLx9B3N0maqgeXX9dDyX2Z IKuhSsSgM7zTWxOCpxLW//9TiAEzPtzd3t086KpGRg1X6P2VV2ScYKsl9aVcndzbUvqS WhZQ== X-Gm-Message-State: AOAM531S0EeCAUFVhUyc16EGuSqy3whtBUb0ld1KWcVOKmaWXzds0517 6FOcJSvneB+0Y2iQJwJ6nIGHXrJgTsvjpDWv X-Received: by 2002:a1c:9808:: with SMTP id a8mr36471404wme.54.1625812187750; Thu, 08 Jul 2021 23:29:47 -0700 (PDT) Received: from localhost.localdomain (ppp-94-66-242-227.home.otenet.gr. [94.66.242.227]) by smtp.gmail.com with ESMTPSA id m6sm5183342wrw.9.2021.07.08.23.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 23:29:47 -0700 (PDT) From: Ilias Apalodimas To: netdev@vger.kernel.org Cc: Ilias Apalodimas , 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 , linux-kernel@vger.kernel.org Subject: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets Date: Fri, 9 Jul 2021 09:29:39 +0300 Message-Id: <20210709062943.101532-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.32.0.rc0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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(-) -- 2.32.0.rc0 Reviewed-by: Alexander Duyck 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; } /*