From: Hui Peng <benquike@gmail.com>
To: Harry Morris <h.morris@cascoda.com>,
Alexander Aring <alex.aring@gmail.com>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Stefan Schmidt <stefan@datenfreihafen.org>
Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, Hui Peng <benquike@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH net v2 3/3] ieee802154: ca8210: validate data_ind length upfront in ca8210_skb_rx()
Date: Mon, 21 Sep 2026 07:42:05 +0000 [thread overview]
Message-ID: <20260921074205.2289211-3-benquike@gmail.com> (raw)
In-Reply-To: <20260919213637.3316595-1-benquike@gmail.com>
In ca8210_skb_rx(), data_ind is read at offsets 22 (msdulen), 23
(mpdulinkquality), 29 + msdulen (hdr.sec.level), 30..39 + msdulen
(security header), and 29 .. 29 + msdulen (payload) without verifying
that the received SPI frame length len covers those offsets, causing an
out-of-bounds read when msdulen exceeds len - 30:
BUG: KASAN: slab-out-of-bounds in ca8210_skb_rx.constprop.0.isra.0+0x137/0x160
Read of size 64 at addr ffff888006453ddd by task init/1
Call Trace:
<TASK>
dump_stack_lvl+0x70/0xa0
print_report+0x153/0x4c6
kasan_report+0xf1/0x120
kasan_check_range+0x125/0x200
__asan_memcpy+0x23/0x60
ca8210_skb_rx.constprop.0.isra.0+0x137/0x160
ca8210_net_rx+0x96/0xc0
...
The buggy address belongs to the object at ffff888006453dc0
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 29 bytes inside of
allocated 32-byte region [ffff888006453dc0, ffff888006453de0)
Consolidate all length and msdulen validations into a single upfront check
at the beginning of ca8210_skb_rx() before allocating the skb.
Tested in QEMU with KASAN enabled by passing a short data_ind buffer with
msdulen = 64 and len = 30 into ca8210_skb_rx().
Fixes: ded845a781a5 ("ieee802154: Add CA8210 IEEE 802.15.4 device driver")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
Changes in v2:
- Split out as patch 3/3.
- Consolidated all length checks in ca8210_skb_rx() into a single place
at the beginning of the function before dev_alloc_skb() and dropped the
unrelated hdr.seq assignment as requested by Miquel Raynal.
drivers/net/ieee802154/ca8210.c | 32 ++++++++++++++++++++++----------
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index 1de6314..2aa7d8c 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -1759,19 +1759,15 @@ static int ca8210_skb_rx(
u8 *data_ind
)
{
- struct ieee802154_hdr hdr;
+ struct ieee802154_hdr hdr = { };
int msdulen;
int hlen;
- u8 mpdulinkquality = data_ind[23];
+ u8 mpdulinkquality;
struct sk_buff *skb;
struct ca8210_priv *priv = hw->priv;
- /* Allocate mtu size buffer for every rx packet */
- skb = dev_alloc_skb(IEEE802154_MTU + sizeof(hdr));
- if (!skb)
- return -ENOMEM;
-
- skb_reserve(skb, sizeof(hdr));
+ if (len < 30)
+ return -EMSGSIZE;
msdulen = data_ind[22]; /* msdu_length */
if (msdulen > IEEE802154_MTU) {
@@ -1779,9 +1775,25 @@ static int ca8210_skb_rx(
&priv->spi->dev,
"received erroneously large msdu length!\n"
);
- kfree_skb(skb);
return -EMSGSIZE;
}
+
+ if (len < 30 + msdulen ||
+ (!priv->promiscuous && data_ind[29 + msdulen] > 0 &&
+ len < 29 + msdulen + sizeof(struct secspec))) {
+ dev_err(&priv->spi->dev,
+ "received truncated data indication!\n");
+ return -EMSGSIZE;
+ }
+
+ mpdulinkquality = data_ind[23];
+
+ /* Allocate mtu size buffer for every rx packet */
+ skb = dev_alloc_skb(IEEE802154_MTU + sizeof(hdr));
+ if (!skb)
+ return -ENOMEM;
+
+ skb_reserve(skb, sizeof(hdr));
dev_dbg(&priv->spi->dev, "skb buffer length = %d\n", msdulen);
if (priv->promiscuous)
--
2.47.3
prev parent reply other threads:[~2026-09-21 7:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260919213637.3316595-1-benquike@gmail.com>
2026-09-21 7:42 ` [PATCH net v2 1/3] ieee802154: ca8210: prevent stack buffer overflow in ca8210_rx_done() Hui Peng
2026-09-21 9:08 ` David Laight
2026-09-21 7:42 ` [PATCH net v2 2/3] ieee802154: ca8210: prevent stack buffer overflow in hwme_get_request_sync() Hui Peng
2026-09-21 7:42 ` Hui Peng [this message]
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=20260921074205.2289211-3-benquike@gmail.com \
--to=benquike@gmail.com \
--cc=alex.aring@gmail.com \
--cc=h.morris@cascoda.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stefan@datenfreihafen.org \
/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
all inboxes | Powered by JetHome®