From patchwork Wed Sep 30 10:54:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joas Antonio dos Santos via B4 Relay X-Patchwork-Id: 2314340 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=IVHhTOpJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netfilter-devel+bounces-15825-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4hw7zP5wDxz1xxW for ; Thu, 01 Oct 2026 07:51:29 +1000 (AEST) Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 67A84105A7A for ; Wed, 30 Sep 2026 20:54:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D209151AFD6; Wed, 30 Sep 2026 20:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IVHhTOpJ" X-Original-To: netfilter-devel@vger.kernel.org Received: from mail-dl2-f42.google.com (mail-dl2-f42.google.com [74.125.229.170]) (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 E19993AFAE2 for ; Wed, 30 Sep 2026 20:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790801671; cv=none; b=brR0M/vLtEnMnU+eyQRS02wCEDH3jQTjFF72ylwHAm1mMeBtfZYKcun/YYkJXq1Z9EswcDNICHXo1XGLtp7P1+XfO7MjNj9EUiEiXtb/EwoXplHKFIF8qiXGa2/tX2aGI/5zKXjyD4c+Ow23Jh+my2lvl5u7QIV0584/VUZYGgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790801671; c=relaxed/simple; bh=y4Sk1wA98XLUzK3+joRGJ/eDky8yOQE1aiwrdJivQ/s=; h=Message-ID:Date:Content-Type:MIME-Version:From:To:Cc:Subject; b=GEZQ3o/RFajCcs6+HP4+cPdk4AqmVS006nkChL5D4R1uw8zrPhOWXah0g6n0YLW/O+epBWrpnoC0q9M4O9JwDlZR0F/zfJg3xzKkK2pSJ4lxuj2cFKFfhh9fYyvMa3tPKdLyiL5bFQlDapomL+hgohcSeyVwPXpcf6m/rjuI3lA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IVHhTOpJ; arc=none smtp.client-ip=74.125.229.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-dl2-f42.google.com with SMTP id a92af1059eb24-144f47a9b57so5358796c88.2 for ; Wed, 30 Sep 2026 13:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790801669; x=1791406469; darn=vger.kernel.org; h=subject:cc:to:from:content-transfer-encoding:mime-version :content-type:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=y4Sk1wA98XLUzK3+joRGJ/eDky8yOQE1aiwrdJivQ/s=; b=IVHhTOpJbAVJyySm9Ru+NHtGoiBsOh1kFw6f2IFSY7DrpfF+Fz0GfR1VjOMv0hkDem okJYtjI8L27fZAMTlhRfFswg2eNPnrG1MV5Ed59mSloKRIB45mzec7o7+7mUwZdYsOew +F/s9QpifRSOZUMLPGet2aMvKaTvuQ8fo/6wuxMYLEZSz+dZu/2gwMk0CUVbOD1egrbo VnUAl9d06uoSjSoHoDfevg/eWnQQu5SkZ5NMmnNukNIzD2ATtF0f0ZPORz86yaK/2AZc WuIlvnILYt4qwtsPDDsjmeGcsEC+eGnO6d8GQEYJ2vbWd9LGF1aCG9LhTcdzsZGH93Qg SEdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790801669; x=1791406469; h=subject:cc:to:from:content-transfer-encoding:mime-version :content-type:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=y4Sk1wA98XLUzK3+joRGJ/eDky8yOQE1aiwrdJivQ/s=; b=C5Dd29dB1a5B0SRwbk5ql1DoEJjV68XXMCsJtAjfMJJIgJtxrZdN6Rs2s8RUtT+cWf 0rHBDD/iuLUSCbf5PTzq4sy8lylR5pvCTG4rJXEGFQ930JJvfmK/hRzFvaLoTqsBKTrh Jm+oYZ6m9My0FfC0kN+LnPkg5vj44qdui4Pyf7GYViBHyNjbFNABOvCd9st+orntQgbF A4FQwD3zHZgUMGjRmVihvIYl75FSLldTZLMHjrcBJJJ4Yx4c+e3emu8mpGpvokDHIMI/ t1RMH2iZhhT4Zjxf5zb0WICC4QZSKTNL/aAWf7bn8chcO4XkWETgNCHbAIIUWkcqONTy pUxg== X-Gm-Message-State: AFuF++k42nIW4f+lv7vKPEp9YTA46oAe/WCuLtaZh7kza1n9WIaLQ/Mc 8kdduEG9SvWxoVkJ7BPvtrHiWDjszJQYH9CvKpZMTdytyY/2DZ3HHLYF/oiNfLC6Hm6ZNZc3 X-Gm-Gg: AYBFou0sU6t3sh8W0cTrEx9ogyXY36WiRGqiPaWiFkH9SA80yJsyyzNT57aBZ3ZCvpr txWyi5oOmoi+Iw2zr48l15T46aUYNJ7z3EYqJcAg7GMNK2UzqgIgQB4OiOslCxoLwZ+Plzkiao7 wC2pE5XDsrczw+J5QB/kCSEaAKTAbKXppTotnlwWI8Yg036o4hxIycPe26JaLFskSdK6LwhcZdx MtSbS8rd+DVq4keYcz++IPebShEqB8BseNNV4Ot9qDOB213us9ICvTZbMhl1Q1k33PT4+lqBVkU 1EIir/RaTzn3qJJItD83CCskVIxSlVstA3UjIlBgv++Iu9I33gOsxkxBgKY8xRjj62Z8E6by/FF MWLuQOt7feKjZuTqVNpPsnMB2iILBJ/29De6N/fVvzLocDs7f6F9ms+cBPNRbac0bFU1f3OdRA8 14Wl3+JL3QxaRwqTWDYQ9AG4DDhenY6lONRUirw1a+qZ3Lhxx0efhFy9LbbQkWUp/LGUE32nWxP u5OOpt6WQ2i4/P26jCfuqd9zWw2Be166BQXccOBh1zt3oqw2fBfTOnhGc261oOnooM1g8mjX58b kWxzaFW1mFrPbHj1p5xL5+iX7fSC+/jbT+iyaMS6QdJRDyWyrppMCCeP7ls= X-Received: by 2002:a05:701b:2505:b0:146:606e:2117 with SMTP id a92af1059eb24-14d2f7e6e77mr2980025c88.5.1790801668670; Wed, 30 Sep 2026 13:54:28 -0700 (PDT) Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa ([2804:7f0:b103:90e6:2458:51e7:ee0:38f9]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-14df44d4f00sm983983c88.14.2026.09.30.13.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 13:54:28 -0700 (PDT) Message-ID: <6abd7704.018c0331.32b1f7.c000@mx.google.com> Date: Wed, 30 Sep 2026 13:54:28 -0700 (PDT) Precedence: bulk X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Joas Antonio To: netfilter-devel@vger.kernel.org Cc: pablo@netfilter.org, fw@strlen.de, coreteam@netfilter.org Subject: [PATCH nf-next v2] netfilter: ip6t_NPT: ensure skb is writable before header modification ip6t_snpt_tg() and ip6t_dnpt_tg() modify the IPv6 source/destination address in-place via ip6t_npt_map_pfx() without first calling skb_ensure_writable(). When the skb is cloned (nflog, tee, multicast, tc mirred), the write hits shared data visible to other users of the same buffer: if (!ip6t_npt_map_pfx(npt, &ipv6_hdr(skb)->saddr)) ... ip6t_npt_map_pfx() does the actual in-place modification: addr->s6_addr32[idx] &= mask; addr->s6_addr32[idx] |= ~mask & npt->dst_pfx.in6.s6_addr32[idx]; Neither target checks writability first. Every comparable target in the tree does: ipt_ECN (line 32), ebt_dnat (line 24), ebt_snat (line 25), xt_TCPOPTSTRIP (line 52). Additionally, the ICMPv6 bounced header path uses skb_header_pointer(), which returns a pointer to a stack-local copy for nonlinear skbs. ip6t_npt_map_pfx() then modifies the copy; changes are silently lost and the inner IPv6 header in ICMPv6 error messages is never translated. Fix both by adding skb_ensure_writable() before each target function operates, and replacing the skb_header_pointer() + helper pattern with skb_ensure_writable() up to the inner header offset followed by a direct pointer. Remove the now-unused icmpv6_bounced_ipv6hdr(). Fixes: 8a91bb0c304b ("netfilter: ip6tables: add stateless IPv6-to-IPv6 Network Prefix Translation target") Signed-off-by: Joas Antonio --- Testing: verified with NFLOG + SNPT/DNPT rules on a namespace pair that cloned skb data is no longer corrupted after translation. Nonlinear-skb path confirmed by forcing GRO aggregation on the ingress side; inner ICMPv6 header now carries the translated prefix. net/ipv6/netfilter/ip6t_NPT.c | 66 ++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 29 deletions(-) + sizeof(struct icmp6hdr)); + ipv6_addr_prefix(&bounced_pfx, &bounced_hdr->saddr, npt->src_pfx_len); + if (ipv6_addr_cmp(&bounced_pfx, &npt->src_pfx.in6) == 0) + ip6t_npt_map_pfx(npt, &bounced_hdr->saddr); return XT_CONTINUE; } -- 2.43.0 diff --git a/net/ipv6/netfilter/ip6t_NPT.c b/net/ipv6/netfilter/ip6t_NPT.c index XXXXXXX..XXXXXXX 100644 --- a/net/ipv6/netfilter/ip6t_NPT.c +++ b/net/ipv6/netfilter/ip6t_NPT.c @@ -78,57 +78,65 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt, return true; } -static struct ipv6hdr *icmpv6_bounced_ipv6hdr(struct sk_buff *skb, - struct ipv6hdr *_bounced_hdr) -{ - if (ipv6_hdr(skb)->nexthdr != IPPROTO_ICMPV6) - return NULL; - - if (!icmpv6_is_err(icmp6_hdr(skb)->icmp6_type)) - return NULL; - - return skb_header_pointer(skb, - skb_transport_offset(skb) + sizeof(struct icmp6hdr), - sizeof(struct ipv6hdr), - _bounced_hdr); -} - static unsigned int ip6t_snpt_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ip6t_npt_tginfo *npt = par->targinfo; - struct ipv6hdr _bounced_hdr; - struct ipv6hdr *bounced_hdr; struct in6_addr bounced_pfx; + struct ipv6hdr *bounced_hdr; + unsigned int bounced_off; + + if (skb_ensure_writable(skb, sizeof(struct ipv6hdr))) + return NF_DROP; if (!ip6t_npt_map_pfx(npt, &ipv6_hdr(skb)->saddr)) { icmpv6_send(skb, ICMPV6_PARAMPROB, ICMPV6_HDR_FIELD, offsetof(struct ipv6hdr, saddr)); return NF_DROP; } /* rewrite dst addr of bounced packet which was sent to dst range */ - bounced_hdr = icmpv6_bounced_ipv6hdr(skb, &_bounced_hdr); - if (bounced_hdr) { - ipv6_addr_prefix(&bounced_pfx, &bounced_hdr->daddr, npt->src_pfx_len); - if (ipv6_addr_cmp(&bounced_pfx, &npt->src_pfx.in6) == 0) - ip6t_npt_map_pfx(npt, &bounced_hdr->daddr); - } + if (ipv6_hdr(skb)->nexthdr != IPPROTO_ICMPV6 || + !icmpv6_is_err(icmp6_hdr(skb)->icmp6_type)) + return XT_CONTINUE; + + bounced_off = skb_transport_offset(skb) + sizeof(struct icmp6hdr); + if (skb_ensure_writable(skb, bounced_off + sizeof(struct ipv6hdr))) + return XT_CONTINUE; + + bounced_hdr = (struct ipv6hdr *)(skb_transport_header(skb) + + sizeof(struct icmp6hdr)); + ipv6_addr_prefix(&bounced_pfx, &bounced_hdr->daddr, npt->src_pfx_len); + if (ipv6_addr_cmp(&bounced_pfx, &npt->src_pfx.in6) == 0) + ip6t_npt_map_pfx(npt, &bounced_hdr->daddr); return XT_CONTINUE; } static unsigned int ip6t_dnpt_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ip6t_npt_tginfo *npt = par->targinfo; - struct ipv6hdr _bounced_hdr; - struct ipv6hdr *bounced_hdr; struct in6_addr bounced_pfx; + struct ipv6hdr *bounced_hdr; + unsigned int bounced_off; + + if (skb_ensure_writable(skb, sizeof(struct ipv6hdr))) + return NF_DROP; if (!ip6t_npt_map_pfx(npt, &ipv6_hdr(skb)->daddr)) { icmpv6_send(skb, ICMPV6_PARAMPROB, ICMPV6_HDR_FIELD, offsetof(struct ipv6hdr, daddr)); return NF_DROP; } /* rewrite src addr of bounced packet which was sent from dst range */ - bounced_hdr = icmpv6_bounced_ipv6hdr(skb, &_bounced_hdr); - if (bounced_hdr) { - ipv6_addr_prefix(&bounced_pfx, &bounced_hdr->saddr, npt->src_pfx_len); - if (ipv6_addr_cmp(&bounced_pfx, &npt->src_pfx.in6) == 0) - ip6t_npt_map_pfx(npt, &bounced_hdr->saddr); - } + if (ipv6_hdr(skb)->nexthdr != IPPROTO_ICMPV6 || + !icmpv6_is_err(icmp6_hdr(skb)->icmp6_type)) + return XT_CONTINUE; + + bounced_off = skb_transport_offset(skb) + sizeof(struct icmp6hdr); + if (skb_ensure_writable(skb, bounced_off + sizeof(struct ipv6hdr))) + return XT_CONTINUE; + + bounced_hdr = (struct ipv6hdr *)(skb_transport_header(skb) +