From: Arnd Bergmann <arnd@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Willem de Bruijn <willemb@google.com>
Cc: Arnd Bergmann <arnd@arndb.de>, Alexander Lobakin <alobakin@pm.me>,
Jonathan Lemon <jonathan.lemon@gmail.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Guillaume Nault <gnault@redhat.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [RFC net] net: skbuff: fix stack variable out of bounds access
Date: Tue, 23 Mar 2021 13:52:24 +0100 [thread overview]
Message-ID: <20210323125233.1743957-1-arnd@kernel.org> (raw)
From: Arnd Bergmann <arnd@arndb.de>
gcc-11 warns that the TS_SKB_CB(&state)) cast in skb_find_text()
leads to an out-of-bounds access in skb_prepare_seq_read() after
the addition of a new struct member made skb_seq_state longer
than ts_state:
net/core/skbuff.c: In function ‘skb_find_text’:
net/core/skbuff.c:3498:26: error: array subscript ‘struct skb_seq_state[0]’ is partly outside array bounds of ‘struct ts_state[1]’ [-Werror=array-bounds]
3498 | st->lower_offset = from;
| ~~~~~~~~~~~~~~~~~^~~~~~
net/core/skbuff.c:3659:25: note: while referencing ‘state’
3659 | struct ts_state state;
| ^~~~~
The warning is currently disabled globally, but I found this
instance during experimental build testing, and it seems
legitimate.
Make the textsearch buffer longer and add a compile-time check to
ensure the two remain the same length.
Fixes: 97550f6fa592 ("net: compound page support in skb_seq_read")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
include/linux/textsearch.h | 2 +-
net/core/skbuff.c | 1 +
2 files changed, 2 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..dd10d4c5f4bf 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3633,6 +3633,7 @@ static unsigned int skb_ts_get_next_block(unsigned int offset, const u8 **text,
struct ts_config *conf,
struct ts_state *state)
{
+ BUILD_BUG_ON(sizeof(struct skb_seq_state) > sizeof(state->cb));
return skb_seq_read(offset, text, TS_SKB_CB(state));
}
--
2.29.2
next reply other threads:[~2021-03-23 12:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-23 12:52 Arnd Bergmann [this message]
2021-03-23 14:42 ` [RFC net] net: skbuff: fix stack variable out of bounds access Willem de Bruijn
2021-03-23 16:29 ` Arnd Bergmann
2021-03-23 17:14 ` Willem de Bruijn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210323125233.1743957-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=alobakin@pm.me \
--cc=arnd@arndb.de \
--cc=davem@davemloft.net \
--cc=gnault@redhat.com \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).