net: wwan: t7xx: validate PIT data before building RX skb
Subsystems (5)
PATCH v2 1/1 net: wwan: t7xx: validate PIT data before building RX skb
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.
--- drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 114 ++++++++++++++------- 1 file changed, 79 insertions(+), 35 deletions(-)
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +79 -35
@@ -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_batstatic 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 intunsigned 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); }
Signature · 1 line
2.50.1
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
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.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
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 is reproduced at runtime, not only theoretical. No t7xx hardware is available, so a fault-injection harness in a KASAN-enabled QEMU guest synthesizes malformed PIT entries and drives the RX assembly paths; this is a synthetic trigger, not a natural one.
On the normal path, a PIT data address 128 bytes below the BAT DMA base yields an int offset of -128. The unpatched code accepts it, skb_reserve() moves skb->data before skb->head, and reading the payload triggers:
BUG: KASAN: slab-out-of-bounds in t7xx15_harness_run+0x1a5e/0x2340 [mtk_t7xx] Read of size 1 at addr ff110000013bd000 by task insmod/71 Call Trace: <TASK> dump_stack_lvl+0x55/0x70 print_report+0x10d/0x5d0 kasan_report+0x96/0xd0 t7xx15_harness_run+0x1a5e/0x2340 [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 ff110000013bcd00 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 [ff110000013bcd00, ff110000013bcfc0)
A second input, where the u64 address difference narrows to a small positive int, is also accepted by the unpatched code. On the fragment path, a negative offset likewise reaches the page copy and faults on an unmapped address. With this patch applied, all of these inputs are rejected (-ENOBUFS on the normal path, -EINVAL on the fragment path) and no KASAN report or fault is produced.
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (4) · Low: 1
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).
- [Medium] The new err_drop path in t7xx_dpmaif_set_data_to_skb() frees the normal BAT skb (dev_kfree_skb_any) and marks the modem-supplied…
- [Low] The commit message undersells or leaves out several of the patch's changes, and it bundles several independent fixes into one…
Pre-existing issues:
- [Medium] Not introduced by this patch: a normal (non-fragment) PD PIT that arrives while skb_info->cur_skb is already set overwrites cur_skb…
- [Medium] Not introduced by this patch: t7xx_dpmaif_stop_rxq() clears rxq->rx_data_info with memset() without freeing skb_info->cur_skb.
- [Medium] Not introduced by this patch: both RX queues (DPMAIF_RXQ_NUM =
2) share one normal BAT and one frag BAT.
- [Medium] Not introduced by this patch, though the new drop path keeps the same behaviour: when a PD PIT's BID fails t7xx_bat_cur_bid_check()…
--
net: wwan: t7xx: validate PIT data before building RX skb
The patch checks the modem-supplied PIT data address, offset and length against the BAT buffer before the RX skb is built, in both the normal and fragment paths. It marks BAT entries as consumed on error and adds a drop path for fragments of packets that have already failed. It also keeps packet assembly errors separate from PIT notification errors in t7xx_dpmaif_rx_start().
Quoted 3 lines
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.
[Severity: Low]
Is this description complete? For a small backwards distance, truncating the u64 difference to an int gives a negative value. For example, base - 16 becomes -16, and that value was then passed to skb_reserve().
Quoted 2 lines
Cast the fragment BAT void pointer to
structdpmaif_bat_pagebefore pointer arithmetic.
This reads like a cosmetic change, but the baseline code was:
bat_page = bat_frag->bat_skb + cur_bid;
That is arithmetic on a void pointer, so it advanced by cur_bid bytes rather than cur_bid entries. t7xx_frag_bat_cur_bid_check() therefore read a misaligned ->page field from the wrong place.
The new t7xx_dpmaif_drop_frag() relies only on this helper before it sets a bitmap bit. Could the message describe this as a functional fix, so backporters know it is a prerequisite?
The message also leaves out a few changes:
- The dev_err() to dev_err_ratelimited() conversions in
t7xx_dpmaif_get_frag() and t7xx_dpmaif_get_rx_pkt().
- t7xx_dpmaif_rx_start() no longer returns a negative value to the NAPI poll path when a packet is dropped. The sentence about keeping packet assembly errors separate from PIT notification errors only implies this.
Since this is tagged for stable, would it make sense to split it into separate, bisectable fixes? The frag BID arithmetic, the normal-path range check, the frag-path range check, the BAT accounting on error and the PIT notify separation each look independent.
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +0
-0@@ -438,22 +448,44 @@ static int t7xx_dpmaif_get_frag(struct dpmaif_rx_queue *rxq,
[ ... ]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static int t7xx_dpmaif_get_frag(struct dpmaif_rx_queue *rxq, · line 470
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +8
-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 ;
[Severity: Medium]
This is a pre-existing issue, and the new drop path behaves the same way. When the BID fails t7xx_frag_bat_cur_bid_check(), or t7xx_bat_cur_bid_check() in t7xx_dpmaif_get_rx_pkt(), no bitmap bit is set at all. The check fails when the BID is out of range or when the slot's page or skb is NULL.
The hardware still consumed some BAT or FRG entry for that PIT. Release stops at the first zero bit:
t7xx_dpmaif_avail_pkt_bat_cnt() {
...
zero_index = find_next_zero_bit(bat_req->bat_bitmap, bat_req->bat_size_cnt,
bat_req->bat_release_rd_idx);
...
}Can the release cursor get stuck on that consumed but unmarked slot? If so, t7xx_dpmaif_rx_buf_alloc() and t7xx_dpmaif_rx_frag_alloc() never refill, and DL RX stalls until the queue is restarted. The DL BAT error interrupts only log, so nothing triggers a reset.
The driver cannot tell which slot a bad BID referred to. Would this case need a recovery step, such as a queue reset or a resync from the hardware read index, rather than another set_bit?
Quoted 12 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +9
-1+ +/* +* 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;
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static int t7xx_dpmaif_get_frag(struct dpmaif_rx_queue *rxq, · line 489
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +6
-2+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 ;
[Severity: Medium]
This isn't a bug introduced by this patch, but both RX queues share one normal BAT and one frag BAT:
t7xx_dpmaif_rx_alloc() {
...
rxq->bat_req = &rxq->dpmaif_ctrl->bat_req;
...
rxq->bat_frag = &rxq->dpmaif_ctrl->bat_frag;
...
}Each queue has its own NAPI instance, and only bat_bitmap is protected by mask_lock. The per-entry bat_skb[bid].skb and bat_page[bid].page fields are checked here and used later without a lock. The later use is in t7xx_dpmaif_set_data_to_skb(), t7xx_dpmaif_set_frag_to_skb() or t7xx_dpmaif_drop_frag().
If the modem reports the same BID on PITs for both queues, could RXQ0 and RXQ1 both pass this check and then race on the same entry? Possible results:
- a second dma_unmap_single() on the same buffer
- a NULL dereference at skb->len = 0 after the other CPU cleared
bat_skb->skb
- both CPUs taking the same skb, either as cur_skb or through the new err_drop dev_kfree_skb_any()
- in the frag path, a double dma_unmap_page() and one page attached to two skbs
[ ... ]
Quoted 7 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1
-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) {
[ ... ]
Quoted 4 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1
-2- 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 );
[ ... ]
Quoted 14 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +12
-0+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);
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static void t7xx_dpmaif_parse_msg_pit(const struct dpmaif_rx_queue *rxq, · line 705
Quoted 10 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +6
-0skb_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 ;
[Severity: Medium]
Is it safe to free the skb here? A wrong BID is exactly what produces a PIT data address outside this BID's buffer. t7xx_bat_cur_bid_check() only checks that cur_bid is in range and that bat_skb->skb is non-NULL. Nothing compares cur_bid against the hardware BAT read index.
If that entry is still posted in the BAT ring, its descriptor keeps the old DMA address until t7xx_dpmaif_rx_buf_alloc() rewrites it, which happens only after release passes that slot. On systems without an IOMMU, could a later modem DMA into this entry write into the freed skb?
The baseline -ENOBUFS path had its own problems. It left the skb unmapped with modified data and tail pointers, and the entry was never marked. But it did not free memory the device could still write to.
dma_unmap_single() also still runs before any of this validation. If the checks ran first, could the mapping be kept and the buffer reused, as the frag path now does?
[ ... ]
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned int · line 803
Quoted 8 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1
-3@@ -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);
[Severity: Medium]
This is a pre-existing issue. What happens when a non-fragment PD PIT arrives while skb_info->cur_skb is already set? This can happen when the earlier PIT had PD_PIT_CONT set, including after a failed fragment has set err_payload.
This branch calls t7xx_dpmaif_get_rx_pkt() regardless of cur_skb or err_payload. t7xx_dpmaif_set_data_to_skb() then does:
skb_info->cur_skb = skb; bat_skb->skb = NULL;
Does this leak the previous skb? Its BAT slot was already marked consumed and refilled, so nothing limits how many skbs can leak this way. The new err_payload / !cur_skb check covers fragment PITs but not normal PITs.
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c static int t7xx_dpmaif_rx_start(struct dpmaif_rx_queue *rxq, const unsigned int · line 812
Quoted 11 lines
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +4
-2+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); }
[Severity: Medium]
This isn't a bug introduced by this patch, but cur_skb can survive across NAPI polls in two cases:
- t7xx_dpmaif_rx_start() returns early on a PIT sequence-check failure in the middle of a packet.
- The loop ends at pit_cnt while the hardware write index is in the middle of a packet.
If the queue is then stopped, t7xx_dpmaif_rx_clear()->t7xx_dpmaif_stop_rxq() does:
t7xx_dpmaif_stop_rxq() {
...
memset(&rxq->rx_data_info, 0, sizeof(rxq->rx_data_info));
...
}It never calls dev_kfree_skb_any() on skb_info->cur_skb. Does this leak the partly assembled skb, along with any pages attached through skb_add_rx_frag()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123171519.33975-1-fangxy%40xiaopeng.com