* [PATCH net] net: expand textsearch ts_state to fit skb_seq_state
@ 2021-03-01 15:09 Willem de Bruijn
2021-03-01 23:54 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Willem de Bruijn @ 2021-03-01 15:09 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, Willem de Bruijn, Kris Karas
From: Willem de Bruijn <willemb@google.com>
The referenced commit expands the skb_seq_state used by
skb_find_text with a 4B frag_off field, growing it to 48B.
This exceeds container ts_state->cb, causing a stack corruption:
[ 73.238353] Kernel panic - not syncing: stack-protector: Kernel stack
is corrupted in: skb_find_text+0xc5/0xd0
[ 73.247384] CPU: 1 PID: 376 Comm: nping Not tainted 5.11.0+ #4
[ 73.252613] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
BIOS 1.14.0-2 04/01/2014
[ 73.260078] Call Trace:
[ 73.264677] dump_stack+0x57/0x6a
[ 73.267866] panic+0xf6/0x2b7
[ 73.270578] ? skb_find_text+0xc5/0xd0
[ 73.273964] __stack_chk_fail+0x10/0x10
[ 73.277491] skb_find_text+0xc5/0xd0
[ 73.280727] string_mt+0x1f/0x30
[ 73.283639] ipt_do_table+0x214/0x410
The struct is passed between skb_find_text and its callbacks
skb_prepare_seq_read, skb_seq_read and skb_abort_seq read through
the textsearch interface using TS_SKB_CB.
I assumed that this mapped to skb->cb like other .._SKB_CB wrappers.
skb->cb is 48B. But it maps to ts_state->cb, which is only 40B.
skb->cb was increased from 40B to 48B after ts_state was introduced,
in commit 3e3850e989c5 ("[NETFILTER]: Fix xfrm lookup in
ip_route_me_harder/ip6_route_me_harder").
Increase ts_state.cb[] to 48 to fit the struct.
Also add a BUILD_BUG_ON to avoid a repeat.
The alternative is to directly add a dependency from textsearch onto
linux/skbuff.h, but I think the intent is textsearch to have no such
dependencies on its callers.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=211911
Fixes: 97550f6fa592 ("net: compound page support in skb_seq_read")
Reported-by: Kris Karas <bugs-a17@moonlit-rail.com>
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
include/linux/textsearch.h | 2 +-
net/core/skbuff.c | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/textsearch.h b/include/linux/textsearch.h
index 13770cfe33ad..6673e4d4ac2e 100644
--- a/include/linux/textsearch.h
+++ b/include/linux/textsearch.h
@@ -23,7 +23,7 @@ struct ts_config;
struct ts_state
{
unsigned int offset;
- char cb[40];
+ char cb[48];
};
/**
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 545a472273a5..c421c8f80925 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3659,6 +3659,8 @@ unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
struct ts_state state;
unsigned int ret;
+ BUILD_BUG_ON(sizeof(struct skb_seq_state) > sizeof(state.cb));
+
config->get_next_block = skb_ts_get_next_block;
config->finish = skb_ts_finish;
--
2.30.1.766.gb4fecdf3b7-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: expand textsearch ts_state to fit skb_seq_state
2021-03-01 15:09 [PATCH net] net: expand textsearch ts_state to fit skb_seq_state Willem de Bruijn
@ 2021-03-01 23:54 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-03-01 23:54 UTC (permalink / raw)
To: Willem de Bruijn; +Cc: netdev, davem, kuba, willemb, bugs-a17
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
On Mon, 1 Mar 2021 15:09:44 +0000 you wrote:
> From: Willem de Bruijn <willemb@google.com>
>
> The referenced commit expands the skb_seq_state used by
> skb_find_text with a 4B frag_off field, growing it to 48B.
>
> This exceeds container ts_state->cb, causing a stack corruption:
>
> [...]
Here is the summary with links:
- [net] net: expand textsearch ts_state to fit skb_seq_state
https://git.kernel.org/netdev/net/c/b228c9b05876
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-02 8:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 15:09 [PATCH net] net: expand textsearch ts_state to fit skb_seq_state Willem de Bruijn
2021-03-01 23:54 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).