tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: ipfilter causes panic when setting tcp_idle_timeout
> It looks to me that ipf_settimeout_tcp() is missing a
> *t->ipft_pint = p->ipftu_int;
> before the
> return 0;
> .
In fact, ipf_{nat,state}_settimeout has such a statement, only, it's skipped
in the TCP case because the function returns ipf_settimeout_tcp()'s result
before reaching it.
The panic can be avoided by only calling ipf_apply_timeout() if ipf is actually
running.
See the attached patch. I't doesn't look particularly elegant to me, but it
works.
I've filed kern/61042 for this.
I hope there's no way for a non-root user to set an ipf tuneable, otherwise
this would be critical since one could panic the machine provided ipf is not
running.
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;
}
Home |
Main Index |
Thread Index |
Old Index