mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve
@ 2026-11-19  6:20 Fang Xieyan
  2026-11-19  6:23 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Fang Xieyan @ 2026-11-19  6:20 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

t7xx_dpmaif_set_data_to_skb() derives the data offset from the
modem-supplied PIT data address and the driver's BAT DMA base address.
The unsigned 64-bit difference is stored in an int, so a backwards
address can wrap into a non-negative value and escape validation.
A negative offset passed to skb_reserve() moves skb->data and
skb->tail before skb->head. The subsequent skb_put() then extends
the skb over an invalid range, allowing later packet processing
to access memory outside the allocated buffer. The existing tail/end
check runs after skb_reserve() and only guards the tail side.

Compare the addresses in the unsigned domain and validate the offset
and data length against both the skb tailroom and the DMA mapping
length before calling skb_reserve(). This subsumes the old tail/end
check.

On error the DMA mapping is already torn down, but the skb stayed
assigned to the BAT entry and the entry was never marked consumed.
This leaves the BAT entry unreclaimable and can eventually stall BAT
release and buffer replenishment. Free the skb and mark the entry
consumed so it can be released and reallocated.

Reject invalid packets with -ENOBUFS.

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 | 29 ++++++++++++++++------
 1 file changed, 21 insertions(+), 8 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..44e2ba15984d 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
@@ -632,9 +632,9 @@ static int t7xx_dpmaif_set_data_to_skb(const struct dpmaif_rx_queue *rxq,
 	unsigned long long data_bus_addr, data_base_addr;
 	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;
+	unsigned long long data_offset;
 
 	bat_skb = rxq->bat_req->bat_skb;
 	bat_skb += t7xx_normal_pit_bid(pkt_info);
@@ -643,22 +643,35 @@ static int t7xx_dpmaif_set_data_to_skb(const struct dpmaif_rx_queue *rxq,
 	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, t7xx_normal_pit_bid(pkt_info));
+	return -ENOBUFS;
 }
 
 static int t7xx_dpmaif_get_rx_pkt(struct dpmaif_rx_queue *rxq,
@@ -674,7 +687,7 @@ static int t7xx_dpmaif_get_rx_pkt(struct dpmaif_rx_queue *rxq,
 
 	ret = t7xx_dpmaif_set_data_to_skb(rxq, pkt_info, 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;
 	}
 
-- 
2.50.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve
  2026-11-19  6:20 [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve Fang Xieyan
@ 2026-11-19  6:23 ` netdev-bot+sinfo
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19  6:23 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-19  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  6:20 [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve Fang Xieyan
2026-11-19  6:23 ` 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

all inboxes | Powered by JetHome®