NetBSD Problem Report #61042
From ef@math.uni-bonn.de Sun Nov 22 10:27:06 2026
Return-Path: <ef@math.uni-bonn.de>
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 BB7821A923B
for <gnats-bugs@gnats.NetBSD.org>; Sun, 22 Nov 2026 10:27:06 +0000 (UTC)
Message-Id: <20261122102659.28E2EB17A00@trave.math.uni-bonn.de>
Date: Sun, 22 Nov 2026 11:26:59 +0100 (CET)
From: ef@math.uni-bonn.de
Reply-To: ef@math.uni-bonn.de
To: gnats-bugs@NetBSD.org
Subject: ipf panic
X-Send-Pr-Version: 3.95
X-From4GNATS: "ef@math.uni-bonn.de via gnats" <gnats-admin@NetBSD.org>
>Number: 61042
>Category: kern
>Synopsis: ipf panics when setting tcp_idle_timeout
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Nov 22 10:30:00 +0000 2026
>Originator: Edgar Fuss <ef@math.uni-bonn.de>
>Release: NetBSD 10.1_STABLE
>Organization:
Mathematisches Institut der Uni Bonn
>Environment:
System: NetBSD trave.math.uni-bonn.de 10.1_STABLE NetBSD 10.1_STABLE (MI-Server) #14: Wed Sep 3 17:26:51 CEST 2025 ef@peene.math.uni-bonn.de:/var/work/obj-10/sys/arch/amd64/compile/miserv amd64
Architecture: x86_64
Machine: amd64
>Description:
Setting tcp_idle_timeout (via ipf -T) panics when ipf is not running.
If it's running, the changed value is not reported back by ipf -T list.
>How-To-Repeat:
/etc/rc.d/ipfilter stop; ipf -T tcp_idle_timeout=4711
>Fix:
The panic is caused by ipf_settimeout_tcp() calling ipf_apply_timeout(),
which then tries to lock an uninitialized (or torn-down) mutex in one
of the ipftq_t entries.
The other problem is caused by ipf_state_settimeout() (and, also
ipf_nat_settimeout()), in the TCP case, doing a
return ipf_settimeout_tcp(t, p, softs->ipf_XXX_tcptq);
which then misses the
*t->ipft_pint = p->ipftu_int;
at the end.
The following patch addresses the first problem by passing an
additional "running" argument to ipf_settimeout_tcp() which, when 0,
makes it skip the ipf_apply_timeout() calls, and the second by
intermediately storing ipf_settimeout_tcp()'s result in an
additional "error" variable so the assignement at the end isn't
skipped any more.
My implementation doesn't look very elegant to me.
Since only root can change an ipf tuneable, the panic problem
seems not to be critical since root can cause a panic anyway.
Index: ip_fil.h
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/ipf/netinet/ip_fil.h,v
retrieving revision 1.8
diff -u -r1.8 ip_fil.h
--- ip_fil.h 11 Nov 2019 19:33:43 -0000 1.8
+++ ip_fil.h 21 Nov 2026 18:08:37 -0000
@@ -1859,7 +1859,7 @@
ipftq_t *, ipftq_t *, u_int *, int, int);
extern void ipf_queuefront(ipftqent_t *);
extern int ipf_settimeout_tcp(ipftuneable_t *, ipftuneval_t *,
- ipftq_t *);
+ ipftq_t *, int);
extern int ipf_checkv4sum(fr_info_t *);
extern int ipf_checkl4sum(fr_info_t *);
extern int ipf_ifpfillv4addr(int, struct sockaddr_in *,
Index: fil.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/ipf/netinet/fil.c,v
retrieving revision 1.35.4.1
diff -u -r1.35.4.1 fil.c
--- fil.c 28 Jul 2026 13:31:07 -0000 1.35.4.1
+++ fil.c 21 Nov 2026 18:08:50 -0000
@@ -8931,35 +8931,38 @@
/* ipf_apply_timeout(). */
/* ------------------------------------------------------------------------ */
int
-ipf_settimeout_tcp(ipftuneable_t *t, ipftuneval_t *p, ipftq_t *tab)
+ipf_settimeout_tcp(ipftuneable_t *t, ipftuneval_t *p, ipftq_t *tab, int running)
{
+ /* need to check running in each branch to catch an unkown name */
if (!strcmp(t->ipft_name, "tcp_idle_timeout") ||
!strcmp(t->ipft_name, "tcp_established")) {
- ipf_apply_timeout(&tab[IPF_TCPS_ESTABLISHED], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_ESTABLISHED], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_close_wait")) {
- ipf_apply_timeout(&tab[IPF_TCPS_CLOSE_WAIT], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_CLOSE_WAIT], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_last_ack")) {
- ipf_apply_timeout(&tab[IPF_TCPS_LAST_ACK], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_LAST_ACK], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_timeout")) {
- ipf_apply_timeout(&tab[IPF_TCPS_LISTEN], p->ipftu_int);
- ipf_apply_timeout(&tab[IPF_TCPS_HALF_ESTAB], p->ipftu_int);
- ipf_apply_timeout(&tab[IPF_TCPS_CLOSING], p->ipftu_int);
+ if (running) {
+ ipf_apply_timeout(&tab[IPF_TCPS_LISTEN], p->ipftu_int);
+ ipf_apply_timeout(&tab[IPF_TCPS_HALF_ESTAB], p->ipftu_int);
+ ipf_apply_timeout(&tab[IPF_TCPS_CLOSING], p->ipftu_int);
+ }
} else if (!strcmp(t->ipft_name, "tcp_listen")) {
- ipf_apply_timeout(&tab[IPF_TCPS_LISTEN], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_LISTEN], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_half_established")) {
- ipf_apply_timeout(&tab[IPF_TCPS_HALF_ESTAB], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_HALF_ESTAB], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_closing")) {
- ipf_apply_timeout(&tab[IPF_TCPS_CLOSING], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_CLOSING], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_syn_received")) {
- ipf_apply_timeout(&tab[IPF_TCPS_SYN_RECEIVED], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_SYN_RECEIVED], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_syn_sent")) {
- ipf_apply_timeout(&tab[IPF_TCPS_SYN_SENT], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_SYN_SENT], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_closed")) {
- ipf_apply_timeout(&tab[IPF_TCPS_CLOSED], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_CLOSED], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_half_closed")) {
- ipf_apply_timeout(&tab[IPF_TCPS_CLOSED], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_CLOSED], p->ipftu_int);
} else if (!strcmp(t->ipft_name, "tcp_time_wait")) {
- ipf_apply_timeout(&tab[IPF_TCPS_TIME_WAIT], p->ipftu_int);
+ if (running) ipf_apply_timeout(&tab[IPF_TCPS_TIME_WAIT], p->ipftu_int);
} else {
/*
* ipf_interror isn't set here because it should be set
Index: ip_state.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/ipf/netinet/ip_state.c,v
retrieving revision 1.12
diff -u -r1.12 ip_state.c
--- ip_state.c 18 Apr 2020 17:02:00 -0000 1.12
+++ ip_state.c 21 Nov 2026 18:09:04 -0000
@@ -5096,6 +5096,8 @@
ipf_state_settimeout(struct ipf_main_softc_s *softc, ipftuneable_t *t,
ipftuneval_t *p)
{
+ int error = 0;
+ int running = (softc->ipf_running > 0);
ipf_state_softc_t *softs = softc->ipf_state_soft;
/*
@@ -5104,19 +5106,19 @@
if (*t->ipft_pint == p->ipftu_int)
return 0;
- if (!strncmp(t->ipft_name, "tcp_", 4))
- return ipf_settimeout_tcp(t, p, softs->ipf_state_tcptq);
-
- if (!strcmp(t->ipft_name, "udp_timeout")) {
- ipf_apply_timeout(&softs->ipf_state_udptq, p->ipftu_int);
+ /* need to check running in each path to catch an unknown name */
+ if (!strncmp(t->ipft_name, "tcp_", 4)) {
+ error = ipf_settimeout_tcp(t, p, softs->ipf_state_tcptq, running);
+ } else if (!strcmp(t->ipft_name, "udp_timeout")) {
+ if (running) ipf_apply_timeout(&softs->ipf_state_udptq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "udp_ack_timeout")) {
- ipf_apply_timeout(&softs->ipf_state_udpacktq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softs->ipf_state_udpacktq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "icmp_timeout")) {
- ipf_apply_timeout(&softs->ipf_state_icmptq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softs->ipf_state_icmptq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "icmp_ack_timeout")) {
- ipf_apply_timeout(&softs->ipf_state_icmpacktq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softs->ipf_state_icmpacktq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "ip_timeout")) {
- ipf_apply_timeout(&softs->ipf_state_iptq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softs->ipf_state_iptq, p->ipftu_int);
} else {
IPFERROR(100034);
return ESRCH;
@@ -5127,7 +5129,7 @@
*/
*t->ipft_pint = p->ipftu_int;
- return 0;
+ return error;
}
Index: ip_nat.c
===================================================================
RCS file: /cvsroot/src/sys/external/bsd/ipf/netinet/ip_nat.c,v
retrieving revision 1.26
diff -u -r1.26 ip_nat.c
--- ip_nat.c 2 Feb 2022 05:40:58 -0000 1.26
+++ ip_nat.c 21 Nov 2026 20:21:18 -0000
@@ -7864,26 +7864,28 @@
ipf_nat_settimeout(struct ipf_main_softc_s *softc, ipftuneable_t *t,
ipftuneval_t *p)
{
+ int error = 0;
+ int running = (softc->ipf_running > 0);
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
- if (!strncmp(t->ipft_name, "tcp_", 4))
- return ipf_settimeout_tcp(t, p, softn->ipf_nat_tcptq);
-
- if (!strcmp(t->ipft_name, "udp_timeout")) {
- ipf_apply_timeout(&softn->ipf_nat_udptq, p->ipftu_int);
+ /* need to check running in each path to catch an unknown name */
+ if (!strncmp(t->ipft_name, "tcp_", 4)) {
+ error = ipf_settimeout_tcp(t, p, softn->ipf_nat_tcptq, running);
+ } else if (!strcmp(t->ipft_name, "udp_timeout")) {
+ if (running) ipf_apply_timeout(&softn->ipf_nat_udptq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "udp_ack_timeout")) {
- ipf_apply_timeout(&softn->ipf_nat_udpacktq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softn->ipf_nat_udpacktq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "icmp_timeout")) {
- ipf_apply_timeout(&softn->ipf_nat_icmptq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softn->ipf_nat_icmptq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "icmp_ack_timeout")) {
- ipf_apply_timeout(&softn->ipf_nat_icmpacktq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softn->ipf_nat_icmpacktq, p->ipftu_int);
} else if (!strcmp(t->ipft_name, "ip_timeout")) {
- ipf_apply_timeout(&softn->ipf_nat_iptq, p->ipftu_int);
+ if (running) ipf_apply_timeout(&softn->ipf_nat_iptq, p->ipftu_int);
} else {
IPFERROR(60062);
return ESRCH;
}
- return 0;
+ return error;
}
>Unformatted:
(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.