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=1796092324; b=XVOsIeRYJ/dnEZK3hTN5weqVEUyphCOoLQlavk4y2ECni5STJHmr9aKRoNFlKf60viDv vR7z7adgi2+QwRh9PLqZkpBzVava0GFJzaVEBFr+Q2kBDfs7XpF+mlMxutRtzfvEbE3Yl ppeOcQlPE1TnXJXiJUOvcc0rNuvp/+q2Tsc9WycmOjQMIPq4iGbyAYanbw8wVDW4KWhMs Q7/hqjjuo9dkCNL/lnwq3sibgRNgVRxiH52XYvdISJMW3tnWf46EXJJwesHOeRRBSEs0i yOlKTBeBCXCe75SF4TaK5z6b1LmPufZbGp+kfvUpbjdV4Ld8fHSkXLMFwV1W8Icn0hA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796092324; 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=FejeoQDUSWr/kOwlJNFyuboCVX8PwCHP8X8eP3i1dawPlY62qpnuiynjQH8ytriBtdql PdeR67Inx1Jg/BKANClOUDWTDHxW6qzsLqE5eSN9LV2Q4+NpvKqYl0JmmdHhnfW3zjOmB AHo1eC1+hk07Y/XVKzyWo3oAEag0B/Osh1FBPW2kn9wAehT0dY+1ZjwQ/PojGm2Ah1Q5A mra7YPTwWbxBPdeHQo6WEfT1qcQtoMOxrOIW0qOAJUJBiESNRlAHDLnUOWM6yTBTDF5ty Tc7yAFtagCbWV581lr/8DzlMn6XG40z8L3LJB4Xroca8u7sRAyFal4eANXXvn97JTLw== 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 83044606A320 for ; Tue, 1 Dec 2026 02:32:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 83044606A320 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-5363b06bcb2so210524551cf.2 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=lLpIo/4HSKnzlNjqMhU3SHYjXHZkeUK9n/FM6tox/ZwkQO24ekJQCbZ5nhlhs42WMX +MyjUJMRA22HdUSchyhJhviBu0zpRZUaVaZeaXnyT3EG717mmQhXipWy3qp2SRmk1xSr wc528aoDT3NBElbBASPAG5Gz576kDrIqR65IOKhQ1ywXjUf/gVwzQb5+NoN8mgaCwGul COiB43+T/zpWXQ+Cx0RdZm2eYxuV7wnOpj1WPcsJuhWXAkm5y5PDROkc2wEyVyUn0AdO 3I3F3Gx/XqA2E8Xms6Jt09d95Ss1gJxlegdATXbDoMCkw4VyYwtq/xd3+PbXgMDUCJY2 rbpw== X-Forwarded-Encrypted: i=1; AL+hErEcnagkjGUcTeeHi0rCSSl6R5lavorm+P7NL5SjgpwTJJ9GnsuayiTHYyVXfthdVh4bKfhr9lY=@vger.kernel.org X-Gm-Message-State: APuU4Z81JkvgncBJcUtvFKwH4XUvSJF4QDryusWYNlEZMyd9xTf7VRlz 8wYde0t/EceXjhCLrQBjL3VVBd6bHqQRefUrrd6wNUWJjBt8nOZnAOUBOyUIWF0emeL4Dj5pXX7 eqi7+8ETmNQ== 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: netdev@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