From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796092323; b=zHuwvLnkHAjzD+509aGeoy5HJxuOYry3q2F1ZPJc79KsH1Zrl5fK5LtotToQCqxs1mDZ RTgCPW8NdKdaFij028TeFxVGU2kMGrsOb547CHW9s6DAwDIcyzz8tRcgd8GpcXW6M8CmZ 5hqL7EFdBumgRM7IiuMQFdFyBTePnrvutUgorhgRhA3fkxtgtyCP7OOs0E6XlWZONR2nI kBahq4HZULnbiqrLO5BaCd2jvZKshFcG+yhK2MtyF1N3vvK5/uWjg3f4wYm5evazDeDGl bLgvB83CfUPRS0NFM4wAxNOUl8qD+t9WhWFJUsIDDv+KUrX2qE9HCmKZMoCpGizfe5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796092323; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=bi7xSY6U9lLDmEWKpGM05Qk4BfCFcugHV6Iic95Z5Wo=; b=wAV4K/VdfOnuyAC2pZD4J/KZ/nP8w0WFwbD76RuMtN+a8M1Wnm3bnHNj4XiQ3tG5cuAW 0tjtmWQk0lCkf6pYH8VTt25wxWBFMwG6VMKvkFUK8GBihrbZoPs1BZ2GixjyrK2VFij20 lYREpVk5hf2IhZESNTCANVRO5qC1SUYtfKHz/T8/xWaJtt4bjcHq7ku10gcy+w4Kkpr/Y 9L5GFV74MK0mwXihqNchdQNueNjiWBcMN54tiZC61V/RNYccoX+9a4zey2uXnxGcmXYYk /XbyAhJoPXIkOB45BlNfWU7gYMRWopZa4BKqB4fqog9y1x96uiBliKgzqhBKspf0drQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IL9amOVb; arc=none smtp.remote-ip=209.85.160.200 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82F97606A31A for ; Tue, 1 Dec 2026 02:32:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82F97606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--willemb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=IL9amOVb Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-544019b1831so202888261cf.0 for ; Mon, 30 Nov 2026 18:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796092322; x=1796697122; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=bi7xSY6U9lLDmEWKpGM05Qk4BfCFcugHV6Iic95Z5Wo=; b=IL9amOVbT/KOO13RZKYa4cKik0DU5Wf3tvDvhfnI4hcqm2IO7h0xiXUJ6N85SqEp65 cgl1nn/zaVWxvZMmWyUfPBrPD61Xg5bB2WrCyZiV5eovgHMx1wla8/8A70sP2ncOhVG5 DhCKERSK4QB3Iw51BAtbc1Fm8mcU1CfEvuR/n57rsf15JpYPKNCivldWEcXHzDLZ23uh 3CKyvx9OG36h6hY40V7IEZc+o19Y1WrDS087+VV9kjXhJG+DQswBbvNtTxljzE7kMzZC S7svQcc4ODo2EVqkkmGgrJ1Ov7b38fcUeHGgRK6+4iR/mXMoGwZ6PWpdahwYY2M6mK7h HDMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796092322; x=1796697122; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bi7xSY6U9lLDmEWKpGM05Qk4BfCFcugHV6Iic95Z5Wo=; b=NN9fxTWAQQ0XYMdmoSsMH/617Y4ieYnVR4xanKnpQiYqwSmFPQvLC2R8eXzTq3U/T5 iz5e9XenCy2452X6PFKL4jIxfy46NIgJrJJPcGjriqw6Xsw/dyweN4z/4IWggS6GolEB Cu7HW/aUUfgtej/MNynw/P7nn3MziCuZtgObVBQWNGX11Nr2xeOK2ftKBaLZop3NYEdu SIrSKQpOGvjJzIu16srBH6scXGnmvJvLqU6vV6dGmFudWQbz+oVr2bjEX7nG8GA/DSW2 dAqYLu1Lf2g3mXtAHl3lvxlVtSnVmktXxu6rcYdcJF4T3v2CsSe4g0OwWt4QNhK8WuKv rVxg== X-Forwarded-Encrypted: i=1; AL+hErFWXIVNhWnHOhZZRWn8R+WGaBCAUC6CB1jpxGXfhTzk9jZlYzcPoGvAbE7pqxif33Jd6t1ufB1GjKsadsW60Bc=@vger.kernel.org X-Gm-Message-State: APuU4Z9h/iN1mac62WHwPn1LGwBP4VZ2XhL+M8M9eNgNbMbrwf2HFshf 6Yj9LuqxnRiDBDqI0Z47WpBxfK9tq2Al55gFwtLd2ziz1kAKBqTtYHmUcITBa+g2/ZJNGJHcXqG Qtygd7Pu7lw== X-Received: from qtxo6.prod.google.com ([2002:a05:622a:446:b0:536:7013:6443]) (user=willemb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:622a:1f13:b0:55b:df9e:369a with SMTP id d75a77b69052e-55d769940f8mr641887891cf.11.1796092322147; Mon, 30 Nov 2026 18:32:02 -0800 (PST) Date: Mon, 30 Nov 2026 21:32:01 -0500 In-Reply-To: <20261124163358.755345-3-theodorlarionov@gmail.com> X-Mailing-List: netfilter-devel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 References: <20261124163358.755345-1-theodorlarionov@gmail.com> <20261124163358.755345-3-theodorlarionov@gmail.com> Message-ID: Subject: Re: [PATCH net v3 2/2] net: unset the mac header of a pskb copy that points into headroom From: willemb@google.com To: Theodor Arsenij Larionov Trichkine , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Simon Horman , Pablo Neira Ayuso , Florian Westphal , Phil Sutter , netdev@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, Theodor Arsenij Larionov Trichkine Content-Type: text/plain; charset="UTF-8"; format=flowed; delsp=yes Theodor Arsenij Larionov Trichkine wrote: > __pskb_copy_fclone() copies the data from skb->data onwards but keeps > the mac_header offset, so if the link-layer header was pulled, the > copy's mac header points into uninitialised headroom. With nft dup, a > link-layer payload load on the copy at LOCAL_OUT or POST_ROUTING reads > those bytes, and a set element hands them to userspace: > BUG: KMSAN: kernel-infoleak in _copy_to_iter > Unset the mac header in that case. Callers that use the copy's mac > header push the link-layer header before copying, as > maybe_deliver_addr() in the bridge does, so the header is copied and > stays valid. > Depends on "netfilter: nf_dup: do not duplicate packets from > br_netfilter"; without it, a tcp reset reject of a bridged dup copy > reads out of bounds. > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Suggested-by: Florian Westphal > Cc: stable@vger.kernel.org > Signed-off-by: Theodor Arsenij Larionov Trichkine > > --- > net/core/skbuff.c | 2 ++ > 1 file changed, 2 insertions(+) > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 85d5caa08887..e38d0de59e06 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -2278,6 +2278,8 @@ struct sk_buff *__pskb_copy_fclone(struct sk_buff > *skb, int headroom, > } > skb_copy_header(n, skb); > + if (skb_mac_header_was_set(n) && skb_mac_offset(n) < 0) > + skb_unset_mac_header(n); skb_copy_header() copies skb->mac_header verbatim without adjusting for (headroom - skb_headroom(skb)). If a caller invokes __pskb_copy() with headroom < skb_headroom(skb) on an skb whose MAC header was pulled into headroom (skb_mac_offset(skb) < 0), skb_mac_offset(n) = skb->mac_header - headroom can be >= 0, leaving n->mac_header set and pointing at an arbitrary offset inside n->data (or even past n->tail/n->end). Checking (skb_mac_offset(skb) < 0 || skb_mac_offset(n) < 0) handles both cases: it unsets mac_header whenever the source MAC header was not copied (skb_mac_offset(skb) < 0) as well as when a larger headroom leaves the unadjusted offset in n's headroom (skb_mac_offset(n) < 0). > out: > return n; > } > -- > 2.34.1