Fix out of bounds when parsing TCP options
Subsystems (6)
v2 cover Fix out of bounds when parsing TCP options
This series fixes out-of-bounds access in various places in the kernel where parsing of TCP options takes place. Fortunately, many more occurrences don't have this bug.
v2 changes:
synproxy: Added an early return when length < 0 to avoid calling skb_header_pointer with negative length.
sch_cake: Added doff validation to avoid parsing garbage.
Maxim Mikityanskiy (3):
netfilter: synproxy: Fix out of bounds when parsing TCP options
mptcp: Fix out of bounds when parsing TCP options
sch_cake: Fix out of bounds when parsing TCP options and header
net/mptcp/options.c | 2 ++ net/netfilter/nf_synproxy_core.c | 5 +++++ net/sched/sch_cake.c | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
PATCH v2 1/3 netfilter: synproxy: Fix out of bounds when parsing TCP options
The TCP option parser in synproxy (synproxy_parse_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1.
This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options.").
v2 changes:
Added an early return when length < 0 to avoid calling skb_header_pointer with negative length.
--- net/netfilter/nf_synproxy_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_synproxy_core.c +5 -0
@@ -31,6 +31,9 @@ synproxy_parse_options(const struct sk_buff *skb, unsigned int doff,int length = (th->doff *4 ) -sizeof (*th);u8 buf[40 ], *ptr; +if (unlikely (length <0 )) +return false; + ptr =skb_header_pointer (skb, doff +sizeof (*th), length, buf);if (ptr ==NULL )return false;
@@ -47,6 +50,8 @@ synproxy_parse_options(const struct sk_buff *skb, unsigned int doff, length--;continue ;default : +if (length <2 ) +return true; opsize = *ptr++;if (opsize <2 )return true;
Signature · 1 line
2.25.1
Re: [PATCH net v2 1/3] netfilter: synproxy: Fix out of bounds when parsing TCP options
Quoted 8 lines · Maxim Mikityanskiy
The TCP option parser in synproxy (
synproxy_parse_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neitherTCPOPT_EOLnorTCPOPT_NOP, it reads one more byte, which exceeds the length of 1.This fix is inspired by commit
9609dad263f8("ipv4:tcp_input: fix stack out of bounds when parsing TCP options.").
PATCH v2 2/3 mptcp: Fix out of bounds when parsing TCP options
In reply to Maxim MikityanskiyThe TCP option parser in mptcp (mptcp_get_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1.
This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options.").
--- net/mptcp/options.c | 2 ++ 1 file changed, 2 insertions(+)
net/mptcp/options.c +2 -0
@@ -356,6 +356,8 @@ void mptcp_get_options(const struct sk_buff *skb, length--;continue ;default : +if (length <2 ) +return ; opsize = *ptr++;if (opsize <2 )/* "silly options" */ return ;
Signature · 1 line
2.25.1
Re: [PATCH net v2 2/3] mptcp: Fix out of bounds when parsing TCP options
Quoted 32 lines · Maxim Mikityanskiy
The TCP option parser in mptcp (
mptcp_get_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neitherTCPOPT_EOLnorTCPOPT_NOP, it reads one more byte, which exceeds the length of 1.This fix is inspired by commit
9609dad263f8("ipv4:tcp_input: fix stack out of bounds when parsing TCP options.").Cc Young Xiao <[email protected]>Fixes cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing connections")Signed-off-by Maxim Mikityanskiy <[email protected]>Reviewed-by Mat Martineau <[email protected]>---
net/mptcp/options.c| 2 ++1 file changed, 2 insertions(+)net/mptcp/options.c +2
-0@@ -356,6 +356,8 @@ void mptcp_get_options(const struct sk_buff *skb, length--;continue ;default : +if (length <2 ) +return ; opsize = *ptr++;if (opsize <2 )/* "silly options" */ return ;Signature · 1 line
2.25.1
Matthieu -
Could you apply this in mptcp_net-next so it's easier to track when the patch finds its way to net-next?
(MPTCP patchwork status set to "queued")
Thanks!
--
Mat Martineau
Intel
Re: [PATCH net v2 2/3] mptcp: Fix out of bounds when parsing TCP options
Quoted 37 lines · Mat Martineau
Quoted 32 lines · Maxim Mikityanskiy
The TCP option parser in mptcp (
mptcp_get_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neitherTCPOPT_EOLnorTCPOPT_NOP, it reads one more byte, which exceeds the length of 1.This fix is inspired by commit
9609dad263f8("ipv4:tcp_input: fix stack out of bounds when parsing TCP options.").Cc Young Xiao <[email protected]>Fixes cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoing connections")Signed-off-by Maxim Mikityanskiy <[email protected]>Reviewed-by Mat Martineau <[email protected]>---
net/mptcp/options.c| 2 ++1 file changed, 2 insertions(+)net/mptcp/options.c +2
-0@@ -356,6 +356,8 @@ void mptcp_get_options(const struct sk_buff *skb, length--;continue ;default : +if (length <2 ) +return ; opsize = *ptr++;if (opsize <2 )/* "silly options" */ return ;Signature · 1 line
2.25.1Matthieu -
Quoted 3 lines
Could you apply this in mptcp_net-next so it's easier to track when the patch finds its way to net-next?
(MPTCP patchwork status set to "queued")
And to clarify for Maxim: we have a separate MPTCP git tree where we stage MPTCP changes before submitting to net- or net-next. For your patch set that has related changes across a few networking subsystems, sending directly to netdev is the best thing to do.
We do have other queued changes for netdev so I think it would work well to include this patch in our tree now, and it will automatically disappear once it is fully merged upstream. Sometimes it takes a couple of weeks for the net/master branch to get merged in to net-next/master.
--
Mat Martineau
Intel
Re: [PATCH net v2 2/3] mptcp: Fix out of bounds when parsing TCP options
In reply to Mat MartineauHi Mat,
Quoted 17 lines · Mat Martineau
Quoted 6 lines · Maxim Mikityanskiy
The TCP option parser in mptcp (
mptcp_get_options) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neitherTCPOPT_EOLnorTCPOPT_NOP, it reads one more byte, which exceeds the length of 1.Quoted 8 lines
This fix is inspired by commit
9609dad263f8("ipv4:tcp_input: fix stack out of bounds when parsing TCP options.").Cc Young Xiao <[email protected]>Fixes cec37a6e41aa ("mptcp: Handle MP_CAPABLE options for outgoingconnections")
Signed-off-by Maxim Mikityanskiy <[email protected]>Reviewed-by Mat Martineau <[email protected]>
Quoted 4 lines
Matthieu -
Could you apply this in mptcp_net-next so it's easier to track when the patch finds its way to net-next?
Sure, good idea!
Thank you for the patch and the review!
Just applied in our tree:
- fdd037a5564a: mptcp: Fix out of bounds when parsing TCP options
- Results: 083034593cec..1ba3eb627299
Builds and tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20210611T142646
https://github.com/multipath-tcp/mptcp_net-next/actions/workflows/build-validation.yml?query=branch:export/20210611T142646
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
PATCH v2 3/3 sch_cake: Fix out of bounds when parsing TCP options and header
In reply to Maxim MikityanskiyThe TCP option parser in cake qdisc (cake_get_tcpopt and cake_tcph_may_drop) could read one byte out of bounds. When the length is 1, the execution flow gets into the loop, reads one byte of the opcode, and if the opcode is neither TCPOPT_EOL nor TCPOPT_NOP, it reads one more byte, which exceeds the length of 1.
This fix is inspired by commit 9609dad263f8 ("ipv4: tcp_input: fix stack out of bounds when parsing TCP options.").
v2 changes:
Added doff validation in cake_get_tcphdr to avoid parsing garbage as TCP header. Although it wasn't strictly an out-of-bounds access (memory was allocated), garbage values could be read where CAKE expected the TCP header if doff was smaller than 5.
--- net/sched/sch_cake.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/sched/sch_cake.c +5 -1
@@ -943,7 +943,7 @@ static struct tcphdr *cake_get_tcphdr(const struct sk_buff *skb, } tcph =skb_header_pointer (skb, offset,sizeof (_tcph), &_tcph); -if (!tcph) +if (!tcph || tcph->doff <5 )return NULL ; return skb_header_pointer(skb, offset,
@@ -967,6 +967,8 @@ static const void *cake_get_tcpopt(const struct tcphdr *tcph, length--;continue ; } +if (length <2 ) +break ; opsize = *ptr++;if (opsize <2 || opsize > length)break ;
@@ -1104,6 +1106,8 @@ static bool cake_tcph_may_drop(const struct tcphdr *tcph, length--;continue ; } +if (length <2 ) +break ; opsize = *ptr++;if (opsize <2 || opsize > length)break ;
Signature · 1 line
2.25.1
This series was applied to netdev/net.git (refs/heads/master):
Hello:
This series was applied to netdev/net.git (refs/heads/master):
Quoted 10 lines · On Thu, 10 Jun 2021 19:40:28 +0300 you wrote:
This series fixes out-of-bounds access in various places in the kernel where parsing of TCP options takes place. Fortunately, many more occurrences don't have this bug.
v2 changes:
synproxy: Added an early return when length < 0 to avoid calling
skb_header_pointerwith negative length.[...]
Here is the summary with links:
- [net,v2,1/3] netfilter: synproxy: Fix out of bounds when parsing TCP options
https://git.kernel.org/netdev/net/c/5fc177ab7594 - [net,v2,2/3] mptcp: Fix out of bounds when parsing TCP options https://git.kernel.org/netdev/net/c/07718be26568 - [net,v2,3/3] sch_cake: Fix out of bounds when parsing TCP options and header https://git.kernel.org/netdev/net/c/ba91c49dedbd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html