Article View: linux.kernel.netdev
Article #73[PATCH net] flow_dissector: avoid u16 truncation of hlen in bpf_flow_dissect()
From: Eric Dumazet
Date: Wed, 07 Oct 2026 04:56
Date: Wed, 07 Oct 2026 04:56
41 lines
6726 bytes
6726 bytes
bpf_flow_dissect() sanitizes the offsets returned by the BPF program
with clamp_t(u16, ..., hlen).
If hlen is bigger than 65535, the upper bound is truncated before
the comparison. For instance, with hlen == 65536, both nhoff and
thoff are forced to zero, even if the program returned sane values.
This is the same class of bug as the one fixed in commit 99bda1ecbd56
("flow_dissector: avoid u16 truncation of skb->len when computing
thoff"). That fix does not cover the BPF path, because
__skb_flow_dissect() returns early when a BPF flow dissector
handles the packet.
struct bpf_flow_keys stores nhoff and thoff as u16, so cap hlen
to U16_MAX before clamping.
Found by sashiko while reviewing the commit above.
Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook")
Assisted-by: LLM
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
net/core/flow_dissector.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 27d8a01bc92306ff043389b4fde2d24af97d3106..1be6c739e3c718b4561195a20e49cc3911874af1 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -1023,6 +1023,8 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
result = bpf_prog_run_pin_on_cpu(prog, ctx);
+ /* bpf_flow_keys offsets are u16: do not let @hlen be truncated. */
+ hlen = min_t(int, hlen, U16_MAX);
flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
flow_keys->nhoff, hlen);
--
2.53.0
Technical Details
Message-ID:
<20261007045616.445596-1-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342195-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-342195-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net] flow_dissector: avoid u16 truncation of hlen in bpf_flow_dissect() Date: Wed, 7 Oct 2026 06:56:15 +0200 Organization: Usenet Network Message-ID: <20261007045616.445596-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="578249"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:XuroktK7aMRuQZFVuEMcV4MIVGg= sha256:4jLiIk6AIxapQSanG9MIM2raIf57TgkhPYfL7LQwegU= sha1:5uU7Vnx1PAxX6H6qUkhYYzumRFg= sha256:ia2n4Lol1l/ZuZ3Y6dTiOU9xa2RgyFUIyfAPnX53PKo= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 71CB210F0DA; Wed, 7 Oct 2026 07:56:33 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.641 X-Spam-Status: No, score=-3.641 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zoqPTRK03-Ce; Wed, 7 Oct 2026 07:56:31 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-342195-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id A08C210F0D2; Wed, 7 Oct 2026 07:56:27 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 2E26A23DF2; Wed, 7 Oct 2026 04:56:25 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5597A2E719B; Wed, 7 Oct 2026 04:56:24 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nDD8xJW1" X-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 5A0EE3806AD for <netdev@vger.kernel.org>; Wed, 7 Oct 2026 04:56:23 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791348984; cv=none; b=TwoOM8JGtJCYyxl3uhB4lUyOQPrh2s2X0/pRu6xw5FJiqE98P2Wf6sbtg/OqSkmmaquJFq2s6y6nwcXFUJ35AxlQDr53OZeoNh/2VW/ptqQdhD4UWPF2FOu3JtGQmnDM7f+z8Jngk2Vlbxt2KK8fLvsIogLmVvk2cxJKre9sXzA= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791348984; c=relaxed/simple; bh=YTagIdj57CL+e7tWVBMZ7SdBEgUALkTRuRZewf5gHBQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=l376+5yJexJux97zEkNqgOdVt01PuVga8UxOKm0AC9ohQ3naGJxRiQUcLkApURcRxfDrZ4G0cDbnFzLfICMd43moH3WSqIKnsqM1XmRHoJ46pJ+gTpGV3b+HMSdt/M+kp3uNAe8xX473x0dq2Yjh3egshGMRykGQMX0H5TNTpmY= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nDD8xJW1; arc=none smtp.client-ip=100.103.45.18 X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E47361F0089B; Wed, 7 Oct 2026 04:56:19 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791348983; bh=mAbTuNvk8mupf6rlBIZU/8xZA92Zs8tRmAuD+dQdpO4=; h=From:To:Cc:Subject:Date; b=nDD8xJW1GWFAFWcy0kKgZwXiUOe5dg9SMEiSZJapUSn1sr8cFyT6CAhqMLO0619rJ W+bi5iR/kCnrMh4j2kz9lihexwTZukxDxBrxl+YzFQt26uIbLUDc+4Z3d5nAmhJRmQ RM7ACntDZ04dMef0k2T1XVIDEAv3AtNMO/YRqzHBRbtonwLs9dbHlDp5k3bslizlDk F8VwJehs/JN//t+YmX58uBEv/uDYqHV6iQ9VHG/3+YH8vVYds9jQrAwlz1o4z+BANB 9FBsKUXmVbMqSrWCSCPGr+fbwTm8q8ZtfEDi+dSkjnQRwlHYatADksuX31DDYgS9/K 4Jv4MCwmuqx6w== X-Cc: Willem de Bruijn <willemb@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org> X-Mailer: git-send-email 2.53.0 X-Precedence: bulk X-Mailing-List: netdev@vger.kernel.org X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>