From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89B713ACEFE; Mon, 17 Aug 2026 14:47:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978077; cv=none; b=E/E+ZfnfZw6nfUQxF0z1sP/xuTB469RlNRlA6U7Uq9ehqnbrCHFvt5ZmONNEuWKCHh2MuDLC3Pu7QDtl3M6blRN8sqCIxBkjbiEsCygYGrWHRWyZDwjeShP3iWpBQIahYa+sKf691zonppwQQA+EJWvqKzr8DBcDg7brmixGte4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978077; c=relaxed/simple; bh=lrTSFhpkLnJwvzAIJvzPMDRTji2BFLdj1SqYl6OtXbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ANFg3CDGHIzfUzQ71Lmg/HJFhtUu6EXyBLa7+v5J4Ikcg0RrtecUxmW3+HtME8HMEBNzEkuF/9ya4keZOg24ZJkVufv5COmz5q3T7RJH98VluHQieLVncGALBzM4/ChM0WzK1/6ivIB3SE/QJ+Sd4oGZ4/Dnw3kWzaDdzH8eE0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Uc2xvfIe; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Uc2xvfIe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF2811F000E9; Mon, 17 Aug 2026 14:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786978076; bh=HY6iHbNWJgcwF3Nlw5RWXFPBmheJS9PlLW7Ca5mguWs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Uc2xvfIeX6pQ0n/h0Ca1Z60lpVxRrVlX5/swLRjw2ijahQiIlaLpF9s8SCSYsf13O bYI1zANA9oqBQ3xmU/3w5fSpM8GxMAVS8vF/IdHJ0kvov3kE5Fs6BE1iiBmQtIHpMg 8TxA2Av54bxsemQN4NBpeBI0AgoGufQfBnEn610A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mohsin Bashir , Lorenzo Bianconi , Sun Jian , Jakub Kicinski Subject: [PATCH 6.12 094/181] net: fix skb length accounting after generic XDP frag adjustment Date: Mon, 17 Aug 2026 15:33:08 +0200 Message-ID: <20260817132539.152006661@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132535.394764707@linuxfoundation.org> References: <20260817132535.394764707@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sun Jian commit 33f2b2eb33d666ecac68031e0f31424fb70528db upstream. 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/ Reviewed-by: Mohsin Bashir Acked-by: Lorenzo Bianconi Signed-off-by: Sun Jian Link: https://patch.msgid.link/20260804054040.613675-2-sun.jian.kdev@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/dev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5116,12 +5116,16 @@ u32 bpf_prog_run_generic_xdp(struct sk_b } /* 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;