Netdev List
 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
  2026-11-23  6:39 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ 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 related	[flat|nested] 4+ 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
  2026-11-19  9:59   ` Fang Xieyan
  2026-11-23  6:39 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ 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] 4+ messages in thread

* Re: [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve
  2026-11-19  6:23 ` netdev-bot+sinfo
@ 2026-11-19  9:59   ` Fang Xieyan
  0 siblings, 0 replies; 4+ messages in thread
From: Fang Xieyan @ 2026-11-19  9:59 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: fangxy, chandrashekar.devegowda, loic.poulain, ryazanov.s.a,
	ilpo.jarvinen, netdev, haijun.liu, johannes, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-kernel, stable, linqj

The issue was found during a security review of the t7xx driver's
device-supplied input paths, assisted by the Hawkeye agent
(LLM-based code analysis).

It has now been reproduced with a fault-injection harness in a
KASAN-enabled QEMU guest. No t7xx hardware is available, so the
harness synthesizes a malformed PIT and calls
t7xx_dpmaif_set_data_to_skb() directly; this is a synthetic trigger,
not a natural one.

With a PIT data address 128 bytes below the BAT DMA base, the int
offset becomes -128. The existing tail+length check passes because
the unsigned tail wraps, skb_reserve() then moves skb->data 64 bytes
before skb->head, and reading the payload triggers:

  BUG: KASAN: slab-out-of-bounds in t7xx15_harness_run+0xa4f/0xda0 [mtk_t7xx]
  Read of size 1 at addr ff11000002095340 by task insmod/67
  Call Trace:
   <TASK>
   dump_stack_lvl+0x55/0x70
   print_report+0x10d/0x5d0
   kasan_report+0x96/0xd0
   t7xx15_harness_run+0xa4f/0xda0 [mtk_t7xx]
   t7xx_pci_init+0x9/0xff0 [mtk_t7xx]
   do_one_initcall+0x84/0x350
   do_init_module+0x29d/0x800
   load_module+0x510c/0x6630
   init_module_from_file+0x15d/0x180
   idempotent_init_module+0x320/0x670
   __x64_sys_finit_module+0xbd/0x120
   do_syscall_64+0xee/0x500
   entry_SYSCALL_64_after_hwframe+0x77/0x7f
   </TASK>
  The buggy address belongs to the object at ff11000002095040
   which belongs to the cache skbuff_small_head of size 704
  The buggy address is located 64 bytes to the right of
   allocated 704-byte region [ff11000002095040, ff11000002095300)

The read address matches the corrupted skb->data (skb->head - 64).
A second case, where the u64 address difference narrows to a small
positive int, is also accepted by the unpatched code. With this
patch applied, both inputs are rejected with -ENOBUFS and no KASAN
report is produced.

^ permalink raw reply	[flat|nested] 4+ 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
@ 2026-11-23  6:39 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23  6:39 UTC (permalink / raw)
  To: fangxy
  Cc: chandrashekar.devegowda, loic.poulain, ryazanov.s.a,
	ilpo.jarvinen, netdev, haijun.liu, johannes, andrew+netdev, davem,
	edumazet, kuba, pabeni, linux-kernel, stable, linqj

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 2 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch fixes the modem-supplied PIT address/length problem
  only for the normal BAT path.
- [High] The new err_drop path in t7xx_dpmaif_set_data_to_skb() calls
  `t7xx_dpmaif_set_bat_mask(rxq->bat_req,…
- [Medium] The patch makes the normal-BAT error path free the skb and set
  the entry's bit in bat_req->bat_bitmap, so release can move past it.

--

net: wwan: t7xx: validate PIT data offset before skb_reserve

This patch makes t7xx_dpmaif_set_data_to_skb() check the modem-supplied
PIT data address and length against the skb tailroom and the DMA mapping
length before it calls skb_reserve(). On error it now frees the skb and
marks the normal BAT entry consumed, so the BAT ring can be released and
refilled.

> diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
> index 5af90ca6e0631..44e2ba15984df 100644
> --- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
> +++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c

[ ... ]

> @@ -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));

[ ... ]

> +	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;
>  	}

[Severity: High]
Does t7xx_dpmaif_set_frag_to_skb() need the same validation? It derives
the offset in the same way from the modem-supplied PIT address, and
still stores it in an int:

drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c:t7xx_dpmaif_set_frag_to_skb() {
    ...
	int data_offset;
    ...
	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));
	skb_add_rx_frag(skb, shinfo->nr_frags, page_info->page,
			data_offset, data_len, page_info->data_len);
    ...
}

On this path the only check is t7xx_frag_bat_cur_bid_check(). It
validates the BID, but not the address or the length. PD_PIT_DATA_LEN is
a 16-bit field (GENMASK(31,16)), and the fragment buffer is only
DPMAIF_HW_FRG_PKTBUF (128) bytes. skb_add_rx_frag() does no bounds
checking of its own.

PKT_BUF_FRAG PD PITs come from the same PIT ring, through
t7xx_dpmaif_rx_start()->t7xx_dpmaif_get_frag(). A backwards address, or
an oversized offset or length, would produce a fragment that points
outside the 128-byte DMA-mapped buffer. A negative int offset would also
become a huge fragment offset.

Could later GRO header pulls, checksum walks or socket copies then read
memory outside the fragment allocation? Should the frag path also reject
data_bus_addr < data_base_addr, and any offset plus length beyond
page_info->data_len?

>  
> +	skb_reserve(skb, (int)data_offset);

[ ... ]

> +
> +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));

[Severity: High]
This line reads the BID from the PIT entry again. The PIT ring
(rxq->pit_base) is dma_alloc_coherent() memory, so the device can write
to it.

The caller t7xx_dpmaif_get_rx_pkt() has already read the BID into
cur_bid and bounded it with t7xx_bat_cur_bid_check()
(cur_bid < DPMAIF_BAT_COUNT). That checked value is not passed down to
this function.

A re-read BID can be as large as 65535 (PD_PIT_H_BID << 13 plus
PD_PIT_BUFFER_ID). bat_bitmap comes from
bitmap_zalloc(DPMAIF_BAT_COUNT), so it holds 8192 bits. Because
dma_unmap_single() and dev_kfree_skb_any() sit between the reads, the
value really is loaded again from coherent memory.

If the modem rewrites the PIT entry after the caller's check, can the
set_bit() in t7xx_dpmaif_set_bat_mask() write past the end of
bat_bitmap?

Even if the index stays in range, the bit could land on a different slot
from the one whose skb was just freed. The freed slot would then stay
unmarked, and a slot the hardware still owns would be counted as
consumed and refilled.

The earlier re-read in "bat_skb += t7xx_normal_pit_bid(pkt_info)" has
the same problem and predates this patch. Would it help to pass the
validated cur_bid down (or read the PIT words once) and use that one
value for both the bat_skb indexing and the bitmap update?

> +	return -ENOBUFS;
>  }

[Severity: Medium]
This path now marks the normal BAT entry consumed. Can the frag BAT ring
still stall in the same way, from the same malformed input?

When the head PD is rejected here, skb_info->cur_skb stays NULL. Every
following PKT_BUF_FRAG PIT of the same packet then takes this branch in
t7xx_dpmaif_rx_start():

		else if (!skb_info->cur_skb)
			ret = -EINVAL;

That branch leaves the frag page mapped and never sets its bit in
rxq->bat_frag->bat_bitmap.

t7xx_dpmaif_get_frag() also sets the bit only on success:

	ret = t7xx_dpmaif_set_frag_to_skb(rxq, pkt_info, skb_info->cur_skb);
	if (ret < 0) {
		dev_err(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);

So a failure such as shinfo->nr_frags >= MAX_SKB_FRAGS leaves the entry
unmarked as well.

t7xx_dpmaif_avail_pkt_bat_cnt() counts set bits with
find_next_zero_bit() starting at bat_release_rd_idx. One unmarked frag
entry therefore stops release and refill of the frag ring for good.

Isn't this the same "stall BAT release and buffer replenishment" problem
the commit message describes, only on the frag ring?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119062044.72261-1-fangxy%40xiaopeng.com

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

end of thread, other threads:[~2026-11-23  6:39 UTC | newest]

Thread overview: 4+ 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
2026-11-19  9:59   ` Fang Xieyan
2026-11-23  6:39 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox