Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp263690lql; Mon, 11 Mar 2024 01:44:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXulcsWIbyg11NdnAGr6pMTt0vnpbRP3lZfpJy42dO+HWNLoFxgoHPf5oBeEgMCrDfMDnN96wVwFaBERcf+2KPyur9XfNFUW13pZtWjhg== X-Google-Smtp-Source: AGHT+IG5WnKIwBGsV7y2ZVlWoV19c+JA5k56aM/KVZKTlJ2l5kABWPJSwxac66KM3L1+GRngrfUi X-Received: by 2002:ac8:7dc3:0:b0:42e:c168:4a1b with SMTP id c3-20020ac87dc3000000b0042ec1684a1bmr8599176qte.7.1710146656895; Mon, 11 Mar 2024 01:44:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710146656; cv=pass; d=google.com; s=arc-20160816; b=CVRbVvQ1OUrazvQRuwithb+MIX00p4zMzmDKKFCFv+VZ7ae7vMFbeoRviqlYj2id77 /p6VJV43qdAVVrhRM3+G21P2CNxrP/X83fKS5s2pEhK7jkLWnSABvgHSgg60cIwKWeT5 +68MLleaYe+CN413Q9EdBW4quXu0NnBvnBmtbDDXE/dACKq9VC11l8Ww5dQ5yoqaBNc1 t54+FtUDgPJOCwDO0Syj4odzhWCk6nJSk/po/gSjru2oSczdoE2G1oXQWOqLxnhS+nyY LwxL9gjiuSw4xVnVF+o4lnKcjt47iXhVRKKCPaJJvhTU23oU4lNnSIy/g5o7QqzicP30 Prvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=7eBCaB1KJSJv4nuU5XUfD5CciJ2EmxrAEpbHEbAM5m0=; fh=ddqojEMNy1WP+UwVby75y4Fyd/L28J3gZmkMQ1xpNF4=; b=rWbYUxmRtgrqUFykw5Cp0QePDYt+Fx7I+J3J6QdXfPi3zhfhL+zbQC/iYtv5s7QSoV stA/CHQ/I6QYGiOG6D7XAbNC1iqI0RWanOyZvHjwuKFforrXp5UtdS146qkZ1FAZswjT S2FzWAw8lzeafZhyq0UN8CfwqDlYWEgfT+Xs6NZ7y+WSfZg01OkLDvhxB1lsPfopo4r4 KpdQw3T+DIhApNc3dPZeR4rxLurTZt4D6I+fQ5OZi+KaxRAnKou6OKqkp+JttX0/kBk/ 8xhS1QEtimSYn7KGIB3OR1icSxOZs+L7iAKZ6ALOhaliKn4T1Bn5Fppuq4cVXvngOOr3 +MnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pGy0NHHU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-98549-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t38-20020a05622a182600b0042ef9802ea1si5073986qtc.186.2024.03.11.01.44.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 01:44:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-98549-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pGy0NHHU; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-98549-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-98549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8F3BB1C20BBC for ; Mon, 11 Mar 2024 08:44:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D214812B7E; Mon, 11 Mar 2024 08:44:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pGy0NHHU" Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 899C6134C9 for ; Mon, 11 Mar 2024 08:44:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710146646; cv=none; b=T9cMXMVxtXDGm5ppploEizLrS0FHleARGRFIPa0Pdw0LZVS5BmJ2YeVBwuEWQeSZr0FYx+yT+0b/DBQ6Lp9ik2gJpygg0tOBw3E0Ya98FBdOfR5u16Khp02t2ud/2MrXcDoQ/Pz/yHMZ+wizqDwtnPi5ssSlsSaYDLlJgF22IzM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710146646; c=relaxed/simple; bh=4yAabAOW5y86cLzd/eEKqcAB/jCkZr6aV2T8AY250g4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=NRgW/gf7Q/wsDo8KIJfyA8SAHFCg9k/CEsT3riNCuIhmM2DcY2qM+tHjD8x3MFZCwmIPCKslFSOq1ihkBOKVLMOquDiO6TccKvykTxoBLsn8x0g3AqDoyNNvr8s0ABf/khU7Adyx3tqchXfUEXhROmtTabqCrO8nmTQtwwwfNTo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=pGy0NHHU; arc=none smtp.client-ip=209.85.208.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-2d4141c4438so61599581fa.3 for ; Mon, 11 Mar 2024 01:44:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1710146643; x=1710751443; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=7eBCaB1KJSJv4nuU5XUfD5CciJ2EmxrAEpbHEbAM5m0=; b=pGy0NHHUVeP57AriTAZK9diNpUQ/NMyuwd6NA72PeAES3sKCHUakG4pmuCor+YIAiZ meEs827GLxvF2dHSFPven9FDjYykUiakFDAGbriOt4G5xMIIMghUEAKCCrPeJJZH4jiN ciN6IOBaeULL3NwohL0z8LE9mHpOmyr9gJ8rICFJGshu+BkJU++FTZANxcXUI4EDvVhB cdLcKizvC0PijBrYiPHSOh0QYIvmZM3bYwNWgRVvLU1HYoUZRqzCTTrm+FD3P1cG5Mjx 3hijAaX3Fb454lU749+4PSp7HmbwLZHpG12pn+CRB3VPJ6l6xK+raMz2V53BKPEBDxi5 kYiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710146643; x=1710751443; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7eBCaB1KJSJv4nuU5XUfD5CciJ2EmxrAEpbHEbAM5m0=; b=SFJ/zhnJSxIcxxvSHHzzE0Eoro+eXS6weh32pXUwB22RE2mqWI255SIPDqxlhjTBQy lm1HUxOH6pXhZczvbt7tWmhe/2cbwv1dlVzn5HbsvdGeXwmpj31dEiHYU6mvA/qrAx0Y kHBMAv0QB32Dl0ZdjiOlyLtlyqw4U2h2SJdGvXlMbqIMYw8syM5TSN7embmN0r3qVkVL hRv6ZVZt/P6givLVcBgEE44g5VcRH1CXfI8tL/J3WRlndkWw063G787qTQTsk2gzIfIc WIZ70mJwUkW1FB5IexPtvcjDc6hV8aY1uqBUXcEL4oqCbvucvip3iSmqoHDplXzQrOy9 WHhw== X-Forwarded-Encrypted: i=1; AJvYcCX0rsl9b6mAjiXjmcq6l/WUKgywvbyLsZguGz/7/Mh9N/3ilb4gpIQ/R+2LU8N1Z6LWjlw9/6IbryHj0dAb3HSiqgaRJM4H7em5aDRw X-Gm-Message-State: AOJu0YzYhDVxsHwIzDTwH4WaXkMK1nu/IqZFgqlwnmoGhcTlAqH47oqY C/oFLSU0wZuarp/md/aaaCM+lSY8HdXPvFlawH/om2bXcYae1v8ga4Z+rR0Lh3NwLgcRCRfiJLC wkR5DnmnWoK3T5FtQazk8HzgAsQrnaUWItyMH1Q== X-Received: by 2002:a2e:850e:0:b0:2d3:982d:aaee with SMTP id j14-20020a2e850e000000b002d3982daaeemr3258850lji.16.1710146642679; Mon, 11 Mar 2024 01:44:02 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240308152723.831620-1-dtatulea@nvidia.com> In-Reply-To: <20240308152723.831620-1-dtatulea@nvidia.com> From: Ilias Apalodimas Date: Mon, 11 Mar 2024 10:43:26 +0200 Message-ID: Subject: Re: [PATCH net v3] net: esp: fix bad handling of pages from page_pool To: Dragos Tatulea Cc: almasrymina@google.com, Steffen Klassert , Herbert Xu , "David S. Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Matteo Croce , leonro@nvidia.com, gal@nvidia.com, stable@vger.kernel.org, "Anatoli N . Chechelnickiy" , Ian Kumlien , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Dragos, On Fri, 8 Mar 2024 at 17:27, Dragos Tatulea wrote: > > When the skb is reorganized during esp_output (!esp->inline), the pages > coming from the original skb fragments are supposed to be released back > to the system through put_page. > But if the skb fragment pages are > originating from a page_pool, calling put_page on them will trigger a > page_pool leak which will eventually result in a crash. > Indeed if you call put_page, you will leak a page. But won't that skb eventually be freed by skb_free_head()? Thanks /Ilias > This leak can be easily observed when using CONFIG_DEBUG_VM and doing > ipsec + gre (non offloaded) forwarding: > > BUG: Bad page state in process ksoftirqd/16 pfn:1451b6 > page:00000000de2b8d32 refcount:0 mapcount:0 mapping:0000000000000000 in= dex:0x1451b6000 pfn:0x1451b6 > flags: 0x200000000000000(node=3D0|zone=3D2) > page_type: 0xffffffff() > raw: 0200000000000000 dead000000000040 ffff88810d23c000 000000000000000= 0 > raw: 00000001451b6000 0000000000000001 00000000ffffffff 000000000000000= 0 > page dumped because: page_pool leak > Modules linked in: ip_gre gre mlx5_ib mlx5_core xt_conntrack xt_MASQUER= ADE nf_conntrack_netlink nfnetlink iptable_nat nf_nat xt_addrtype br_netfil= ter rpcrdma rdma_ucm ib_iser libiscsi scsi_transport_iscsi ib_umad rdma_cm = ib_ipoib iw_cm ib_cm ib_uverbs ib_core overlay zram zsmalloc fuse [last unl= oaded: mlx5_core] > CPU: 16 PID: 96 Comm: ksoftirqd/16 Not tainted 6.8.0-rc4+ #22 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.13.0-0-g= f21b5a4aeb02-prebuilt.qemu.org 04/01/2014 > Call Trace: > > dump_stack_lvl+0x36/0x50 > bad_page+0x70/0xf0 > free_unref_page_prepare+0x27a/0x460 > free_unref_page+0x38/0x120 > esp_ssg_unref.isra.0+0x15f/0x200 > esp_output_tail+0x66d/0x780 > esp_xmit+0x2c5/0x360 > validate_xmit_xfrm+0x313/0x370 > ? validate_xmit_skb+0x1d/0x330 > validate_xmit_skb_list+0x4c/0x70 > sch_direct_xmit+0x23e/0x350 > __dev_queue_xmit+0x337/0xba0 > ? nf_hook_slow+0x3f/0xd0 > ip_finish_output2+0x25e/0x580 > iptunnel_xmit+0x19b/0x240 > ip_tunnel_xmit+0x5fb/0xb60 > ipgre_xmit+0x14d/0x280 [ip_gre] > dev_hard_start_xmit+0xc3/0x1c0 > __dev_queue_xmit+0x208/0xba0 > ? nf_hook_slow+0x3f/0xd0 > ip_finish_output2+0x1ca/0x580 > ip_sublist_rcv_finish+0x32/0x40 > ip_sublist_rcv+0x1b2/0x1f0 > ? ip_rcv_finish_core.constprop.0+0x460/0x460 > ip_list_rcv+0x103/0x130 > __netif_receive_skb_list_core+0x181/0x1e0 > netif_receive_skb_list_internal+0x1b3/0x2c0 > napi_gro_receive+0xc8/0x200 > gro_cell_poll+0x52/0x90 > __napi_poll+0x25/0x1a0 > net_rx_action+0x28e/0x300 > __do_softirq+0xc3/0x276 > ? sort_range+0x20/0x20 > run_ksoftirqd+0x1e/0x30 > smpboot_thread_fn+0xa6/0x130 > kthread+0xcd/0x100 > ? kthread_complete_and_exit+0x20/0x20 > ret_from_fork+0x31/0x50 > ? kthread_complete_and_exit+0x20/0x20 > ret_from_fork_asm+0x11/0x20 > > > The suggested fix is to introduce a new wrapper (skb_page_unref) that > covers page refcounting for page_pool pages as well. > > Cc: stable@vger.kernel.org > Fixes: 6a5bcd84e886 ("page_pool: Allow drivers to hint on SKB recycling") > Reported-and-tested-by: Anatoli N.Chechelnickiy > Reported-by: Ian Kumlien > Link: https://lore.kernel.org/netdev/CAA85sZvvHtrpTQRqdaOx6gd55zPAVsqMYk_= Lwh4Md5knTq7AyA@mail.gmail.com > Signed-off-by: Dragos Tatulea > Reviewed-by: Mina Almasry > Reviewed-by: Jakub Kicinski > --- > Changes in v2: > - Fixes in tags. > > Changes in v3: > - Rebased to ipsec tree. > --- > include/linux/skbuff.h | 10 ++++++++++ > net/ipv4/esp4.c | 8 ++++---- > net/ipv6/esp6.c | 8 ++++---- > 3 files changed, 18 insertions(+), 8 deletions(-) > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > index 2dde34c29203..d9a1ccfb5708 100644 > --- a/include/linux/skbuff.h > +++ b/include/linux/skbuff.h > @@ -3448,6 +3448,16 @@ static inline void skb_frag_ref(struct sk_buff *sk= b, int f) > > bool napi_pp_put_page(struct page *page, bool napi_safe); > > +static inline void > +skb_page_unref(const struct sk_buff *skb, struct page *page, bool napi_s= afe) > +{ > +#ifdef CONFIG_PAGE_POOL > + if (skb->pp_recycle && napi_pp_put_page(page, napi_safe)) > + return; > +#endif > + put_page(page); > +} > + > static inline void > napi_frag_unref(skb_frag_t *frag, bool recycle, bool napi_safe) > { > diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c > index 4dd9e5040672..d33d12421814 100644 > --- a/net/ipv4/esp4.c > +++ b/net/ipv4/esp4.c > @@ -95,7 +95,7 @@ static inline struct scatterlist *esp_req_sg(struct cry= pto_aead *aead, > __alignof__(struct scatterlist)); > } > > -static void esp_ssg_unref(struct xfrm_state *x, void *tmp) > +static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buf= f *skb) > { > struct crypto_aead *aead =3D x->data; > int extralen =3D 0; > @@ -114,7 +114,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void = *tmp) > */ > if (req->src !=3D req->dst) > for (sg =3D sg_next(req->src); sg; sg =3D sg_next(sg)) > - put_page(sg_page(sg)); > + skb_page_unref(skb, sg_page(sg), false); > } > > #ifdef CONFIG_INET_ESPINTCP > @@ -260,7 +260,7 @@ static void esp_output_done(void *data, int err) > } > > tmp =3D ESP_SKB_CB(skb)->tmp; > - esp_ssg_unref(x, tmp); > + esp_ssg_unref(x, tmp, skb); > kfree(tmp); > > if (xo && (xo->flags & XFRM_DEV_RESUME)) { > @@ -639,7 +639,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_b= uff *skb, struct esp_info * > } > > if (sg !=3D dsg) > - esp_ssg_unref(x, tmp); > + esp_ssg_unref(x, tmp, skb); > > if (!err && x->encap && x->encap->encap_type =3D=3D TCP_ENCAP_ESP= INTCP) > err =3D esp_output_tail_tcp(x, skb); > diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c > index 6e6efe026cdc..7371886d4f9f 100644 > --- a/net/ipv6/esp6.c > +++ b/net/ipv6/esp6.c > @@ -112,7 +112,7 @@ static inline struct scatterlist *esp_req_sg(struct c= rypto_aead *aead, > __alignof__(struct scatterlist)); > } > > -static void esp_ssg_unref(struct xfrm_state *x, void *tmp) > +static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buf= f *skb) > { > struct crypto_aead *aead =3D x->data; > int extralen =3D 0; > @@ -131,7 +131,7 @@ static void esp_ssg_unref(struct xfrm_state *x, void = *tmp) > */ > if (req->src !=3D req->dst) > for (sg =3D sg_next(req->src); sg; sg =3D sg_next(sg)) > - put_page(sg_page(sg)); > + skb_page_unref(skb, sg_page(sg), false); > } > > #ifdef CONFIG_INET6_ESPINTCP > @@ -294,7 +294,7 @@ static void esp_output_done(void *data, int err) > } > > tmp =3D ESP_SKB_CB(skb)->tmp; > - esp_ssg_unref(x, tmp); > + esp_ssg_unref(x, tmp, skb); > kfree(tmp); > > esp_output_encap_csum(skb); > @@ -677,7 +677,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_= buff *skb, struct esp_info > } > > if (sg !=3D dsg) > - esp_ssg_unref(x, tmp); > + esp_ssg_unref(x, tmp, skb); > > if (!err && x->encap && x->encap->encap_type =3D=3D TCP_ENCAP_ESP= INTCP) > err =3D esp_output_tail_tcp(x, skb); > -- > 2.42.0 >