For those of you that follow bugtraq, you might have seen my recent
email about ICMP state packet matching. I've crafted up a patch for
that (see below, ip_state.h & ip_state.c) which will require rebuilding
ipfstat as well as the kernel/lkm. Being where I am, I've even less
capacity to test this apart from compile & regression tests, but it
looks relatively straight forward O:-) THis patch should apply to
almost any version of 3.4 (or any recent one, anyway O:-)
There's a second patch included for 3.4.33pre1 (if you're using 3.4.32,
don't, use 3.4.33pre1 at least) that might go some way towards
addressing the panics people have been seeing.
Please let me know if either of these break things, cause instant panics,
the heavens to rain fish, etc.
Cheers,
Darren
Index: ip_state.h
===================================================================
RCS file: /devel/CVS/IP-Filter/ip_state.h,v
retrieving revision 2.13.2.13
diff -c -r2.13.2.13 ip_state.h
*** ip_state.h 27 Jun 2002 14:40:29 -0000 2.13.2.13
--- ip_state.h 20 Sep 2003 13:25:47 -0000
***************
*** 62,67 ****
--- 62,68 ----
frentry_t *is_rule;
U_QUAD_T is_pkts;
U_QUAD_T is_bytes;
+ U_QUAD_T is_icmppkts;
union i6addr is_src;
union i6addr is_dst;
void *is_ifp[4];
Index: ip_state.c
===================================================================
RCS file: /devel/CVS/IP-Filter/ip_state.c,v
retrieving revision 2.30.2.84
diff -c -r2.30.2.84 ip_state.c
*** ip_state.c 7 Jun 2003 11:55:55 -0000 2.30.2.84
--- ip_state.c 20 Sep 2003 14:18:23 -0000
***************
*** 1300,1309 ****
READ_ENTER(&ipf_state);
for (isp = &ips_table[hv]; (is = *isp); isp = &is->is_hnext)
if ((is->is_p == pr) && (is->is_v == 4) &&
fr_matchsrcdst(is, src, dst, &ofin, NULL) &&
! fr_matchicmpqueryreply(is->is_v, is, icmp, fin->fin_rev)) {
ips_stats.iss_hits++;
! is->is_pkts++;
is->is_bytes += ip->ip_len;
fr = is->is_rule;
break;
--- 1300,1311 ----
READ_ENTER(&ipf_state);
for (isp = &ips_table[hv]; (is = *isp); isp = &is->is_hnext)
if ((is->is_p == pr) && (is->is_v == 4) &&
+ (is->is_icmppkts < is->is_pkts) &&
fr_matchsrcdst(is, src, dst, &ofin, NULL) &&
! fr_matchicmpqueryreply(is->is_v, is, icmp,
! fin->fin_rev)) {
ips_stats.iss_hits++;
! is->is_icmppkts++;
is->is_bytes += ip->ip_len;
fr = is->is_rule;
break;
***************
*** 1356,1365 ****
* tcp internals such as seq and ack numbers.
*/
if ((is->is_p == pr) && (is->is_v == 4) &&
fr_matchsrcdst(is, src, dst, &ofin, tcp)) {
fr = is->is_rule;
ips_stats.iss_hits++;
! is->is_pkts++;
is->is_bytes += fin->fin_plen;
/*
* we deliberately do not touch the timeouts
--- 1358,1368 ----
* tcp internals such as seq and ack numbers.
*/
if ((is->is_p == pr) && (is->is_v == 4) &&
+ (is->is_icmppkts < is->is_pkts) &&
fr_matchsrcdst(is, src, dst, &ofin, tcp)) {
fr = is->is_rule;
ips_stats.iss_hits++;
! is->is_icmppkts++;
is->is_bytes += fin->fin_plen;
/*
* we deliberately do not touch the timeouts
***************
*** 2086,2092 ****
int types[1];
ipsl.isl_type = type;
! ipsl.isl_pkts = is->is_pkts;
ipsl.isl_bytes = is->is_bytes;
ipsl.isl_src = is->is_src;
ipsl.isl_dst = is->is_dst;
--- 2089,2095 ----
int types[1];
ipsl.isl_type = type;
! ipsl.isl_pkts = is->is_pkts + is->is_icmppkts;
ipsl.isl_bytes = is->is_bytes;
ipsl.isl_src = is->is_src;
ipsl.isl_dst = is->is_dst;
Index: fil.c
===================================================================
RCS file: /devel/CVS/IP-Filter/fil.c,v
retrieving revision 2.35.2.73
diff -c -r2.35.2.73 fil.c
*** fil.c 27 Jun 2003 15:29:37 -0000 2.35.2.73
--- fil.c 18 Sep 2003 21:28:09 -0000
***************
*** 229,235 ****
fin->fin_id = ip->ip_id;
fi->fi_tos = ip->ip_tos;
off = (ip->ip_off & IP_OFFMASK);
- tcp = (tcphdr_t *)((char *)ip + hlen);
(*(((u_short *)fi) + 1)) = (*(((u_short *)ip) + 4));
fi->fi_src.i6[1] = 0;
fi->fi_src.i6[2] = 0;
--- 229,234 ----
***************
*** 254,260 ****
p = ip6->ip6_nxt;
fi->fi_p = p;
fi->fi_ttl = ip6->ip6_hlim;
- tcp = (tcphdr_t *)(ip6 + 1);
fi->fi_src.in6 = ip6->ip6_src;
fi->fi_dst.in6 = ip6->ip6_dst;
fin->fin_id = (u_short)(ip6->ip6_flow & 0xffff);
--- 253,258 ----
***************
*** 270,276 ****
fin->fin_off = off;
fin->fin_plen = plen;
! fin->fin_dp = (char *)tcp;
fin->fin_misc = 0;
off <<= 3;
--- 268,274 ----
fin->fin_off = off;
fin->fin_plen = plen;
! tcp = (tcphdr_t *)((char *)ip + hlen);
fin->fin_misc = 0;
off <<= 3;
***************
*** 379,384 ****
--- 377,383 ----
ip = ipf_pullup(m, fin, plen);
if (ip == NULL)
return -1;
+ tcp = (tcphdr_t *)((char *)ip + hlen);
}
#endif /* KERNEL && !__sgi */
minicmpsz = ICMPERR_MINPKTLEN - sizeof(ip_t);
***************
*** 417,422 ****
--- 416,422 ----
ip = ipf_pullup(m, fin, tlen);
if (ip == NULL)
return -1;
+ tcp = (tcphdr_t *)((char *)ip + hlen);
}
}
#endif /* _KERNEL && !_sgi */
***************
*** 459,464 ****
--- 459,466 ----
default :
break;
}
+
+ fin->fin_dp = (char *)tcp;
#ifdef USE_INET6
if (v == 6) {