Netfilter: match "tcp option" with the same type present multiple times
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP REMOVE_ADDR suboption (type 0x30, len >=4, subtype 0x4) is added to the TCP options, it is added after an MPTCP DSS option (type 0x30, len >= 8, subtype 0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:
net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() {
...
for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
optl = optlen(opt, i);
if (priv->type != opt[i])
continue;
...
return; // <== it will look at the first MPTCP option
}
...
}It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
For more details about the Clashiko report:
https://lore.kernel.org/[email protected]
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \
{ type filter hook output priority filter; policy accept; }nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
(Also, it looks like the MPTCP suboptions are not documented in the nft man page :) )
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Florian Westphal
maintainerQuoted 8 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
Quoted 8 lines
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:
Yes, this won't work. 'tcp option X' extracts the
option X.
I don't see how this could be fixed within the limitations of the architecture. Just use bpf.
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
I don't know how, unless one would extend the kernel to make it aware of mptcp, which also requires userspace to pass the suboption type to look for in addition to 'mptcp option'.
Quoted 6 lines
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \{ type filter hook output priority filter; policy accept; }
Quoted 8 lines
nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
No idea.
cd git/netfilter.org/nftables/tests/shell; ./run-tests.sh -k testcases/packetpath/tcp_options
passes here.
Even tried adding 'tcp option timestamp exists...' to the test, also passes.
nft --debug=netlink list ruleset displays the rule like this:
inet t c 15 14
[ exthdr load tcpopt 1b @ 8 + 0 present => reg 1 ] [ cmp eq reg 1 0x01 ]
[ objref type 1 name tsc ]
Linux 7.3.0-rc3+
nftables v1.1.6 (Commodore Bullmoose #7)
Hi Florian,
Thank you for your reply!
Quoted 18 lines · Florian Westphal
Quoted 8 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
Quoted 8 lines
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:
Quoted 5 lines
Yes, this won't work. 'tcp option X' extracts the
option X.I don't see how this could be fixed within the limitations of the architecture.
That's what I was thinking too :-/
Quoted 1 line
Just use bpf.
Yes, or with a raw payload expression with NFTables.
Quoted 7 lines
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
I don't know how, unless one would extend the kernel to make it aware of mptcp, which also requires userspace to pass the suboption type to look for in addition to 'mptcp option'.
Should there be a note somewhere in the doc about this limitation? Because it looks like it will never be possible to match such subtype.
There are other MPTCP suboptions that can be used with DSS, e.g. MP_PRIO and MP_FAIL. But also MP_RST that can be used with FAST_CLOSE.
Quoted 13 lines
Quoted 13 lines
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \{ type filter hook output priority filter; policy accept; }nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
Quoted 8 lines
Quoted 1 line
... then the drop is effective. Any idea what I'm missing here? :)
No idea.
cd git/netfilter.org/nftables/tests/shell; ./run-tests.sh -k testcases/packetpath/tcp_optionspasses here.
Even tried adding 'tcp option timestamp exists...' to the test, also passes.
Arf, my bad, I still had debugging code, sorry... :/
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Florian Westphal
maintainerQuoted 1 line · Matthieu Baerts
Yes, or with a raw payload expression with NFTables.
If you expect identical layout every time, yes, that works too.
Quoted 2 lines
Should there be a note somewhere in the doc about this limitation? Because it looks like it will never be possible to match such subtype.
Yes, not without extra code on the kernel side.
Quoted 2 lines
There are other MPTCP suboptions that can be used with DSS, e.g.
MP_PRIOandMP_FAIL. But alsoMP_RSTthat can be used withFAST_CLOSE.
Right. I did not consider that this stops at first mptcp option encountered.
Quoted 5 lines
Quoted 3 lines
passes here.
Even tried adding 'tcp option timestamp exists...' to the test, also passes.Arf, my bad, I still had debugging code, sorry... :/
Phew :-)
Quoted 24 lines · Florian Westphal
Quoted 8 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
Quoted 8 lines
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:Yes, this won't work. 'tcp option X' extracts the
option X.I don't see how this could be fixed within the limitations of the architecture. Just use bpf.
Quoted 8 lines
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
I don't know how, unless one would extend the kernel to make it aware of mptcp, which also requires userspace to pass the suboption type to look for in addition to 'mptcp option'.
This won't be easy neither fast but I added this to my TODO list. It sounds fun. Unless someone else does it first, I will take it.
Quoted 31 lines
Quoted 6 lines
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \{ type filter hook output priority filter; policy accept; }Quoted 8 lines
nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
No idea.
cd git/netfilter.org/nftables/tests/shell; ./run-tests.sh -k testcases/packetpath/tcp_optionspasses here.
Even tried adding 'tcp option timestamp exists...' to the test, also passes.nft --debug=netlink list ruleset displays the rule like this:
inet t c 15 14
[ exthdr load tcpopt 1b @ 8 + 0 present => reg 1 ] [ cmp eq reg 10x01]
[ objref type 1 name tsc ]Linux 7.3.0-rc3+
nftables v1.1.6 (Commodore Bullmoose #7)
Florian Westphal
maintainerQuoted 16 lines · Fernando Fernandez Mancera
Quoted 15 lines · Florian Westphal
Quoted 4 lines
0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:Yes, this won't work. 'tcp option X' extracts the
option X.I don't see how this could be fixed within the limitations of the architecture. Just use bpf.
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Quoted 7 lines
Quoted 4 lines
I don't know how, unless one would extend the kernel to make it aware of mptcp, which also requires userspace to pass the suboption type to look for in addition to 'mptcp option'.
This won't be easy neither fast but I added this to my TODO list. It sounds fun. Unless someone else does it first, I will take it.
Thanks Fernando. I haven't looked at this at all.
I think the only sensible solution is to come up with a new syntax to clarify that we want a specific mptcp subtype and not the first mptcp option.
The problem is that "tcp option mptcp subtype" really just tells kernel "find the first mptcp option, if any, then place the subtype into dreg".
And kernel doesn't even know what a subtype is, it just extracts data at given offset :-/
Quoted 27 lines · Florian Westphal
Quoted 16 lines · Fernando Fernandez Mancera
Quoted 15 lines · Florian Westphal
Quoted 4 lines
0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:Yes, this won't work. 'tcp option X' extracts the
option X.I don't see how this could be fixed within the limitations of the architecture. Just use bpf.
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Quoted 7 lines
Quoted 4 lines
I don't know how, unless one would extend the kernel to make it aware of mptcp, which also requires userspace to pass the suboption type to look for in addition to 'mptcp option'.
This won't be easy neither fast but I added this to my TODO list. It sounds fun. Unless someone else does it first, I will take it.
Thanks Fernando. I haven't looked at this at all.
Quoted 8 lines
I think the only sensible solution is to come up with a new syntax to clarify that we want a specific mptcp subtype and not the first mptcp option.
The problem is that "tcp option mptcp subtype" really just tells kernel "find the first mptcp option, if any, then place the subtype into dreg".
And kernel doesn't even know what a subtype is, it just extracts data at given offset :-/
Yes, this will likely require both userspace and kernelspace code but I guess it is worth doing it :)
Quoted 50 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
For more details about the Clashiko report:
https://lore.kernel.org/[email protected]
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \{ type filter hook output priority filter; policy accept; }nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
Quoted 8 lines
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
(Also, it looks like the MPTCP suboptions are not documented in the nft man page :) )
Tomorrow there should be a patch in netfilter-devel adding it, we definitively should put more work into documentation.
Quoted 2 lines
Cheers,
Matt
Quoted 53 lines · Fernando Fernandez Mancera
Quoted 52 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() {
...
for (i =sizeof(*tcph); i <tcphdr_len- 1; i += optl) { optl =optlen(opt, i);if (
priv->type!= opt[i])
continue;
...
return; // <== it will look at the first MPTCP option }
...
}It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
For more details about the Clashiko report:
https://lore.kernel.org/[email protected]
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \
{ type filter hook output priority filter; policy accept; } nft insert rule ip filter OUTPUT tcp option mptcp exists counter dropSame with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
Quoted 9 lines
Quoted 6 lines
... then the drop is effective. Any idea what I'm missing here? :)
(Also, it looks like the MPTCP suboptions are not documented in the nft man page :) )
Tomorrow there should be a patch in netfilter-devel adding it, we definitively should put more work into documentation.
While at it, I will also document the existing limitation that was discussed above too.
Quoted 3 lines
Quoted 2 lines
Cheers,
Matt
Hi Fernando,
Quoted 61 lines · Fernando Fernandez Mancera
Quoted 60 lines · Fernando Fernandez Mancera
Quoted 58 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() {
...
for (i =sizeof(*tcph); i <tcphdr_len- 1; i += optl) { optl =optlen(opt, i);if (
priv->type!= opt[i])
continue;
...
return; // <== it will look at the first MPTCP option }
...
}It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
For more details about the Clashiko report:
https://lore.kernel.org/[email protected]
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \
{ type filter hook output priority filter; policy accept; } nft insert rule ip filter OUTPUT tcp option mptcp exists counter dropSame with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
(Also, it looks like the MPTCP suboptions are not documented in the nft man page :) )
Quoted 6 lines
Quoted 3 lines
Tomorrow there should be a patch in netfilter-devel adding it, we definitively should put more work into documentation.
While at it, I will also document the existing limitation that was discussed above too.
Great, thank you for looking at all this :)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Pablo Neira Ayuso
maintainerHi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }
Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop
^
|
|
allow to specify a match at a given tcp optionOr would this be too strict for your use-case and you would prefer that you can match it anywhere?
Thanks.
Quoted 30 lines
For more details about the Clashiko report:
https://lore.kernel.org/[email protected]
BTW, I'm probably missing something, but adding the following doesn't seem to have any effect on my side:
nft add table ip filter
nft add chain ip filter OUTPUT \{ type filter hook output priority filter; policy accept; }nft insert rule ip filter OUTPUT tcp option mptcp exists counter drop
Same with "mptcp subtype mp-capable", other subtypes or other types like "timestamp". But if I use ...
nft insert rule ip filter OUTPUT meta l4proto tcp counter drop
... then the drop is effective. Any idea what I'm missing here? :)
(Also, it looks like the MPTCP suboptions are not documented in the nft man page :) )
Cheers,
MattSignature · 1 line
Sponsored by the NGI0 Core fund.
Hi Pablo,
Thank you for your reply!
Quoted 37 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Quoted 8 lines
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp option
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an MP_RESET can be used alone, or after an MP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Pablo Neira Ayuso
maintainerQuoted 45 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 40 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
Quoted 8 lines
Quoted 5 lines
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionIn my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
I would support both of them eventually? Starting by the one above that allows to match at a given position which looks simpler to support to me. Then, look into adding a MPTCP subtype parser later?
Thanks.
Quoted 52 lines · Pablo Neira Ayuso
Quoted 51 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 45 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp option
Quoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
I understand. But I guess that still means adding a new option.
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)
I don't know if you need something specific to MPTCP, maybe just a way to check all options with the same type.
Quoted 3 lines
I would support both of them eventually? Starting by the one above that allows to match at a given position which looks simpler to support to me. Then, look into adding a MPTCP subtype parser later?
If the second one can be implemented in a simple way, perhaps the first one is not needed? If not, yes, good idea to start with the first one, which might be enough for most people.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Pablo Neira Ayuso
maintainerQuoted 58 lines · Matthieu Baerts
Quoted 52 lines · Pablo Neira Ayuso
Quoted 51 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 45 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionQuoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
Quoted 7 lines
I understand. But I guess that still means adding a new option.
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
You mean, the might want to validate the entire list of suboptions in a particular order, correct? ie. first suboption A then suboption B.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.
Quoted 8 lines
Quoted 2 lines
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In
nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)
In nftables, the fetch then cmp instructions are splitted, ie. you first retrieve then you compare (or make a set lookup with it). Builtin comparison should be possible, but it defeats the integration with the set infrastructure.
Quoted 2 lines
I don't know if you need something specific to MPTCP, maybe just a way to check all options with the same type.
Going back to this:
"When an MPTCP REMOVE_ADDR suboption (type 0x30, len >=4, subtype 0x4) is added to the TCP options, it is added after an MPTCP DSS option (type 0x30, len >= 8, subtype 0x2)"
Would you like to check for this particular sequence, right? Then position-based solution would work, because this would allow to match strictly:
pos = 0, suboption DSS
pos = 1, suboption REMOVE_ADDR
This ruleset might break the protocol if there is ever a suboption before DSS.
Loose mode is more protocol designer friendly as it does not constrain future updates in the protocol:
"please find MP-TCP suboption REMOVE_ADDR for me"
but security folks might probably say this is ... loose, because it does not validate DSS before and REMOVE_ADDR might come anywhere. Protocol designer would say that this is good for them because this firewall does not constrain future enhancements of the protocol (still raw expressions are possible, then this last statement does not hold anymore).
Which one would you pick? :-)
Quoted 7 lines
Quoted 3 lines
I would support both of them eventually? Starting by the one above that allows to match at a given position which looks simpler to support to me. Then, look into adding a MPTCP subtype parser later?
If the second one can be implemented in a simple way, perhaps the first one is not needed? If not, yes, good idea to start with the first one, which might be enough for most people.
Both solutions are feasible IMO, the second needs a bit more work, that's all.
Hi Pablo,
Thank you for your reply!
Quoted 61 lines · Pablo Neira Ayuso
Quoted 60 lines · Matthieu Baerts
Quoted 52 lines · Pablo Neira Ayuso
Quoted 51 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 45 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionQuoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
I understand. But I guess that still means adding a new option.
Quoted 8 lines
Quoted 5 lines
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
You mean, the might want to validate the entire list of suboptions in a particular order, correct? ie. first suboption A then suboption B.
Yes, that's one possibility. But initially, I was thinking about having two rules (or a set?) to match "the MPTCP subtype is either in the first MPTCP option, or the second one (if any)". (Or nft could always say with MPTCP by default, check also for a second MPTCP option, if any)
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.Quoted 8 lines
Quoted 2 lines
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In
nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)
Quoted 4 lines
In nftables, the fetch then cmp instructions are splitted, ie. you first retrieve then you compare (or make a set lookup with it). Builtin comparison should be possible, but it defeats the integration with the set infrastructure.
OK, I see.
If someone gives ...
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
... a bitmap could be used, but then that's specific to MPTCP I suppose.
Quoted 10 lines
Quoted 2 lines
I don't know if you need something specific to MPTCP, maybe just a way to check all options with the same type.
Going back to this:
"When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2)"Would you like to check for this particular sequence, right? Then
In my case, no particularly -- I just want to count/drop REMOVE_ADDR to catch kernel regressions in the selftests -- but I can.
Quoted 8 lines
position-based solution would work, because this would allow to match strictly:
pos = 0, suboption DSS
pos = 1, suboptionREMOVE_ADDRThis ruleset might break the protocol if there is ever a suboption before DSS.
Indeed. Technically, with MPTCP, we could send the REMOVE_ADDR alone (without DSS), or before the DSS, or with another one in between if there is room.
Quoted 5 lines
Loose mode is more protocol designer friendly as it does not constrain future updates in the protocol:
"please find MP-TCP suboption
REMOVE_ADDRfor me"
Quoted 8 lines
but security folks might probably say this is ... loose, because it does not validate DSS before and
REMOVE_ADDRmight come anywhere. Protocol designer would say that this is good for them because this firewall does not constrain future enhancements of the protocol (still raw expressions are possible, then this last statement does not hold anymore).Which one would you pick? :-)
I would first prefer if people don't drop packets with MPTCP options :-D
Honestly, I'm not sure what people would be interested in doing in production, but I guess it would be more: "please match packet with MPTCP suboption X, no matter the order". If people are interested in a specific packet where MPTCP suboptions are in a specific order, with a specific length, I *think* they can use a raw payload expression instead, no?
In my case, I just wanted to drop packets with a specific MPTCP suboption. It happens that I know exactly which packet I want to block, and I can use a raw payload expression, but a simpler rule would be welcome :)
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
I would support both of them eventually? Starting by the one above that allows to match at a given position which looks simpler to support to me. Then, look into adding a MPTCP subtype parser later?
If the second one can be implemented in a simple way, perhaps the first one is not needed? If not, yes, good idea to start with the first one, which might be enough for most people.
Both solutions are feasible IMO, the second needs a bit more work, that's all.
Understood!
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Pablo Neira Ayuso
maintainerHi Matthieu,
Quoted 101 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 61 lines · Pablo Neira Ayuso
Quoted 60 lines · Matthieu Baerts
Quoted 52 lines · Pablo Neira Ayuso
Quoted 51 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 45 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionQuoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
I understand. But I guess that still means adding a new option.
Quoted 8 lines
Quoted 5 lines
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
You mean, the might want to validate the entire list of suboptions in a particular order, correct? ie. first suboption A then suboption B.
Yes, that's one possibility. But initially, I was thinking about having two rules (or a set?) to match "the MPTCP subtype is either in the first MPTCP option, or the second one (if any)". (Or nft could always say with MPTCP by default, check also for a second MPTCP option, if any)
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.Quoted 8 lines
Quoted 2 lines
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In
nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)Quoted 4 lines
In nftables, the fetch then cmp instructions are splitted, ie. you first retrieve then you compare (or make a set lookup with it). Builtin comparison should be possible, but it defeats the integration with the set infrastructure.
Quoted 7 lines
OK, I see.
If someone gives ...
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
... a bitmap could be used, but then that's specific to MPTCP I suppose.
I think this makes sense from user perspective.
The nft_exthdr expression needs iterate over the whole list of tcp options, then if type is 30, make a set lookup to check if the subtype value is in the set.
Something like:
- loop
| r1 <- exthdr [ if no more tcp options, break loop ] | r2 <- lookup(r1) [ if found, break loop ]
but exthdr need to be taugh to resume from the last visited tcp option. A new loop expression would wrap these two exthdr and lookup expression (similar to nft_inner) and store the iteration context (ie. last visited tcp option to continue from there).
exthdr tcp option support needs advertise a new NFT_EXPR_LOOP flag, so it can be used with within this new nft_loop expression.
Another question: Would you still like to validate that DSS comes before REMOVE_ADDR?
Quoted 20 lines
Quoted 10 lines
Quoted 2 lines
I don't know if you need something specific to MPTCP, maybe just a way to check all options with the same type.
Going back to this:
"When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2)"Would you like to check for this particular sequence, right? Then
In my case, no particularly -- I just want to count/drop
REMOVE_ADDRto catch kernel regressions in the selftests -- but I can.Quoted 6 lines
position-based solution would work, because this would allow to match strictly:
pos = 0, suboption DSS
pos = 1, suboptionREMOVE_ADDR
Quoted 6 lines
Quoted 2 lines
This ruleset might break the protocol if there is ever a suboption before DSS.
Indeed. Technically, with MPTCP, we could send the
REMOVE_ADDRalone (without DSS), or before the DSS, or with another one in between if there is room.
Position matching is too strict.
You can still make it with the raw expression, but I think the native matching representation should be more flexible too as you describe.
Quoted 12 lines
Quoted 12 lines
Loose mode is more protocol designer friendly as it does not constrain future updates in the protocol:
"please find MP-TCP suboption
REMOVE_ADDRfor me"but security folks might probably say this is ... loose, because it does not validate DSS before and
REMOVE_ADDRmight come anywhere. Protocol designer would say that this is good for them because this firewall does not constrain future enhancements of the protocol (still raw expressions are possible, then this last statement does not hold anymore).
Quoted 7 lines
Quoted 1 line
Which one would you pick? :-)
I would first prefer if people don't drop packets with MPTCP options :-D
Honestly, I'm not sure what people would be interested in doing in production, but I guess it would be more: "please match packet with MPTCP suboption X, no matter the order".
Yes, as discussed, this is more protocol friendly too in terms of extensibility.
Quoted 8 lines
If people are interested in a specific packet where MPTCP suboptions are in a specific order, with a specific length, I *think* they can use a raw payload expression instead, no?
In my case, I just wanted to drop packets with a specific MPTCP suboption. It happens that I know exactly which packet I want to block, and I can use a raw payload expression, but a simpler rule would be welcome :)
Makes sense.
This would need an extension in the kernel as Florian has anticipated.
Quoted 124 lines · Pablo Neira Ayuso
Hi Matthieu,
Quoted 101 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 61 lines · Pablo Neira Ayuso
Quoted 60 lines · Matthieu Baerts
Quoted 52 lines · Pablo Neira Ayuso
Quoted 51 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 45 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionQuoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
I understand. But I guess that still means adding a new option.
Quoted 8 lines
Quoted 5 lines
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
You mean, the might want to validate the entire list of suboptions in a particular order, correct? ie. first suboption A then suboption B.
Yes, that's one possibility. But initially, I was thinking about having two rules (or a set?) to match "the MPTCP subtype is either in the first MPTCP option, or the second one (if any)". (Or nft could always say with MPTCP by default, check also for a second MPTCP option, if any)
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.Quoted 8 lines
Quoted 2 lines
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In
nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)Quoted 4 lines
In nftables, the fetch then cmp instructions are splitted, ie. you first retrieve then you compare (or make a set lookup with it). Builtin comparison should be possible, but it defeats the integration with the set infrastructure.
Quoted 7 lines
OK, I see.
If someone gives ...
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
... a bitmap could be used, but then that's specific to MPTCP I suppose.
I think this makes sense from user perspective.
The
nft_exthdrexpression needs iterate over the whole list of tcp options, then if type is 30, make a set lookup to check if the subtype value is in the set.Something like:
- loop
| r1 <- exthdr [ if no more tcp options, break loop ] | r2 <- lookup(r1) [ if found, break loop ]
Quoted 8 lines
but exthdr need to be taugh to resume from the last visited tcp option. A new loop expression would wrap these two exthdr and lookup expression (similar to
nft_inner) and store the iteration context (ie. last visited tcp option to continue from there).exthdr tcp option support needs advertise a new
NFT_EXPR_LOOPflag, so it can be used with within this newnft_loopexpression.
Wouldn't this be too complex? I was thinking in something a bit more generic and simpler. E.g a new NFTA_EXTHDR_INNER_TYPE which will work with PRESENT flag.
That way one can match MPTCP options exactly the same way TCP options are matched. The implementation would look first for the TCP option 30 and then check the subtype, if it matches return 1 otherwise continue.
This is chained with a CMP_EQ expression.
I have a working patch, let me polish the code and will send it as RFC today so we can discuss it. I like this idea because it could be extended to match similar situations in IPv6 headers or SCTP.
Quoted 70 lines
Another question: Would you still like to validate that DSS comes before
REMOVE_ADDR?Quoted 20 lines
Quoted 10 lines
Quoted 2 lines
I don't know if you need something specific to MPTCP, maybe just a way to check all options with the same type.
Going back to this:
"When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2)"Would you like to check for this particular sequence, right? Then
In my case, no particularly -- I just want to count/drop
REMOVE_ADDRto catch kernel regressions in the selftests -- but I can.Quoted 6 lines
position-based solution would work, because this would allow to match strictly:
pos = 0, suboption DSS
pos = 1, suboptionREMOVE_ADDRQuoted 6 lines
Quoted 2 lines
This ruleset might break the protocol if there is ever a suboption before DSS.
Indeed. Technically, with MPTCP, we could send the
REMOVE_ADDRalone (without DSS), or before the DSS, or with another one in between if there is room.Position matching is too strict.
You can still make it with the raw expression, but I think the native matching representation should be more flexible too as you describe.
Quoted 12 lines
Quoted 12 lines
Loose mode is more protocol designer friendly as it does not constrain future updates in the protocol:
"please find MP-TCP suboption
REMOVE_ADDRfor me"but security folks might probably say this is ... loose, because it does not validate DSS before and
REMOVE_ADDRmight come anywhere. Protocol designer would say that this is good for them because this firewall does not constrain future enhancements of the protocol (still raw expressions are possible, then this last statement does not hold anymore).Quoted 7 lines
Quoted 1 line
Which one would you pick? :-)
I would first prefer if people don't drop packets with MPTCP options :-D
Honestly, I'm not sure what people would be interested in doing in production, but I guess it would be more: "please match packet with MPTCP suboption X, no matter the order".
Yes, as discussed, this is more protocol friendly too in terms of extensibility.
Quoted 8 lines
If people are interested in a specific packet where MPTCP suboptions are in a specific order, with a specific length, I *think* they can use a raw payload expression instead, no?
In my case, I just wanted to drop packets with a specific MPTCP suboption. It happens that I know exactly which packet I want to block, and I can use a raw payload expression, but a simpler rule would be welcome :)
Makes sense.
This would need an extension in the kernel as Florian has anticipated.
Pablo Neira Ayuso
maintainerHi Fernando,
Quoted 131 lines · Fernando Fernandez Mancera
Quoted 128 lines · Pablo Neira Ayuso
Hi Matthieu,
Quoted 100 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 60 lines · Pablo Neira Ayuso
Quoted 59 lines · Matthieu Baerts
Quoted 51 lines · Pablo Neira Ayuso
Quoted 50 lines · Matthieu Baerts
Hi Pablo,
Thank you for your reply!
Quoted 44 lines · Pablo Neira Ayuso
Hi Mattieu,
Quoted 30 lines · Matthieu Baerts
Hello Netfilter devs,
First, thank you for maintaining Netfilter in the kernel and the userspace tools.
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if (priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option } ... }Quoted 3 lines
It looks like it shouldn't stop if the wrong subtype is found, but the subtype is not compared there if I'm not mistaken. Should there be a fix to support this case?
Would it work for you if you can specify what TCP option you want to match? ie.
tcp option[2] mptcp subtype remove-addr drop ^ | | allow to specify a match at a given tcp optionQuoted 4 lines
Quoted 2 lines
In my specific use-case, yes it would work. Some MPTCP sub-options will always be after another one... when the Linux stack is used.
This would require a smaller patch.
I understand. But I guess that still means adding a new option.
Quoted 8 lines
Quoted 5 lines
In my case, it would work, but this might be confusing for people who want to use this filter: they need to know if a suboption can be used with another one. I guess they could have multiple rules to check the presence of a suboption in the first matched type, and in a second one, but that seems confusing. Or maybe not?
You mean, the might want to validate the entire list of suboptions in a particular order, correct? ie. first suboption A then suboption B.
Yes, that's one possibility. But initially, I was thinking about having two rules (or a set?) to match "the MPTCP subtype is either in the first MPTCP option, or the second one (if any)". (Or nft could always say with MPTCP by default, check also for a second MPTCP option, if any)
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Or would this be too strict for your use-case and you would prefer that you can match it anywhere?
I think it would make more sense to match it anywhere. For example, an
MP_RESETcan be used alone, or after anMP_FASTCLOSE. Plus some stacks could reorder the options as there is no imposed order.Quoted 8 lines
Quoted 2 lines
I think this would require a MPTCP subtype parser, ie. make kernel aware of MPTCP subtypes.
In
nft_exthdr_tcp_eval(), why can the comparison not be done there instead of copying the data in a register, and compare later on? If the comparison is done directly for a given type and is different, the code could continue and check for the same type. (Or store in multiple registers.)Quoted 4 lines
In nftables, the fetch then cmp instructions are splitted, ie. you first retrieve then you compare (or make a set lookup with it). Builtin comparison should be possible, but it defeats the integration with the set infrastructure.
Quoted 7 lines
OK, I see.
If someone gives ...
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
... a bitmap could be used, but then that's specific to MPTCP I suppose.
I think this makes sense from user perspective.
The
nft_exthdrexpression needs iterate over the whole list of tcp options, then if type is 30, make a set lookup to check if the subtype value is in the set.Something like:
- loop
| r1 <- exthdr [ if no more tcp options, break loop ] | r2 <- lookup(r1) [ if found, break loop ]but exthdr need to be taugh to resume from the last visited tcp option. A new loop expression would wrap these two exthdr and lookup expression (similar to
nft_inner) and store the iteration context (ie. last visited tcp option to continue from there).
Quoted 7 lines
Quoted 3 lines
exthdr tcp option support needs advertise a new
NFT_EXPR_LOOPflag, so it can be used with within this newnft_loopexpression.Wouldn't this be too complex? I was thinking in something a bit more generic and simpler. E.g a new
NFTA_EXTHDR_INNER_TYPEwhich will work with PRESENT flag.
That's fine, this is needed for matching the subtype.
Quoted 5 lines
That way one can match MPTCP options exactly the same way TCP options are matched. The implementation would look first for the TCP option 30 and then check the subtype, if it matches return 1 otherwise continue.
This is chained with a
CMP_EQexpression.
I think it would be great if we support this too:
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
and even combine this new feature with maps.
IIUC, TCP option 30 might come several times, one for each subtype, that is why I suggested the loop thing, because we need to have control on the iteration over the list of options. But if you design copes with the requirements that we have discussed or it can be extended later on, that's fine.
Quoted 3 lines
I have a working patch, let me polish the code and will send it as RFC today so we can discuss it. I like this idea because it could be extended to match similar situations in IPv6 headers or SCTP.
Yes, this should work with other extensions too.
Hi Pablo,
Thank you for your reply!
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Matthieu Baerts
Quoted 3 lines · Pablo Neira Ayuso
Quoted 2 lines · Matthieu Baerts
Quoted 1 line · Pablo Neira Ayuso
On Tue, Sep 29, 2026 at 11:21:15AM +0200, Matthieu Baerts wrote:
(...)
Quoted 18 lines
Quoted 5 lines
If someone gives ...
tcp option mptcp subtype { mp-capable, mp-join, remove-addr } drop
... a bitmap could be used, but then that's specific to MPTCP I suppose.
I think this makes sense from user perspective.
The
nft_exthdrexpression needs iterate over the whole list of tcp options, then if type is 30, make a set lookup to check if the subtype value is in the set.Something like:
- loop
| r1 <- exthdr [ if no more tcp options, break loop ] | r2 <- lookup(r1) [ if found, break loop ]
Quoted 7 lines
but exthdr need to be taugh to resume from the last visited tcp option. A new loop expression would wrap these two exthdr and lookup expression (similar to
nft_inner) and store the iteration context (ie. last visited tcp option to continue from there).exthdr tcp option support needs advertise a new
NFT_EXPR_LOOPflag, so it can be used with within this newnft_loopexpression.
Yes, this or Fernando's idea (BTW, thank you for looking at that!). Both will need to expose a new capability to the userspace from what I understand, so any of them are fine for me.
Quoted 2 lines
Another question: Would you still like to validate that DSS comes before
REMOVE_ADDR?
I don't think that's needed: the RFC doesn't impose an order nor a specific combination. When multiple MPTCP options are used, they are notifying two different things.
If people are interested in validating that option A comes before option B, that's certainly because they are trying to find a specific pattern -- e.g. to identify a specific stack or kernel version -- not to identify packets of a certain protocol. For them, they can use other techniques, but I don't think we need to increase the complexity to support that case. (At least for MPTCP.)
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Quoted 12 lines · Matthieu Baerts
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:
Quoted 10 lines
net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() {
...
for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
optl = optlen(opt, i);
if ( priv->type != opt[i])
continue;
...
return; // <== it will look at the first MPTCP option
}Hm, neither RFC 793 nor 9293 seem to define a general processing rule or error-handling behavior for duplicate or repeated options within the header of a TCP segment.
MPTCP RFC 8684 seems to acknowledge that, with:
"it may not be possible to combine all desired options .. on a single packet"
Hi Jan,
Quoted 25 lines · Jan Engelhardt
Quoted 12 lines · Matthieu Baerts
The MPTCP selftests are switching from IPTables to NFTables, and Clashiko reported that this part of a rule wouldn't match anything:
tcp option mptcp subtype remove-addr drop
When an MPTCP
REMOVE_ADDRsuboption (type0x30, len >=4, subtype0x4) is added to the TCP options, it is added after an MPTCP DSS option (type0x30, len >= 8, subtype0x2). In other words, there will be two MPTCP (type 30) options in the TCP options. It looks like Netfilter doesn't handle that, because it stops processing other TCP options when the expected type is found:Quoted 10 lines
net/netfilter/nft_exthdr.c:nft_exthdr_tcp_eval() { ... for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) { optl = optlen(opt, i); if ( priv->type != opt[i]) continue; ... return; // <== it will look at the first MPTCP option }
Quoted 3 lines
Hm, neither RFC 793 nor 9293 seem to define a general processing rule or error-handling behavior for duplicate or repeated options within the header of a TCP segment.
From what I understood at the IETF, new TCP extensions can only be assigned one "type". If multiple message types should be passed, the subtype should be either extracted from the size, or by using another TLV inside. (MPTCP is using the two techniques.)
(Old extensions like SACK and echo are exceptions, because they are old ones.)
Quoted 4 lines
MPTCP RFC 8684 seems to acknowledge that, with:
"it may not be possible to combine all desired options .. on a single packet"
The MPTCP RFC specifies this mainly because of the TCP options space restriction (40 bytes). For example, the ADD_ADDR option can take up to 30 bytes (+2 for the alignment). If you add TCP Timestamp (10 + 2 for the alignment) or SACK, you are over the limit.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.