NetBSD Problem Report #60975

From www@netbsd.org  Fri Nov  6 22:41:16 2026
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4F08C1A923B
	for <gnats-bugs@gnats.NetBSD.org>; Fri,  6 Nov 2026 22:41:16 +0000 (UTC)
Message-Id: <20261106224115.1C9471A923C@mollari.NetBSD.org>
Date: Fri,  6 Nov 2026 22:41:15 +0000 (UTC)
From: joe@eloisystems.com
Reply-To: joe@eloisystems.com
To: gnats-bugs@NetBSD.org
Subject: NPF rules are almost never BPF JIT compiled since 2014
X-Send-Pr-Version: www-1.0
X-From4GNATS: "joe@eloisystems.com via gnats" <gnats-admin@NetBSD.org>

>Number:         60975
>Category:       kern
>Synopsis:       NPF rules are almost never BPF JIT compiled since 2014
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Nov 06 22:45:00 +0000 2026
>Last-Modified:  Sun Nov 15 16:15:01 +0000 2026
>Originator:     Emmanuel Nyarko
>Release:        NetBSD 11
>Organization:
NetBSD
>Environment:
NetBSD  11.0_STABLE NetBSD 11.0_STABLE 
>Description:

wrong size is passed to npf_bpf_compile. the compile function expects a instruction size count 
but the byte count of the nvlist blob is what is sent to BPF JIT.

This almost always leads to RET instructions not falling on the last BPF code
or random crashes rules count are more than the blob size.


so setting bpf jit to 1 or on almost always sets it back to BPF interpretion or crash with some randomly odd number of rules.
>How-To-Repeat:


code inspection.
>Fix:

Yes please.

>Audit-Trail:
From: "Emmanuel" <joe@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/60975 CVS commit: src/usr.sbin/npf/npftest/libnpftest
Date: Sat, 7 Nov 2026 17:44:29 +0000

 Module Name:	src
 Committed By:	joe
 Date:		Sat Nov  7 17:44:29 UTC 2026

 Modified Files:
 	src/usr.sbin/npf/npftest/libnpftest: npf_bpf_test.c

 Log Message:
 PR kern/60975 add BPF validate tests to catch early if anything breaks


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/npf/npftest/libnpftest/npf_bpf_test.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Alexander Nasonov <alnsn@yandex.ru>
To: gnats-bugs@netbsd.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: kern/60975: NPF rules are almost never BPF JIT compiled since
 2014
Date: Sun, 15 Nov 2026 15:13:01 +0000

 joe@eloisystems.com via gnats wrote:
 > >Number:         60975
 > >Category:       kern
 > >Synopsis:       NPF rules are almost never BPF JIT compiled since 2014
 > >Confidential:   no
 > >Severity:       serious
 > >Priority:       high
 > >Responsible:    kern-bug-people
 > >State:          open
 > >Class:          sw-bug
 > >Submitter-Id:   net
 > >Arrival-Date:   Fri Nov 06 22:45:00 +0000 2026
 > >Originator:     Emmanuel Nyarko
 > >Release:        NetBSD 11
 > >Organization:
 > NetBSD
 > >Environment:
 > NetBSD  11.0_STABLE NetBSD 11.0_STABLE 
 > >Description:
 > 
 > wrong size is passed to npf_bpf_compile. the compile function expects a instruction size count 
 > but the byte count of the nvlist blob is what is sent to BPF JIT.
 > 
 > This almost always leads to RET instructions not falling on the last BPF code
 > or random crashes rules count are more than the blob size.

 The title is misleading. Even though a wrong size is passed, it's
 harmless in stable releases because bpfjit doesn't read unreachable
 code.

 Below is a copy of my analysis sent to source-changes-d:

 Alexander Nasonov wrote:
 > In stable releases it reads past the end of allocations but it generates
 > valid jitted code.

 Further analysis below. Stable releases should be fine,
 because I don't see reads of unreachable insns anywhere.

 optimize_pass1 doesn't read unreachable insns:

 	for (i = 0; i < insn_count; i++) {
 		if (!SLIST_EMPTY(&insn_dat[i].bjumps))
 			unreachable = false;
 		insn_dat[i].unreachable = unreachable;

 		if (unreachable)
 			continue;

 optimize_pass2 doesn't read unreachable insns, it only
 computes addresses:

 	for (i = insn_count; i != 0; i--) {
 		pc = &insns[i-1];
 		pd = &insn_dat[i-1];

 		if (pd->unreachable)
 			continue;

 optimize_pass3 doesn't read unreachable insns either:

 	for (i = 0; i < insn_count; i++) {
 		if (insn_dat[i].unreachable)
 			continue;

 --
 Alex

From: Emmanuel Nyarko <joe@eloisystems.com>
To: Alexander Nasonov <alnsn@yandex.ru>
Cc: gnats-bugs@netbsd.org, kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
        netbsd-bugs@netbsd.org
Subject: Re: kern/60975: NPF rules are almost never BPF JIT compiled since
 2014
Date: Sun, 15 Nov 2026 16:12:49 +0000

 Okay.

 We could edit the PR.

 you have committed the fix so i think we can request pullup and close it ?

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.