* [PATCH net v2] net: wwan: t7xx: validate PIT data before building RX skb
@ 2026-11-23 17:15 Fang Xieyan
2026-11-23 17:16 ` netdev-bot+sinfo
0 siblings, 1 reply; 2+ messages in thread
From: Fang Xieyan @ 2026-11-23 17:15 UTC (permalink / raw)
To: Chandrashekar Devegowda, Loic Poulain, Sergey Ryazanov,
Ilpo Järvinen, netdev
Cc: Liu Haijun, Johannes Berg, Andrew Lunn, David S . Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, linux-kernel, stable,
Lin Qiaojie
Both normal and fragment RX paths derive a data offset from the
modem-supplied PIT address and the BAT DMA base. The unsigned 64-bit
difference was stored in an int without checking the address order,
so a backwards address could wrap into a non-negative offset. The
normal path could then pass an invalid offset to skb_reserve(), while
the fragment path could pass an invalid offset and PIT data length
to skb_add_rx_frag().
These invalid ranges can make the resulting skb or fragment refer
outside the allocated buffer or DMA-mapped page. The error paths
also left consumed BAT entries unmarked, preventing BAT release and
buffer replenishment. In addition, packet assembly errors shared
the return value with the final PIT notification, so dropping a
packet could prevent consumed PIT entries from being returned to
the hardware.
Validate the address order and complete offset/length range before
building either skb representation: check normal data against both
skb tailroom and the DMA mapping length, and fragment data against
the mapped page buffer, keeping DMA-relative and page-relative
offsets separate. Extract each PIT BID once, validate it before
indexing the BAT array, and use the same index for BAT access and
bitmap updates. Cast the fragment BAT void pointer to
struct dpmaif_bat_page before pointer arithmetic. On error, free
the normal BAT skb and mark its entry consumed; also consume
fragment entries of failed packets and failed assemblies while
keeping their pages mapped for reuse. Keep packet assembly errors
separate from PIT notification errors so consumed PIT entries are
returned even when a packet is dropped.
Fixes: d642b012df70 ("net: wwan: t7xx: Add data path interface")
Cc: stable@vger.kernel.org
Reviewed-by: Lin Qiaojie <linqj@xiaopeng.com>
Signed-off-by: Fang Xieyan <fangxy@xiaopeng.com>
---
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 114 ++++++++++++++-------
1 file changed, 79 insertions(+), 35 deletions(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
index 5af90ca6e063..da4b7cb05bf3 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
@@ -282,7 +282,7 @@ static int t7xx_frag_bat_cur_bid_check(struct dpmaif_rx_queue *rxq,
if (cur_bid >= DPMAIF_FRG_COUNT)
return -EINVAL;
- bat_page = bat_frag->bat_skb + cur_bid;
+ bat_page = (struct dpmaif_bat_page *)bat_frag->bat_skb + cur_bid;
if (!bat_page->page)
return -EINVAL;
@@ -392,17 +392,15 @@ int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat
static int t7xx_dpmaif_set_frag_to_skb(const struct dpmaif_rx_queue *rxq,
const struct dpmaif_pit *pkt_info,
- struct sk_buff *skb)
+ unsigned int cur_bid, struct sk_buff *skb)
{
- unsigned long long data_bus_addr, data_base_addr;
+ unsigned long long data_bus_addr, data_base_addr, dma_offset;
struct skb_shared_info *shinfo = skb_shinfo(skb);
struct device *dev = rxq->dpmaif_ctrl->dev;
struct dpmaif_bat_page *page_info;
- unsigned int data_len;
- int data_offset;
+ unsigned int data_len, data_offset;
- page_info = rxq->bat_frag->bat_skb;
- page_info += t7xx_normal_pit_bid(pkt_info);
+ page_info = (struct dpmaif_bat_page *)rxq->bat_frag->bat_skb + cur_bid;
if (!page_info->page)
return -EINVAL;
@@ -410,14 +408,26 @@ static int t7xx_dpmaif_set_frag_to_skb(const struct dpmaif_rx_queue *rxq,
if (shinfo->nr_frags >= MAX_SKB_FRAGS)
return -EINVAL;
- dma_unmap_page(dev, page_info->data_bus_addr, page_info->data_len, DMA_FROM_DEVICE);
-
data_bus_addr = le32_to_cpu(pkt_info->pd.data_addr_h);
data_bus_addr = (data_bus_addr << 32) + le32_to_cpu(pkt_info->pd.data_addr_l);
data_base_addr = page_info->data_bus_addr;
- data_offset = data_bus_addr - data_base_addr;
- data_offset += page_info->offset;
data_len = FIELD_GET(PD_PIT_DATA_LEN, le32_to_cpu(pkt_info->header));
+
+ if (data_bus_addr < data_base_addr) {
+ dev_err_ratelimited(dev, "Invalid PIT frag data address\n");
+ return -EINVAL;
+ }
+
+ dma_offset = data_bus_addr - data_base_addr;
+ if (dma_offset > page_info->data_len ||
+ data_len > page_info->data_len - dma_offset) {
+ dev_err_ratelimited(dev, "Invalid PIT frag data offset or length\n");
+ return -EINVAL;
+ }
+
+ dma_unmap_page(dev, page_info->data_bus_addr, page_info->data_len, DMA_FROM_DEVICE);
+
+ data_offset = page_info->offset + dma_offset;
skb_add_rx_frag(skb, shinfo->nr_frags, page_info->page,
data_offset, data_len, page_info->data_len);
@@ -438,22 +448,44 @@ static int t7xx_dpmaif_get_frag(struct dpmaif_rx_queue *rxq,
if (ret < 0)
return ret;
- ret = t7xx_dpmaif_set_frag_to_skb(rxq, pkt_info, skb_info->cur_skb);
+ ret = t7xx_dpmaif_set_frag_to_skb(rxq, pkt_info, cur_bid, skb_info->cur_skb);
+ /* Mark the entry consumed on failure too, so release can reuse it. */
+ t7xx_dpmaif_set_bat_mask(rxq->bat_frag, cur_bid);
if (ret < 0) {
- dev_err(rxq->dpmaif_ctrl->dev, "Failed to set frag data to skb: %d\n", ret);
+ dev_err_ratelimited(rxq->dpmaif_ctrl->dev,
+ "Failed to set frag data to skb: %d\n", ret);
return ret;
}
- t7xx_dpmaif_set_bat_mask(rxq->bat_frag, cur_bid);
return 0;
}
+/* Consume a fragment PIT belonging to a packet that is already dropped. */
+static int t7xx_dpmaif_drop_frag(struct dpmaif_rx_queue *rxq,
+ const struct dpmaif_pit *pkt_info)
+{
+ unsigned int cur_bid = t7xx_normal_pit_bid(pkt_info);
+
+ if (t7xx_frag_bat_cur_bid_check(rxq, cur_bid))
+ return -EINVAL;
+
+ /*
+ * The page is still mapped and owned by the BAT entry; marking it
+ * consumed lets release advance and the allocator reuse the page.
+ */
+ t7xx_dpmaif_set_bat_mask(rxq->bat_frag, cur_bid);
+ return -EINVAL;
+}
+
static int t7xx_bat_cur_bid_check(struct dpmaif_rx_queue *rxq, const unsigned int cur_bid)
{
- struct dpmaif_bat_skb *bat_skb = rxq->bat_req->bat_skb;
+ struct dpmaif_bat_skb *bat_skb;
+
+ if (cur_bid >= DPMAIF_BAT_COUNT)
+ return -EINVAL;
- bat_skb += cur_bid;
- if (cur_bid >= DPMAIF_BAT_COUNT || !bat_skb->skb)
+ bat_skb = (struct dpmaif_bat_skb *)rxq->bat_req->bat_skb + cur_bid;
+ if (!bat_skb->skb)
return -EINVAL;
return 0;
@@ -627,38 +659,50 @@ static void t7xx_dpmaif_parse_msg_pit(const struct dpmaif_rx_queue *rxq,
static int t7xx_dpmaif_set_data_to_skb(const struct dpmaif_rx_queue *rxq,
const struct dpmaif_pit *pkt_info,
+ unsigned int cur_bid,
struct dpmaif_cur_rx_skb_info *skb_info)
{
- unsigned long long data_bus_addr, data_base_addr;
+ unsigned long long data_bus_addr, data_base_addr, data_offset;
struct device *dev = rxq->dpmaif_ctrl->dev;
struct dpmaif_bat_skb *bat_skb;
- unsigned int data_len;
+ unsigned int data_len, tailroom, max_len;
struct sk_buff *skb;
- int data_offset;
- bat_skb = rxq->bat_req->bat_skb;
- bat_skb += t7xx_normal_pit_bid(pkt_info);
+ bat_skb = (struct dpmaif_bat_skb *)rxq->bat_req->bat_skb + cur_bid;
dma_unmap_single(dev, bat_skb->data_bus_addr, bat_skb->data_len, DMA_FROM_DEVICE);
data_bus_addr = le32_to_cpu(pkt_info->pd.data_addr_h);
data_bus_addr = (data_bus_addr << 32) + le32_to_cpu(pkt_info->pd.data_addr_l);
data_base_addr = bat_skb->data_bus_addr;
- data_offset = data_bus_addr - data_base_addr;
data_len = FIELD_GET(PD_PIT_DATA_LEN, le32_to_cpu(pkt_info->header));
skb = bat_skb->skb;
skb->len = 0;
skb_reset_tail_pointer(skb);
- skb_reserve(skb, data_offset);
- if (skb->tail + data_len > skb->end) {
- dev_err(dev, "No buffer space available\n");
- return -ENOBUFS;
+ if (data_bus_addr < data_base_addr) {
+ dev_err_ratelimited(dev, "Invalid PIT data address\n");
+ goto err_drop;
+ }
+
+ data_offset = data_bus_addr - data_base_addr;
+ tailroom = skb_tailroom(skb);
+ max_len = min(tailroom, bat_skb->data_len);
+ if (data_offset > max_len || data_len > max_len - data_offset) {
+ dev_err_ratelimited(dev, "Invalid PIT data offset or length\n");
+ goto err_drop;
}
+ skb_reserve(skb, (int)data_offset);
skb_put(skb, data_len);
skb_info->cur_skb = skb;
bat_skb->skb = NULL;
return 0;
+
+err_drop:
+ dev_kfree_skb_any(skb);
+ bat_skb->skb = NULL;
+ t7xx_dpmaif_set_bat_mask(rxq->bat_req, cur_bid);
+ return -ENOBUFS;
}
static int t7xx_dpmaif_get_rx_pkt(struct dpmaif_rx_queue *rxq,
@@ -672,9 +716,9 @@ static int t7xx_dpmaif_get_rx_pkt(struct dpmaif_rx_queue *rxq,
if (ret < 0)
return ret;
- ret = t7xx_dpmaif_set_data_to_skb(rxq, pkt_info, skb_info);
+ ret = t7xx_dpmaif_set_data_to_skb(rxq, pkt_info, cur_bid, skb_info);
if (ret < 0) {
- dev_err(rxq->dpmaif_ctrl->dev, "RX set data to skb failed: %d\n", ret);
+ dev_err_ratelimited(rxq->dpmaif_ctrl->dev, "RX set data to skb failed: %d\n", ret);
return ret;
}
@@ -726,7 +770,7 @@ static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned int
unsigned int cur_pit, pit_len, rx_cnt, recv_skb_cnt = 0;
struct device *dev = rxq->dpmaif_ctrl->dev;
struct dpmaif_cur_rx_skb_info *skb_info;
- int ret = 0;
+ int ret = 0, pkt_ret;
pit_len = rxq->pit_size_cnt;
skb_info = &rxq->rx_data_info;
@@ -756,13 +800,13 @@ static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned int
} else { /* DES_PT_PD */
val = FIELD_GET(PD_PIT_BUFFER_TYPE, le32_to_cpu(pkt_info->header));
if (val != PKT_BUF_FRAG)
- ret = t7xx_dpmaif_get_rx_pkt(rxq, pkt_info, skb_info);
- else if (!skb_info->cur_skb)
- ret = -EINVAL;
+ pkt_ret = t7xx_dpmaif_get_rx_pkt(rxq, pkt_info, skb_info);
+ else if (skb_info->err_payload || !skb_info->cur_skb)
+ pkt_ret = t7xx_dpmaif_drop_frag(rxq, pkt_info);
else
- ret = t7xx_dpmaif_get_frag(rxq, pkt_info, skb_info);
+ pkt_ret = t7xx_dpmaif_get_frag(rxq, pkt_info, skb_info);
- if (ret < 0) {
+ if (pkt_ret < 0) {
skb_info->err_payload = 1;
dev_err_ratelimited(dev, "RXQ%u error payload\n", rxq->index);
}
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] net: wwan: t7xx: validate PIT data before building RX skb
2026-11-23 17:15 [PATCH net v2] net: wwan: t7xx: validate PIT data before building RX skb Fang Xieyan
@ 2026-11-23 17:16 ` netdev-bot+sinfo
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-11-23 17:16 UTC (permalink / raw)
To: Fang Xieyan
Cc: Chandrashekar Devegowda, Loic Poulain, Sergey Ryazanov,
Ilpo Järvinen, netdev, Liu Haijun, Johannes Berg,
Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, linux-kernel, stable, Lin Qiaojie
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-23 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 17:15 [PATCH net v2] net: wwan: t7xx: validate PIT data before building RX skb Fang Xieyan
2026-11-23 17:16 ` netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox