From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (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 ACA4344210C for ; Fri, 31 Jul 2026 15:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785512713; cv=none; b=ZF3EA/Dr50gRZ0GWcBVmbIWqXhHJlADV5cKxBlWoEZnUX1nE03PcSKMbp0qErMBEcyYBBSMGM+forpPs9dSYg1pZK7xhFKRBCozDSxMSzCHEfQ3tBYAqL84DwFrUAM/pthwOD8G5Nmgy0mJtr4mp/0yyIQrQPOrqqfgaWsBTRX4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785512713; c=relaxed/simple; bh=QljyVPFlAv4h/ZzcE8C+5GE8/id8T+aE6aMhZzBAF/Y=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mtbtHGhVSJw5ByYiqYd9S21neDJ4PRbniRB4/pstvU8y8oiltWgSJd+Gs+9VWxEWEVE3SgKkmqbW8XqCJrQa2vFEQ5MXnLch3SQM0dTnjZgxry/ommNIaR9VpyZtOG+m+V+O0d9uFaTIjQqVwoeNbFXnyZTDgHtin+8YOUaZoK8= 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=n3QvJhLH; arc=none smtp.client-ip=209.85.215.180 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n3QvJhLH" Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-c9e607d81fcso651351a12.2 for ; Fri, 31 Jul 2026 08:45:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785512712; x=1786117512; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=tTr+FVEJek8HJ3HeYCgl63RHoNH7nCzt1TWIIYAYrB0=; b=n3QvJhLHSax0EIgAg31zVsyiaA3GFTOThr/sKnIwk1AlNJYzy703rz1ByL5pGsEAAb KnZNUfLuX28RGcJq3klfQbDv+JPv7DUVp0L83hTf/3o992ceY4u/wQo3H5vOr0f2IH18 G0h1/U7AIBhqotS6F2zMBzIhCCFUugoMc5L0S4uSBe6PPL6XReLHlCwndBE+21iXW4YZ SHaU3OnRa70Qfkcg/aadOPBOhtqOh6IBWEpKKM844v0RUR8DY81ig7B7mZqk4yeB0d5X hXGSY41kXXDS0RyvRvgEIV3pWLYXfsB4AAr79YNlqOTBYhAOxTzep2yj9yWU6Y9UFn8v w/3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785512712; x=1786117512; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tTr+FVEJek8HJ3HeYCgl63RHoNH7nCzt1TWIIYAYrB0=; b=qqxynMn3KoxJ3IQ6FeaKFlhgvKT40bQRKQyYv2x0cleutNC5m66p17tC8zV7z/LVrH vyEjvraEFmIqVcTWq4a4ds1rjSjPMZ65jUg+5GR53i11OLmvkF7n3WCjJY3G8Taj36t7 8dU5y33OL8CiNRcLmAurgo5beIA1Se9jizVy9A2AkqiC1lMWzZ4Ml8u56OERSi9UYDsC ZXTACZGPRgYPhR3UzuO1fNxTbSWGshCi1E8QWTfaLHjt2pUt19owvCApnoOB4yGuxIkB E9NaWexMetJvttLYr49/RqYjHwq5R8ko/WjUlGETNeFbliidr7G8WfDMksNVxZu7tDph SX2w== X-Forwarded-Encrypted: i=1; AHgh+Ro0vo/ds7npLN3LpGPH44KwVOIjBNcnDmtuVdyJn8BN/x8q7j1f/AmMIseTnpB/UsZslJ/0qdE1TTVmTaA=@vger.kernel.org X-Gm-Message-State: AOJu0YzHrwnTKQgdmtQKhyfjzFZ45QEVq/czXpeS95PE9OJL3VfHd5mB UUkI+3ReItIz/ow8ioL9uhoskPoX+bdQwbcN2gxLl7664mgP0rMN3XYy X-Gm-Gg: AR+sD11+kOSs+iyB/6clEozs31c1LRZDAGhEq1cplctoX/MpijH6PKbjtHJsrcsBXEL TRzGtKN7BW32urYxCDN/bvL4ocfCHviG9gp9sS0c0V3Unba8pDehhazUo3KDVNcHFQuE3g9ssn6 Mk8vMsZ3JRgY1Yy8Hjqm3EpIuosKPCRxZbF2hkIBRu0wFqiNQhPO3nLCQdojpE8f4pFj/gxr2LK Sh1ccrR79Hm7+77KYTycod31coJa1tlD+3BJggAWdI/7z7ieMgZSTtbf6FwaYIQVcnygljb9A3J ++PWEg8QBLPvrP2VBBmo419p+qCdqipo/rzx3QHrFGxPIETrxP/WHKVwuo/KPmln2vVIo642QOE yMvM1DdFf2uEZwROo85XnvfLKUwFMaHXb2VRBcORDtNazoI+PJvQQvM6xc8ifV5Otvx7mtNNPxl Lrq24hfJNfokBNQTNixY2ZNX1bgsq9NsjRYH5/kLTCPxfR9A2mG/wfR5SWdjU0wLbcdaFC70mUD M5NCtu7iDhS+KnFdViJ/W01TtDAdjDhNXEnyIbD7kIH0bd1YLeo29o/2qE= X-Received: by 2002:a05:6a20:6a21:b0:3b4:5ff3:45cb with SMTP id adf61e73a8af0-3c92a75b25cmr258440637.8.1785512711706; Fri, 31 Jul 2026 08:45:11 -0700 (PDT) Received: from ?IPV6:2601:646:8f02:5350:ce4:701d:f6e3:3a6b? ([2601:646:8f02:5350:ce4:701d:f6e3:3a6b]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e29a126sm7821146eec.31.2026.07.31.08.45.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 31 Jul 2026 08:45:11 -0700 (PDT) Message-ID: <6fe86a50-34ec-45aa-b2b4-52429a72369c@gmail.com> Date: Fri, 31 Jul 2026 08:45:09 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net v2 1/2] net: fix skb length accounting after generic XDP frag adjustment To: Sun Jian , netdev@vger.kernel.org Cc: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Kuniyuki Iwashima , Hangbin Liu , Krishna Kumar , Samiullah Khawaja , Martin Karsten , Lorenzo Bianconi , =?UTF-8?Q?Toke_H=C3=B8iland-J=C3=B8rgensen?= , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, maciej.fijalkowski@intel.com, stable@vger.kernel.org References: <20260731032357.6114-1-sun.jian.kdev@gmail.com> <20260731032357.6114-2-sun.jian.kdev@gmail.com> Content-Language: en-US From: Mohsin Bashir In-Reply-To: <20260731032357.6114-2-sun.jian.kdev@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/30/26 8:23 PM, Sun Jian wrote: > Generic XDP exposes non-linear skb fragments through an xdp_buff. If an > XDP program adjusts the fragment area, bpf_prog_run_generic_xdp() copies > xdp_frags_size back to skb->data_len but leaves skb->len containing the > old fragment contribution. > > After a fragment shrink, this makes skb_headlen() larger than the actual > linear area. In the reproduced UDP receive path, __skb_datagram_iter() > copied 1024 bytes past the actual linear tail to userspace, starting at > struct skb_shared_info. The copied bytes included the affected skb's > nr_frags, xdp_frags_size and a kernel pointer from > skb_shinfo(skb)->frags[0]. Real packet data was displaced by the same > amount and truncated at the end. > > Subtract the old data_len before replacing it and add the new data_len > afterwards, keeping skb->len and skb->data_len synchronized. > > A 60000-byte UDP datagram on a veth pair with MTU 64000 was shortened by > 1024 bytes from its fragment area. Before the fix, all 10 runs produced > corrupted payloads. After the fix, all 10 runs matched the expected > payload exactly. > > Fixes: e6d5dbdd20aa ("xdp: add multi-buff support for xdp running in generic mode") > Cc: stable@vger.kernel.org > Link: https://lore.kernel.org/bpf/al9T9Eto%2FhRIzP5W@boxer/ > Signed-off-by: Sun Jian > --- > net/core/dev.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/net/core/dev.c b/net/core/dev.c > index 5933c5dab09e..5c37cf6c4aa1 100644 > --- a/net/core/dev.c > +++ b/net/core/dev.c > @@ -5517,12 +5517,16 @@ u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp, > } > > /* XDP frag metadata (e.g. nr_frags) are updated in eBPF helpers > - * (e.g. bpf_xdp_adjust_tail), we need to update data_len here. > + * (e.g. bpf_xdp_adjust_tail). Remove the old fragment contribution > + * from skb->len before updating data_len, then add the new one back. > */ > - if (xdp_buff_has_frags(xdp)) > + skb->len -= skb->data_len; > + if (xdp_buff_has_frags(xdp)) { > skb->data_len = skb_shinfo(skb)->xdp_frags_size; > - else > + skb->len += skb->data_len; > + } else { > skb->data_len = 0; > + } > > /* check if XDP changed eth hdr such SKB needs update */ > eth = (struct ethhdr *)xdp->data; Reviewed-by: Mohsin Bashir