Skip to contentSkip to conversation

ICMP match bug

DISCUSSION Balazs Scheidler 2 participants 5 messages Jan 27, 2003 – Feb 3, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

We have found a problem with ICMP match. I'm afraid it is not easy to fix due to compatibility problems but here it goes:

if I add a rule with a command line like this:

iptables -A INPUT -p icmp -j ACCEPT

then no extra match is added to the rule:

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0          

if I add a rule with a command line like this:

iptables -A INPUT -p icmp -m icmp -j ACCEPT

(note that no --icmp-type was specified), it results in:

Chain INPUT (policy ACCEPT)

target     prot opt source               destination         
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0          icmp type 0 

Thus, --icmp-type was assumed, and its value is 0

A similar thing happens with TCP/UDP but match assumes a wildcard default:

iptables -A INPUT -p udp -m udp -j ACCEPT

ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp

thus matches all UDP packets.

We encountered this problem because we generate iptables-restore compatible output. iptables-restore does not demand load protocol matchers (thus we needed explicit match specifications to be able to use --dport & friends). We rewrite rules by sed -e 's/-p \(.*\)/-p \1 -m \1/', thus iptables -p icmp becomes iptables -p icmp -m icmp unconditionally.

The solution would be either to create a 'wildcard' match for -m icmp which would match all packets (I'm afraid this would create incompatibilities) _or_ to fix iptables-restore to load matches the same way as iptables itself does.

Signature · 2 lines
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
#1 lore raw
Quoted 10 lines · Balazs Scheidler

We encountered this problem because we generate iptables-restore compatible output. iptables-restore does not demand load protocol matchers (thus we needed explicit match specifications to be able to use --dport & friends). We rewrite rules by sed -e 's/-p \(.*\)/-p \1 -m \1/', thus iptables -p icmp becomes iptables -p icmp -m icmp unconditionally.

The solution would be either to create a 'wildcard' match for -m icmp which would match all packets (I'm afraid this would create incompatibilities) _or_ to fix iptables-restore to load matches the same way as iptables itself does.

Let me fix myself, the latest iptables version seems to have this demand loading fixed, thus our problem is solved.

However the way the icmp match defaults does not seem to be correct to me.

Signature · 2 lines
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
#2 lore raw
Quoted 7 lines · Balazs Scheidler
Quoted 6 lines · Balazs Scheidler

We encountered this problem because we generate iptables-restore compatible output. iptables-restore does not demand load protocol matchers (thus we needed explicit match specifications to be able to use --dport & friends). We rewrite rules by sed -e 's/-p \(.*\)/-p \1 -m \1/', thus iptables -p icmp becomes iptables -p icmp -m icmp unconditionally.

Quoted 7 lines
Quoted 4 lines

The solution would be either to create a 'wildcard' match for -m icmp which would match all packets (I'm afraid this would create incompatibilities) _or_ to fix iptables-restore to load matches the same way as iptables itself does.

Let me fix myself, the latest iptables version seems to have this demand loading fixed, thus our problem is solved.

;). Yes, I remember having fixed that demandloading code. It now has more comment than C code :(

Quoted 1 line

However the way the icmp match defaults does not seem to be correct to me.

I totally agree. Any suggestions?

Quoted 1 line

Bazsi

Signature · 5 lines
Live long and prosper
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
GCS/E/IT d- s-: a-- C+++ UL++++$ P+++ L++++$ E--- W- N++ o? K- w--- O- M- 
V-- PS+ PE-- Y+ PGP++ t++ 5-- !X !R tv-- b+++ DI? !D G+ e* h+ r% y+(*)
#3 lore raw
Quoted 10 lines · Harald Welte
Quoted 2 lines · Balazs Scheidler

Let me fix myself, the latest iptables version seems to have this demand loading fixed, thus our problem is solved.

;). Yes, I remember having fixed that demandloading code. It now has more comment than C code :(

Quoted 1 line

However the way the icmp match defaults does not seem to be correct to me.

I totally agree. Any suggestions?

I don't think this issue can be fixed without changing the userspace API (and retain compatibility)

Incompatible solutions:

1) have a special value meaning "no icmp type specified", for example -1 (0xFF) would mean "any"
2) create a possibility to match a range of icmp types, and initialize the range to [0,max_icmp_type]
3) use a bitmask instead of a range where each bit would mean a specific icmp type

Option 1) could be implemented without changing the size of the match struct, the other two would involve changing the size of the match struct.

I've checked the kernel source, specifying -1 for old kernels would mean 'match nothing', thus our beloved compatibility equations would be like this:

1) old kernel - new iptables

when ANY icmp type is specified, no packets would be matched, this is different from the current behaviour when icmp type 0 is matched (PONG).

when a usual icmp type is specified everything works correctly.

2) new kernel - old iptables

no problem.

The question is whether we can live with the incompatibility of matching nothing instead of PONG when no --icmp-type is specified.

Signature · 2 lines
Bazsi
PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1
#4 lore raw
Quoted 12 lines · Balazs Scheidler

Option 1) could be implemented without changing the size of the match struct, the other two would involve changing the size of the match struct.

I've checked the kernel source, specifying -1 for old kernels would mean 'match nothing', thus our beloved compatibility equations would be like this:

1) old kernel - new iptables

when ANY icmp type is specified, no packets would be matched, this is different from the current behaviour when icmp type 0 is matched (PONG).

Quoted 8 lines

when a usual icmp type is specified everything works correctly.

2) new kernel - old iptables

no problem.

The question is whether we can live with the incompatibility of matching nothing instead of PONG when no --icmp-type is specified.

yes, this is perfectly fine. matching 'pong' when no icmp-type is specified was never advertised as a feature. It's a misbehaviour which is now going to be corrected. We should document this change at least in bugzilla (i.e. submit a bug report, and document the change to CVS)

Do you want to send me a patch?

Thanks.

Quoted 1 line

Bazsi

Signature · 4 lines
- Harald Welte / [email protected]               http://www.gnumonks.org/
============================================================================
"If this were a dictatorship, it'd be a heck of a lot easier, just so long
 as I'm the dictator."  --  George W. Bush Dec 18, 2000