From 98bb921b141aa642faedbf2ac510541c76499a19 Mon Sep 17 00:00:00 2001
From: Denis Ovsienko <denis@ovsienko.info>
Date: Thu, 30 Jul 2026 13:34:21 +0100
Subject: [PATCH] CVE-2026-6244: Avoid division by zero via
 pcap_offline_filter().

The current revision of pcapint_filter_with_aux_data() for "div x" and
"mod x" correctly rejects the packet if X is zero, but for "div #k" and
"mod #k" it assumes that k is never zero.  This holds for programs that
have been generated or validated by libpcap.

However, this does not necessarily hold for programs that come from an
external source via pcap_offline_filter() or [deprecated] bpf_filter()
and have not been explicitly validated.  If the interpreter executes
such a program, it can attempt a division by zero, which will typically
terminate the process via SIGFPE.

To fix this problem, in pcapint_filter_with_aux_data() treat "div #k"
and "mod #k" the same way as "div x" and "mod x".

(backported from commit 0b2b1ad4a1796513613ff68e9dc09049cc8e0af4)
---
 CHANGES      | 1 +
 bpf_filter.c | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/bpf_filter.c b/bpf_filter.c
index d6e4b0196c..9dc9e4d94a 100644
--- a/bpf_filter.c
+++ b/bpf_filter.c
@@ -414,10 +414,14 @@ DIAG_ON_DEFAULT_ONLY_SWITCH
 			continue;
 
 		case BPF_ALU|BPF_DIV|BPF_K:
+			if (pc->k == 0)
+				return 0;
 			A /= pc->k;
 			continue;
 
 		case BPF_ALU|BPF_MOD|BPF_K:
+			if (pc->k == 0)
+				return 0;
 			A %= pc->k;
 			continue;
 
