* [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown
@ 2026-12-03 6:26 Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
Malformed modem PIT/BAT and handshake blobs can OOB the host driver.
An in-flight CLDMA IRQ can requeue work after stop and UAF the rings.
Handshake work and skb ownership races can double-free.
Each patch is one failure class:
0001 DPMAIF RX validation and BAT refill
A.1.a PIT/BAT buffer_id used as index before validation
A.1.c partial BAT refill loses unreplenished RX slots
B.4 PIT nr_frags exceeds MAX_SKB_FRAGS
B.5 32-bit DMA offset truncates a 64-bit address
A.1.b already in t7xx_ccmni_recv_skb() (no change)
0002 control / PORT_ENUM payload length
B.3 PORT_ENUM length / port_count OOB
0003 runtime-feature handshake blob bounds
B.1 malformed runtime-feature data OOB read
0004 CLDMA IRQ/work vs ring teardown
B.2 in-flight IRQ requeues work after stop (UAF)
F.3 same class; not copied from the Fibocom empty-handler
lock wrap
0005 handshake races and remaining skb lifetime bugs
F.1 MHCCIF re-queues handshake while the first run is active
F.2 core_ap.ready stays set; handshake races cldma_reset
F.4 CLDMA TX sleep-disable timeout double-free
F.5 dedicated recv error return double-free
F.6 DPMAIF TX peek/unlink UAF
0001 is DPMAIF data path only. Control-message checks are 0002.
B.1 still rejects a truncated feature (-EINVAL) but does not require
FEATURE_COUNT entries; firmware may advertise a subset of complete
features.
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
Wanquan Zhong (5):
t7xx: validate PIT/BAT ids and restore failed RX BAT refill
t7xx: validate control-message and PORT_ENUM payload lengths
t7xx: reject malformed runtime-feature handshake data
t7xx: stop in-flight CLDMA IRQ and work before ring teardown
t7xx: fix handshake races and skb double-free on TX/RX
drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 125 +++++++----
drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 2 +
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 4 +-
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 1 +
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 231 ++++++++++++++++-----
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 7 +-
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 5 +-
drivers/net/wwan/t7xx/t7xx_modem_ops.c | 65 ++++--
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 21 +-
drivers/net/wwan/t7xx/t7xx_port_proxy.c | 3 +-
drivers/net/wwan/t7xx/t7xx_state_monitor.c | 1 +
11 files changed, 353 insertions(+), 112 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
@ 2026-12-03 6:26 ` Wanquan Zhong
2026-12-03 13:47 ` kernel test robot
2026-12-03 6:26 ` [PATCH net 2/5] t7xx: validate control-message and PORT_ENUM payload lengths Wanquan Zhong
` (4 subsequent siblings)
5 siblings, 1 reply; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
This is the DPMAIF RX data-path half of the v1.0.33 host checks. It
does not touch the control-message path.
A.1.a A malformed PIT buffer_id was used as an array index before
it was range-checked. Reject an out-of-range or empty BAT id
without writing the occupancy bitmap.
A.1.c A partial BAT refill left already-released slots off the free
pool, so RX capacity shrank over time. Restore the unallocated
tail of bat_release_rd_idx and retry via bat_pending_refill.
B.4 Modem PIT data could make skb_add_rx_frag() exceed MAX_SKB_FRAGS.
Unmap and drop a bad payload, then still consume a valid BAT id.
B.5 A 32-bit DMA offset truncated a 64-bit address into the skb.
Validate the range with u64 addresses before skb_put /
skb_add_rx_frag.
A valid BAT id is always consumed after cleanup. An illegal id is not.
A.1.b (netif / ccmni_inst[]) is already handled in t7xx_ccmni_recv_skb().
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c | 4 +-
drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h | 1 +
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c | 231 ++++++++++++++++-----
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h | 7 +-
4 files changed, 190 insertions(+), 53 deletions(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
index 7ff33c1d6ac7..a27b36ea7a8b 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.c
@@ -326,14 +326,14 @@ static int t7xx_dpmaif_start(struct dpmaif_ctrl *dpmaif_ctrl)
bitmap_zero(dpmaif_ctrl->bat_req.bat_bitmap, dpmaif_ctrl->bat_req.bat_size_cnt);
buf_cnt = dpmaif_ctrl->bat_req.bat_size_cnt - 1;
- ret = t7xx_dpmaif_rx_buf_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_req, 0, buf_cnt, true);
+ ret = t7xx_dpmaif_rx_buf_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_req, 0, buf_cnt, true, NULL);
if (ret) {
dev_err(dpmaif_ctrl->dev, "Failed to allocate RX buffer: %d\n", ret);
return ret;
}
buf_cnt = dpmaif_ctrl->bat_frag.bat_size_cnt - 1;
- ret = t7xx_dpmaif_rx_frag_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_frag, buf_cnt, true);
+ ret = t7xx_dpmaif_rx_frag_alloc(dpmaif_ctrl, &dpmaif_ctrl->bat_frag, buf_cnt, true, NULL);
if (ret) {
dev_err(dpmaif_ctrl->dev, "Failed to allocate frag RX buffer: %d\n", ret);
goto err_free_normal_bat;
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
index 0ce4505e813d..58ae73213687 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif.h
@@ -86,6 +86,7 @@ struct dpmaif_bat_request {
unsigned int bat_size_cnt;
unsigned int bat_wr_idx;
unsigned int bat_release_rd_idx;
+ unsigned int bat_pending_refill;
void *bat_skb;
unsigned int pkt_buf_sz;
unsigned long *bat_bitmap;
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
index 5af90ca6e063..aa7231f07939 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c
@@ -78,6 +78,79 @@ static unsigned int t7xx_normal_pit_bid(const struct dpmaif_pit *pit_info)
return value;
}
+static void t7xx_dpmaif_drop_normal_slot(const struct dpmaif_rx_queue *rxq,
+ unsigned int cur_bid)
+{
+ struct dpmaif_bat_request *bat_req = rxq->bat_req;
+ struct dpmaif_bat_skb *bat_skb = bat_req->bat_skb + cur_bid;
+ struct device *dev = rxq->dpmaif_ctrl->dev;
+
+ if (!bat_skb->skb)
+ return;
+
+ dma_unmap_single(dev, bat_skb->data_bus_addr, bat_skb->data_len,
+ DMA_FROM_DEVICE);
+ dev_kfree_skb_any(bat_skb->skb);
+ bat_skb->skb = NULL;
+}
+
+static void t7xx_dpmaif_drop_frag_slot(const struct dpmaif_rx_queue *rxq,
+ unsigned int cur_bid)
+{
+ struct dpmaif_bat_request *bat_frag = rxq->bat_frag;
+ struct dpmaif_bat_page *page_info = bat_frag->bat_skb + cur_bid;
+ struct device *dev = rxq->dpmaif_ctrl->dev;
+
+ if (!page_info->page)
+ return;
+
+ dma_unmap_page(dev, page_info->data_bus_addr, page_info->data_len,
+ DMA_FROM_DEVICE);
+ put_page(page_info->page);
+ page_info->page = NULL;
+ page_info->offset = 0;
+ page_info->data_len = 0;
+}
+
+static bool t7xx_dpmaif_rx_data_range_valid(u64 data_addr, u64 base_addr,
+ u32 data_len, u32 buffer_len,
+ u32 *data_offset)
+{
+ u64 offset;
+
+ if (data_addr < base_addr)
+ return false;
+
+ offset = data_addr - base_addr;
+ if (offset > buffer_len || data_len > buffer_len - offset)
+ return false;
+
+ *data_offset = (u32)offset;
+ return true;
+}
+
+static void t7xx_dpmaif_restore_bat_release(struct dpmaif_bat_request *bat_req,
+ unsigned int restore_cnt)
+{
+ unsigned long flags;
+ unsigned int i, index;
+
+ if (!restore_cnt)
+ return;
+
+ spin_lock_irqsave(&bat_req->mask_lock, flags);
+ index = bat_req->bat_release_rd_idx;
+ for (i = 0; i < restore_cnt; i++) {
+ if (!index)
+ index = bat_req->bat_size_cnt;
+ index--;
+ set_bit(index, bat_req->bat_bitmap);
+ }
+ bat_req->bat_release_rd_idx = index;
+ bat_req->bat_pending_refill = restore_cnt;
+ spin_unlock_irqrestore(&bat_req->mask_lock, flags);
+}
+
static int t7xx_dpmaif_update_bat_wr_idx(struct dpmaif_ctrl *dpmaif_ctrl,
const unsigned int q_num, const unsigned int bat_cnt)
{
@@ -163,12 +236,15 @@ static void t7xx_unmap_bat_skb(struct device *dev, struct dpmaif_bat_skb *bat_sk
* * -ERROR - Error code.
*/
int t7xx_dpmaif_rx_buf_alloc(struct dpmaif_ctrl *dpmaif_ctrl,
- const struct dpmaif_bat_request *bat_req,
+ struct dpmaif_bat_request *bat_req,
const unsigned int q_num, const unsigned int buf_cnt,
- const bool initial)
+ const bool initial, unsigned int *allocated_cnt)
{
unsigned int i, bat_cnt, bat_max_cnt, bat_start_idx;
- int ret;
+ int ret, alloc_ret = 0;
+
+ if (allocated_cnt)
+ *allocated_cnt = 0;
if (!buf_cnt || buf_cnt > bat_req->bat_size_cnt)
return -EINVAL;
@@ -193,8 +269,10 @@ int t7xx_dpmaif_rx_buf_alloc(struct dpmaif_ctrl *dpmaif_ctrl,
cur_skb = (struct dpmaif_bat_skb *)bat_req->bat_skb + cur_bat_idx;
if (!cur_skb->skb &&
- !t7xx_alloc_and_map_skb_info(dpmaif_ctrl, bat_req->pkt_buf_sz, cur_skb))
+ !t7xx_alloc_and_map_skb_info(dpmaif_ctrl, bat_req->pkt_buf_sz, cur_skb)) {
+ alloc_ret = -ENOMEM;
break;
+ }
cur_bat = (struct dpmaif_bat *)bat_req->bat_base + cur_bat_idx;
cur_bat->buffer_addr_ext = upper_32_bits(cur_skb->data_bus_addr);
@@ -202,12 +280,15 @@ int t7xx_dpmaif_rx_buf_alloc(struct dpmaif_ctrl *dpmaif_ctrl,
}
if (!i)
- return -ENOMEM;
+ return alloc_ret ? alloc_ret : -ENOMEM;
ret = t7xx_dpmaif_update_bat_wr_idx(dpmaif_ctrl, q_num, i);
if (ret)
goto err_unmap_skbs;
+ if (allocated_cnt)
+ *allocated_cnt = i;
+
if (!initial) {
unsigned int hw_wr_idx;
@@ -224,11 +305,15 @@ int t7xx_dpmaif_rx_buf_alloc(struct dpmaif_ctrl *dpmaif_ctrl,
}
}
+ if (alloc_ret)
+ return alloc_ret;
+
return 0;
err_unmap_skbs:
while (i--)
- t7xx_unmap_bat_skb(dpmaif_ctrl->dev, bat_req->bat_skb, i);
+ t7xx_unmap_bat_skb(dpmaif_ctrl->dev, (struct dpmaif_bat_skb *)bat_req->bat_skb,
+ (bat_start_idx + i) % bat_max_cnt);
return ret;
}
@@ -279,7 +364,7 @@ static int t7xx_frag_bat_cur_bid_check(struct dpmaif_rx_queue *rxq,
struct dpmaif_bat_request *bat_frag = rxq->bat_frag;
struct dpmaif_bat_page *bat_page;
- if (cur_bid >= DPMAIF_FRG_COUNT)
+ if (cur_bid >= bat_frag->bat_size_cnt)
return -EINVAL;
bat_page = bat_frag->bat_skb + cur_bid;
@@ -318,12 +403,16 @@ static void t7xx_unmap_bat_page(struct device *dev, struct dpmaif_bat_page *bat_
* * -ERROR - Error code.
*/
int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat_request *bat_req,
- const unsigned int buf_cnt, const bool initial)
+ const unsigned int buf_cnt, const bool initial,
+ unsigned int *allocated_cnt)
{
unsigned int buf_space, cur_bat_idx = bat_req->bat_wr_idx;
struct dpmaif_bat_page *bat_skb = bat_req->bat_skb;
int ret = 0, i;
+ if (allocated_cnt)
+ *allocated_cnt = 0;
+
if (!buf_cnt || buf_cnt > bat_req->bat_size_cnt)
return -EINVAL;
@@ -376,6 +465,12 @@ int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat
bat_req->bat_wr_idx = cur_bat_idx;
+ if (!i)
+ return -ENOMEM;
+
+ if (allocated_cnt)
+ *allocated_cnt = i;
+
if (!initial)
t7xx_dpmaif_dl_snd_hw_frg_cnt(&dpmaif_ctrl->hw_info, i);
@@ -392,32 +487,36 @@ 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)
+ struct sk_buff *skb, unsigned int cur_bid)
{
- unsigned long long data_bus_addr, data_base_addr;
+ u64 data_bus_addr, data_base_addr;
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;
+ u32 data_len, data_offset;
- page_info = rxq->bat_frag->bat_skb;
- page_info += t7xx_normal_pit_bid(pkt_info);
+ page_info = rxq->bat_frag->bat_skb + cur_bid;
if (!page_info->page)
return -EINVAL;
- 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 (!t7xx_dpmaif_rx_data_range_valid(data_bus_addr, data_base_addr, data_len,
+ page_info->data_len, &data_offset) ||
+ shinfo->nr_frags >= MAX_SKB_FRAGS) {
+ dev_err_ratelimited(dev,
+ "invalid frag: bid=%u addr=%llx base=%llx len=%u buf=%u nr_frags=%u\n",
+ cur_bid, data_bus_addr, data_base_addr, data_len,
+ page_info->data_len, shinfo->nr_frags);
+ return -EINVAL;
+ }
+
+ dma_unmap_page(dev, page_info->data_bus_addr, page_info->data_len, DMA_FROM_DEVICE);
+ data_offset += page_info->offset;
skb_add_rx_frag(skb, shinfo->nr_frags, page_info->page,
data_offset, data_len, page_info->data_len);
@@ -435,25 +534,32 @@ static int t7xx_dpmaif_get_frag(struct dpmaif_rx_queue *rxq,
int ret;
ret = t7xx_frag_bat_cur_bid_check(rxq, cur_bid);
- if (ret < 0)
+ if (ret < 0) {
+ dev_err_ratelimited(rxq->dpmaif_ctrl->dev,
+ "invalid frag BAT id: %u\n", cur_bid);
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, skb_info->cur_skb, cur_bid);
if (ret < 0) {
dev_err(rxq->dpmaif_ctrl->dev, "Failed to set frag data to skb: %d\n", ret);
- return ret;
+ t7xx_dpmaif_drop_frag_slot(rxq, cur_bid);
}
t7xx_dpmaif_set_bat_mask(rxq->bat_frag, cur_bid);
- return 0;
+ return ret;
}
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_request *bat_req = rxq->bat_req;
+ struct dpmaif_bat_skb *bat_skb;
+
+ if (cur_bid >= bat_req->bat_size_cnt)
+ return -EINVAL;
- bat_skb += cur_bid;
- if (cur_bid >= DPMAIF_BAT_COUNT || !bat_skb->skb)
+ bat_skb = bat_req->bat_skb + cur_bid;
+ if (!bat_skb->skb)
return -EINVAL;
return 0;
@@ -575,11 +681,12 @@ static int t7xx_dpmaif_pit_release_and_add(struct dpmaif_rx_queue *rxq)
static int t7xx_dpmaif_bat_release_and_add(const struct dpmaif_rx_queue *rxq)
{
- unsigned int bid_cnt;
+ struct dpmaif_bat_request *bat_req = rxq->bat_req;
+ unsigned int bid_cnt, allocated_cnt = 0;
int ret;
- bid_cnt = t7xx_dpmaif_avail_pkt_bat_cnt(rxq->bat_req);
- if (bid_cnt < DPMAIF_BAT_CNT_THRESHOLD)
+ bid_cnt = t7xx_dpmaif_avail_pkt_bat_cnt(bat_req);
+ if (bid_cnt < DPMAIF_BAT_CNT_THRESHOLD && !bat_req->bat_pending_refill)
return 0;
ret = t7xx_dpmaif_release_bat_entry(rxq, bid_cnt, BAT_TYPE_NORMAL);
@@ -588,7 +695,13 @@ static int t7xx_dpmaif_bat_release_and_add(const struct dpmaif_rx_queue *rxq)
return ret;
}
- ret = t7xx_dpmaif_rx_buf_alloc(rxq->dpmaif_ctrl, rxq->bat_req, rxq->index, bid_cnt, false);
+ ret = t7xx_dpmaif_rx_buf_alloc(rxq->dpmaif_ctrl, bat_req, rxq->index, bid_cnt,
+ false, &allocated_cnt);
+ if (allocated_cnt < bid_cnt)
+ t7xx_dpmaif_restore_bat_release(bat_req, bid_cnt - allocated_cnt);
+ else
+ bat_req->bat_pending_refill = 0;
+
if (ret < 0)
dev_err(rxq->dpmaif_ctrl->dev, "Allocate new RX buffer failed: %d\n", ret);
@@ -597,11 +710,12 @@ static int t7xx_dpmaif_bat_release_and_add(const struct dpmaif_rx_queue *rxq)
static int t7xx_dpmaif_frag_bat_release_and_add(const struct dpmaif_rx_queue *rxq)
{
- unsigned int bid_cnt;
+ struct dpmaif_bat_request *bat_frag = rxq->bat_frag;
+ unsigned int bid_cnt, allocated_cnt = 0;
int ret;
- bid_cnt = t7xx_dpmaif_avail_pkt_bat_cnt(rxq->bat_frag);
- if (bid_cnt < DPMAIF_BAT_CNT_THRESHOLD)
+ bid_cnt = t7xx_dpmaif_avail_pkt_bat_cnt(bat_frag);
+ if (bid_cnt < DPMAIF_BAT_CNT_THRESHOLD && !bat_frag->bat_pending_refill)
return 0;
ret = t7xx_dpmaif_release_bat_entry(rxq, bid_cnt, BAT_TYPE_FRAG);
@@ -610,7 +724,14 @@ static int t7xx_dpmaif_frag_bat_release_and_add(const struct dpmaif_rx_queue *rx
return ret;
}
- return t7xx_dpmaif_rx_frag_alloc(rxq->dpmaif_ctrl, rxq->bat_frag, bid_cnt, false);
+ ret = t7xx_dpmaif_rx_frag_alloc(rxq->dpmaif_ctrl, bat_frag, bid_cnt, false,
+ &allocated_cnt);
+ if (allocated_cnt < bid_cnt)
+ t7xx_dpmaif_restore_bat_release(bat_frag, bid_cnt - allocated_cnt);
+ else
+ bat_frag->bat_pending_refill = 0;
+
+ return ret;
}
static void t7xx_dpmaif_parse_msg_pit(const struct dpmaif_rx_queue *rxq,
@@ -627,24 +748,32 @@ 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,
- struct dpmaif_cur_rx_skb_info *skb_info)
+ struct dpmaif_cur_rx_skb_info *skb_info,
+ unsigned int cur_bid)
{
- unsigned long long data_bus_addr, data_base_addr;
+ u64 data_bus_addr, data_base_addr;
struct device *dev = rxq->dpmaif_ctrl->dev;
struct dpmaif_bat_skb *bat_skb;
- unsigned int data_len;
+ u32 data_len, data_offset;
struct sk_buff *skb;
- int data_offset;
- bat_skb = rxq->bat_req->bat_skb;
- bat_skb += t7xx_normal_pit_bid(pkt_info);
- dma_unmap_single(dev, bat_skb->data_bus_addr, bat_skb->data_len, DMA_FROM_DEVICE);
+ bat_skb = rxq->bat_req->bat_skb + cur_bid;
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 (!t7xx_dpmaif_rx_data_range_valid(data_bus_addr, data_base_addr, data_len,
+ bat_skb->data_len, &data_offset)) {
+ dev_err_ratelimited(dev,
+ "invalid pkt: bid=%u addr=%llx base=%llx len=%u buf=%u\n",
+ cur_bid, data_bus_addr, data_base_addr, data_len,
+ bat_skb->data_len);
+ return -EINVAL;
+ }
+
+ dma_unmap_single(dev, bat_skb->data_bus_addr, bat_skb->data_len, DMA_FROM_DEVICE);
skb = bat_skb->skb;
skb->len = 0;
skb_reset_tail_pointer(skb);
@@ -652,6 +781,8 @@ static int t7xx_dpmaif_set_data_to_skb(const struct dpmaif_rx_queue *rxq,
if (skb->tail + data_len > skb->end) {
dev_err(dev, "No buffer space available\n");
+ dev_kfree_skb(skb);
+ bat_skb->skb = NULL;
return -ENOBUFS;
}
@@ -669,17 +800,20 @@ static int t7xx_dpmaif_get_rx_pkt(struct dpmaif_rx_queue *rxq,
int ret;
ret = t7xx_bat_cur_bid_check(rxq, cur_bid);
- if (ret < 0)
+ if (ret < 0) {
+ dev_err_ratelimited(rxq->dpmaif_ctrl->dev,
+ "invalid normal BAT id: %u\n", cur_bid);
return ret;
+ }
- ret = t7xx_dpmaif_set_data_to_skb(rxq, pkt_info, skb_info);
+ ret = t7xx_dpmaif_set_data_to_skb(rxq, pkt_info, skb_info, cur_bid);
if (ret < 0) {
dev_err(rxq->dpmaif_ctrl->dev, "RX set data to skb failed: %d\n", ret);
- return ret;
+ t7xx_dpmaif_drop_normal_slot(rxq, cur_bid);
}
t7xx_dpmaif_set_bat_mask(rxq->bat_req, cur_bid);
- return 0;
+ return ret;
}
static int t7xx_dpmaifq_rx_notify_hw(struct dpmaif_rx_queue *rxq)
@@ -959,6 +1093,7 @@ int t7xx_dpmaif_bat_alloc(const struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_b
bat_req->type = buf_type;
bat_req->bat_wr_idx = 0;
bat_req->bat_release_rd_idx = 0;
+ bat_req->bat_pending_refill = 0;
bat_req->bat_base = dma_alloc_coherent(dpmaif_ctrl->dev,
bat_req->bat_size_cnt * sizeof(struct dpmaif_bat),
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
index f4e1b69ad426..d781c7dbfeef 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.h
@@ -99,11 +99,12 @@ int t7xx_dpmaif_rxq_init(struct dpmaif_rx_queue *queue);
void t7xx_dpmaif_rx_clear(struct dpmaif_ctrl *dpmaif_ctrl);
int t7xx_dpmaif_bat_rel_wq_alloc(struct dpmaif_ctrl *dpmaif_ctrl);
int t7xx_dpmaif_rx_buf_alloc(struct dpmaif_ctrl *dpmaif_ctrl,
- const struct dpmaif_bat_request *bat_req,
+ struct dpmaif_bat_request *bat_req,
const unsigned int q_num, const unsigned int buf_cnt,
- const bool initial);
+ const bool initial, unsigned int *allocated_cnt);
int t7xx_dpmaif_rx_frag_alloc(struct dpmaif_ctrl *dpmaif_ctrl, struct dpmaif_bat_request *bat_req,
- const unsigned int buf_cnt, const bool first_time);
+ const unsigned int buf_cnt, const bool initial,
+ unsigned int *allocated_cnt);
void t7xx_dpmaif_rx_stop(struct dpmaif_ctrl *dpmaif_ctrl);
void t7xx_dpmaif_irq_rx_done(struct dpmaif_ctrl *dpmaif_ctrl, const unsigned int que_mask);
void t7xx_dpmaif_rxq_free(struct dpmaif_rx_queue *queue);
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 2/5] t7xx: validate control-message and PORT_ENUM payload lengths
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
@ 2026-12-03 6:26 ` Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 3/5] t7xx: reject malformed runtime-feature handshake data Wanquan Zhong
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
This is for B.3. The host could read past a PORT_ENUM or HS2 control
message when data_length or the skb was shorter than the header
claimed.
Require a full ctrl_msg_header. Reject HS2 and PORT_ENUM payloads
that exceed the skb. Pass the header data_length into
t7xx_port_enum_msg_handler() instead of skb->len so port_count is
checked against the claimed payload. Free the skb on the unknown
message path as well as on PORT_ENUM; the RX thread does not free
it from the return value.
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c b/drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
index f869e4ed9ee9..ce25d43c86dd 100644
--- a/drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
+++ b/drivers/net/wwan/t7xx/t7xx_port_ctrl_msg.c
@@ -176,7 +176,23 @@ static int control_msg_handler(struct t7xx_port *port, struct sk_buff *skb)
struct ctrl_msg_header *ctrl_msg_h;
int ret = 0;
+ if (!skb || skb->len < sizeof(*ctrl_msg_h)) {
+ dev_err(port->dev, "Invalid control message length: %u\n", skb ? skb->len : 0);
+ dev_kfree_skb_any(skb);
+ return -EINVAL;
+ }
+
ctrl_msg_h = (struct ctrl_msg_header *)skb->data;
+
+ if ((le32_to_cpu(ctrl_msg_h->ctrl_msg_id) == CTL_ID_HS2_MSG ||
+ le32_to_cpu(ctrl_msg_h->ctrl_msg_id) == CTL_ID_PORT_ENUM) &&
+ le32_to_cpu(ctrl_msg_h->data_length) > skb->len - sizeof(*ctrl_msg_h)) {
+ dev_err(port->dev, "Invalid control message payload length: %u/%zu\n",
+ le32_to_cpu(ctrl_msg_h->data_length), skb->len - sizeof(*ctrl_msg_h));
+ dev_kfree_skb_any(skb);
+ return -EINVAL;
+ }
+
switch (le32_to_cpu(ctrl_msg_h->ctrl_msg_id)) {
case CTL_ID_HS2_MSG:
skb_pull(skb, sizeof(*ctrl_msg_h));
@@ -205,19 +221,22 @@ static int control_msg_handler(struct t7xx_port *port, struct sk_buff *skb)
case CTL_ID_PORT_ENUM:
skb_pull(skb, sizeof(*ctrl_msg_h));
- ret = t7xx_port_enum_msg_handler(ctl->md, (struct port_msg *)skb->data, skb->len);
+ ret = t7xx_port_enum_msg_handler(ctl->md, (struct port_msg *)skb->data,
+ le32_to_cpu(ctrl_msg_h->data_length));
if (!ret)
ret = port_ctl_send_msg_to_md(port, CTL_ID_PORT_ENUM, 0);
else
ret = port_ctl_send_msg_to_md(port, CTL_ID_PORT_ENUM,
PORT_ENUM_VER_MISMATCH);
+ dev_kfree_skb_any(skb);
break;
default:
ret = -EINVAL;
dev_err(port->dev, "Unknown control message ID to FSM %x\n",
le32_to_cpu(ctrl_msg_h->ctrl_msg_id));
+ dev_kfree_skb_any(skb);
break;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 3/5] t7xx: reject malformed runtime-feature handshake data
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 2/5] t7xx: validate control-message and PORT_ENUM payload lengths Wanquan Zhong
@ 2026-12-03 6:26 ` Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 4/5] t7xx: stop in-flight CLDMA IRQ and work before ring teardown Wanquan Zhong
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
This is for B.1. Malformed runtime-feature blobs can make the host
walk off the end of the handshake buffer.
Validate the feature header and payload lengths before using them.
Fail a truncated header or data_len with -EINVAL. Propagate PORT_ENUM
errors for MUST features.
Do not require FEATURE_COUNT entries: firmware may advertise a
subset of complete runtime features. A truncated record is not a
subset; a subset ends on a complete feature at offset == length.
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
drivers/net/wwan/t7xx/t7xx_modem_ops.c | 42 ++++++++++++++++----------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
index adb29d30c63f..e5065bf55bd6 100644
--- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c
+++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
@@ -453,40 +453,50 @@ static int t7xx_parse_host_rt_data(struct t7xx_fsm_ctl *ctl, struct t7xx_sys_inf
{
enum mtk_feature_support_type ft_spt_st, ft_spt_cfg;
struct mtk_runtime_feature *rt_feature;
- int i, offset;
+ int i, offset, ret = 0;
+ size_t remaining, feat_data_len;
offset = sizeof(struct feature_query);
- for (i = 0; i < FEATURE_COUNT && offset < data_length; i++) {
- size_t remaining = data_length - offset;
- size_t feat_data_len, feat_total;
+ if (!data || data_length < offset)
+ return -EINVAL;
- if (remaining < sizeof(*rt_feature))
+ for (i = 0; i < FEATURE_COUNT && offset < data_length; i++) {
+ remaining = data_length - offset;
+ if (remaining < sizeof(*rt_feature)) {
+ ret = -EINVAL;
break;
+ }
rt_feature = data + offset;
feat_data_len = le32_to_cpu(rt_feature->data_len);
-
- if (feat_data_len > remaining - sizeof(*rt_feature))
+ if (feat_data_len > remaining - sizeof(*rt_feature)) {
+ ret = -EINVAL;
break;
-
- feat_total = sizeof(*rt_feature) + feat_data_len;
- offset += feat_total;
+ }
ft_spt_cfg = FIELD_GET(FEATURE_MSK, core->feature_set[i]);
- if (ft_spt_cfg != MTK_FEATURE_MUST_BE_SUPPORTED)
+ if (ft_spt_cfg != MTK_FEATURE_MUST_BE_SUPPORTED) {
+ offset += sizeof(*rt_feature) + feat_data_len;
continue;
+ }
ft_spt_st = FIELD_GET(FEATURE_MSK, rt_feature->support_info);
- if (ft_spt_st != MTK_FEATURE_MUST_BE_SUPPORTED)
- return -EINVAL;
+ if (ft_spt_st != MTK_FEATURE_MUST_BE_SUPPORTED) {
+ ret = -EINVAL;
+ break;
+ }
if (i == RT_ID_MD_PORT_ENUM || i == RT_ID_AP_PORT_ENUM) {
- t7xx_port_enum_msg_handler(ctl->md, rt_feature->data,
- feat_data_len);
+ ret = t7xx_port_enum_msg_handler(ctl->md, rt_feature->data,
+ feat_data_len);
+ if (ret)
+ break;
}
+
+ offset += sizeof(*rt_feature) + feat_data_len;
}
- return 0;
+ return ret;
}
static int t7xx_core_reset(struct t7xx_modem *md)
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 4/5] t7xx: stop in-flight CLDMA IRQ and work before ring teardown
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
` (2 preceding siblings ...)
2026-12-03 6:26 ` [PATCH net 3/5] t7xx: reject malformed runtime-feature handshake data Wanquan Zhong
@ 2026-12-03 6:26 ` Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 5/5] t7xx: fix handshake races and skb double-free on TX/RX Wanquan Zhong
2026-12-03 6:33 ` [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown netdev-bot+sinfo
5 siblings, 0 replies; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
This is for B.2, and it also covers Fibocom F.3. An in-flight IRQ
can requeue CLDMA work after the queues are stopped, so the worker
touches rings that teardown has already freed.
Gate the ISR on cldma_irq_enabled. Queue TX/RX work, and let workers
re-queue or unmask L2, only while the queue is active, holding
cldma_lock for that check. Do not nest that lock around the TX empty
handler.
Look up pci_irq_vector(pdev, phy_interrupt_id) at stop/reset and
synchronize_irq() before cancel_work_sync(). t7xx_cldma_init() runs
before MSI-X allocation, so the vector must not be cached there.
phy_interrupt_id is already the in-tree MSI-X index; do not apply
the vendor PCIe OFFSET.
t7xx_cldma_disable_irq() already clears the MAC mask. Skip
t7xx_pcie_mac_set_int() at the end of a racing ISR so stop cannot
be undone by an empty MSI. Always rebuild rings on switch_cfg:
callers use it as reinit, and the first handshake would skip
late_init if an unchanged cfg_id returned early.
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 110 +++++++++++++++++++------
drivers/net/wwan/t7xx/t7xx_hif_cldma.h | 2 +
2 files changed, 86 insertions(+), 26 deletions(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
index 2917cee9b802..622cb8ee0282 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
@@ -24,6 +24,7 @@
#include <linux/dma-mapping.h>
#include <linux/dma-direction.h>
#include <linux/gfp.h>
+#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/iopoll.h>
@@ -239,17 +240,27 @@ static void t7xx_cldma_rx_done(struct work_struct *work)
{
struct cldma_queue *queue = container_of(work, struct cldma_queue, cldma_work);
struct cldma_ctrl *md_ctrl = queue->md_ctrl;
+ unsigned long flags;
int value;
value = t7xx_cldma_gpd_rx_collect(queue, queue->budget);
- if (value && md_ctrl->rxq_active & BIT(queue->index)) {
- queue_work(queue->worker, &queue->cldma_work);
- return;
+ if (value) {
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+ if (md_ctrl->rxq_active & BIT(queue->index)) {
+ queue_work(queue->worker, &queue->cldma_work);
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+ return;
+ }
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
}
- t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info);
- t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX);
- t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX);
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+ if (md_ctrl->rxq_active & BIT(queue->index)) {
+ t7xx_cldma_clear_ip_busy(&md_ctrl->hw_info);
+ t7xx_cldma_hw_irq_en_txrx(&md_ctrl->hw_info, queue->index, MTK_RX);
+ t7xx_cldma_hw_irq_en_eq(&md_ctrl->hw_info, queue->index, MTK_RX);
+ }
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
pm_runtime_put_autosuspend(md_ctrl->dev);
}
@@ -349,8 +360,13 @@ static void t7xx_cldma_tx_done(struct work_struct *work)
if (l2_tx_int & BIT(queue->index)) {
t7xx_cldma_hw_tx_done(hw_info, BIT(queue->index));
- queue_work(queue->worker, &queue->cldma_work);
- return;
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+ if (md_ctrl->txq_active & BIT(queue->index)) {
+ queue_work(queue->worker, &queue->cldma_work);
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+ return;
+ }
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
}
spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
@@ -535,20 +551,37 @@ static void t7xx_cldma_txq_init(struct cldma_queue *queue)
static void t7xx_cldma_enable_irq(struct cldma_ctrl *md_ctrl)
{
- t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
+ if (atomic_cmpxchg(&md_ctrl->cldma_irq_enabled, 0, 1) == 0)
+ t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
}
static void t7xx_cldma_disable_irq(struct cldma_ctrl *md_ctrl)
{
- t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
+ if (atomic_cmpxchg(&md_ctrl->cldma_irq_enabled, 1, 0) == 1)
+ t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, md_ctrl->hw_info.phy_interrupt_id);
+}
+
+static void t7xx_cldma_synchronize_irq(struct cldma_ctrl *md_ctrl)
+{
+ int irq;
+
+ /* Look up after pci_alloc_irq_vectors(); t7xx_cldma_init() runs first. */
+ irq = pci_irq_vector(md_ctrl->t7xx_dev->pdev,
+ md_ctrl->hw_info.phy_interrupt_id);
+ if (irq >= 0)
+ synchronize_irq(irq);
}
static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
{
unsigned long l2_tx_int_msk, l2_rx_int_msk, l2_tx_int, l2_rx_int, val;
struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
+ unsigned long flags;
int i;
+ if (!atomic_read(&md_ctrl->cldma_irq_enabled))
+ return;
+
/* L2 raw interrupt status */
l2_tx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2TISAR0);
l2_rx_int = ioread32(hw_info->ap_pdn_base + REG_CLDMA_L2RISAR0);
@@ -570,12 +603,16 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
if (l2_tx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
for_each_set_bit(i, &l2_tx_int, L2_INT_BIT_COUNT) {
if (i < CLDMA_TXQ_NUM) {
- pm_runtime_get(md_ctrl->dev);
- t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX);
- t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX);
- queue_work(md_ctrl->txq[i].worker,
- &md_ctrl->txq[i].cldma_work);
- } else {
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+ if (md_ctrl->txq_active & BIT(i)) {
+ pm_runtime_get(md_ctrl->dev);
+ t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_TX);
+ t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_TX);
+ queue_work(md_ctrl->txq[i].worker,
+ &md_ctrl->txq[i].cldma_work);
+ }
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+ } else if (md_ctrl->txq_active & BIT(i - CLDMA_TXQ_NUM)) {
t7xx_cldma_txq_empty_hndl(&md_ctrl->txq[i - CLDMA_TXQ_NUM]);
}
}
@@ -595,10 +632,15 @@ static void t7xx_cldma_irq_work_cb(struct cldma_ctrl *md_ctrl)
if (l2_rx_int & (TXRX_STATUS_BITMASK | EMPTY_STATUS_BITMASK)) {
l2_rx_int |= l2_rx_int >> CLDMA_RXQ_NUM;
for_each_set_bit(i, &l2_rx_int, CLDMA_RXQ_NUM) {
- pm_runtime_get(md_ctrl->dev);
- t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX);
- t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX);
- queue_work(md_ctrl->rxq[i].worker, &md_ctrl->rxq[i].cldma_work);
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
+ if (md_ctrl->rxq_active & BIT(i)) {
+ pm_runtime_get(md_ctrl->dev);
+ t7xx_cldma_hw_irq_dis_eq(hw_info, i, MTK_RX);
+ t7xx_cldma_hw_irq_dis_txrx(hw_info, i, MTK_RX);
+ queue_work(md_ctrl->rxq[i].worker,
+ &md_ctrl->rxq[i].cldma_work);
+ }
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
}
}
}
@@ -633,15 +675,20 @@ static bool t7xx_cldma_qs_are_active(struct cldma_ctrl *md_ctrl)
int t7xx_cldma_stop(struct cldma_ctrl *md_ctrl)
{
struct t7xx_cldma_hw *hw_info = &md_ctrl->hw_info;
+ unsigned long flags;
bool active;
int i, ret;
+ spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
md_ctrl->rxq_active = 0;
- t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX);
md_ctrl->txq_active = 0;
- t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX);
md_ctrl->txq_started = 0;
+ spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+
+ t7xx_cldma_hw_stop_all_qs(hw_info, MTK_RX);
+ t7xx_cldma_hw_stop_all_qs(hw_info, MTK_TX);
t7xx_cldma_disable_irq(md_ctrl);
+ t7xx_cldma_synchronize_irq(md_ctrl);
t7xx_cldma_hw_stop(hw_info, MTK_RX);
t7xx_cldma_hw_stop(hw_info, MTK_TX);
t7xx_cldma_hw_tx_done(hw_info, CLDMA_L2TISAR0_ALL_INT_MASK);
@@ -649,10 +696,10 @@ int t7xx_cldma_stop(struct cldma_ctrl *md_ctrl)
if (md_ctrl->is_late_init) {
for (i = 0; i < CLDMA_TXQ_NUM; i++)
- flush_work(&md_ctrl->txq[i].cldma_work);
+ cancel_work_sync(&md_ctrl->txq[i].cldma_work);
for (i = 0; i < CLDMA_RXQ_NUM; i++)
- flush_work(&md_ctrl->rxq[i].cldma_work);
+ cancel_work_sync(&md_ctrl->rxq[i].cldma_work);
}
ret = read_poll_timeout(t7xx_cldma_qs_are_active, active, !active, CHECK_Q_STOP_STEP_US,
@@ -689,9 +736,12 @@ void t7xx_cldma_reset(struct cldma_ctrl *md_ctrl)
spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
md_ctrl->txq_active = 0;
md_ctrl->rxq_active = 0;
- t7xx_cldma_disable_irq(md_ctrl);
+ md_ctrl->txq_started = 0;
spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
+ t7xx_cldma_disable_irq(md_ctrl);
+ t7xx_cldma_synchronize_irq(md_ctrl);
+
for (i = 0; i < CLDMA_TXQ_NUM; i++) {
cancel_work_sync(&md_ctrl->txq[i].cldma_work);
@@ -1262,7 +1312,8 @@ static irqreturn_t t7xx_cldma_isr_handler(int irq, void *data)
t7xx_pcie_mac_clear_int(md_ctrl->t7xx_dev, interrupt);
t7xx_cldma_irq_work_cb(md_ctrl);
t7xx_pcie_mac_clear_int_status(md_ctrl->t7xx_dev, interrupt);
- t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, interrupt);
+ if (atomic_read(&md_ctrl->cldma_irq_enabled))
+ t7xx_pcie_mac_set_int(md_ctrl->t7xx_dev, interrupt);
return IRQ_HANDLED;
}
@@ -1305,6 +1356,7 @@ int t7xx_cldma_init(struct cldma_ctrl *md_ctrl)
md_ctrl->txq_active = 0;
md_ctrl->rxq_active = 0;
md_ctrl->is_late_init = false;
+ atomic_set(&md_ctrl->cldma_irq_enabled, 0);
ret = t7xx_cldma_pm_init(md_ctrl);
if (ret)
@@ -1351,6 +1403,12 @@ int t7xx_cldma_init(struct cldma_ctrl *md_ctrl)
void t7xx_cldma_switch_cfg(struct cldma_ctrl *md_ctrl, enum cldma_cfg cfg_id)
{
+ if (t7xx_cldma_stop(md_ctrl)) {
+ dev_err(md_ctrl->dev, "Stop CLDMA%d before switching config failed\n",
+ md_ctrl->hif_id);
+ return;
+ }
+
t7xx_cldma_late_release(md_ctrl);
t7xx_cldma_adjust_config(md_ctrl, cfg_id);
t7xx_cldma_late_init(md_ctrl);
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.h b/drivers/net/wwan/t7xx/t7xx_hif_cldma.h
index 9d0107e18a7b..d8fc28b1814f 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.h
+++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.h
@@ -18,6 +18,7 @@
#ifndef __T7XX_HIF_CLDMA_H__
#define __T7XX_HIF_CLDMA_H__
+#include <linux/atomic.h>
#include <linux/bits.h>
#include <linux/device.h>
#include <linux/dmapool.h>
@@ -111,6 +112,7 @@ struct cldma_ctrl {
struct md_pm_entity *pm_entity;
struct t7xx_cldma_hw hw_info;
bool is_late_init;
+ atomic_t cldma_irq_enabled;
};
#define CLDMA_Q_IDX_DUMP 1
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH net 5/5] t7xx: fix handshake races and skb double-free on TX/RX
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
` (3 preceding siblings ...)
2026-12-03 6:26 ` [PATCH net 4/5] t7xx: stop in-flight CLDMA IRQ and work before ring teardown Wanquan Zhong
@ 2026-12-03 6:26 ` Wanquan Zhong
2026-12-03 6:33 ` [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown netdev-bot+sinfo
5 siblings, 0 replies; 8+ messages in thread
From: Wanquan Zhong @ 2026-12-03 6:26 UTC (permalink / raw)
To: netdev
Cc: chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel, zwq2226404116
This is the Fibocom handshake and skb-lifetime set. F.3 is not
copied here; CLDMA work UAF on stop is handled by the preceding
teardown patch.
F.1 MHCCIF can re-queue handshake work while the first run is
still active. Mask ASYNC_MD_HK after queue_work. Do not add
a second t7xx_cldma_stop() in the work: switch_cfg already
stops CLDMA.
F.2 core_ap.ready can stay set across reset, so handshake work
races t7xx_cldma_reset(). Clear AP handshake state, append
AP_HS2_EXIT, and always drain handshake works then reset
CLDMA even if the HS2_EXIT append fails.
F.4 A sleep-disable timeout after the skb is already in the
CLDMA TX ring lets the caller and completion both free it.
Wait for sleep-disable before publishing the skb.
F.5 Dedicated recv_skb that frees then returns an error makes
CLDMA redeliver and free again. Return 0 after consume/drop.
Stop AP CLDMA before switching to NORMAL ports on LINUX
stage entry.
F.6 DPMAIF TX peek/unlink lets completion free an skb still on
tx_skb_head. Dequeue before DRB insert and re-queue on
failure.
Signed-off-by: Wanquan Zhong <zwq2226404116@163.com>
---
drivers/net/wwan/t7xx/t7xx_hif_cldma.c | 15 +++++---------
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c | 5 +++--
drivers/net/wwan/t7xx/t7xx_modem_ops.c | 23 +++++++++++++++++++---
drivers/net/wwan/t7xx/t7xx_port_proxy.c | 3 ++-
drivers/net/wwan/t7xx/t7xx_state_monitor.c | 1 +
5 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
index 622cb8ee0282..2074ad590f51 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_cldma.c
@@ -992,6 +992,11 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
spin_unlock_irqrestore(&md_ctrl->cldma_lock, flags);
do {
+ if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
+ ret = -ETIMEDOUT;
+ break;
+ }
+
spin_lock_irqsave(&queue->ring_lock, flags);
tx_req = queue->tx_next;
if (queue->budget > 0 && !tx_req->skb) {
@@ -1002,11 +1007,6 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
queue->tx_next = list_next_entry_circular(tx_req, gpd_ring, entry);
spin_unlock_irqrestore(&queue->ring_lock, flags);
- if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
- ret = -ETIMEDOUT;
- break;
- }
-
/* Protect the access to the modem for queues operations (resume/start)
* which access shared locations by all the queues.
* cldma_lock is independent of ring_lock which is per queue.
@@ -1019,11 +1019,6 @@ int t7xx_cldma_send_skb(struct cldma_ctrl *md_ctrl, int qno, struct sk_buff *skb
}
spin_unlock_irqrestore(&queue->ring_lock, flags);
- if (!t7xx_pci_sleep_disable_complete(md_ctrl->t7xx_dev)) {
- ret = -ETIMEDOUT;
- break;
- }
-
if (!t7xx_cldma_hw_queue_status(&md_ctrl->hw_info, qno, MTK_TX)) {
spin_lock_irqsave(&md_ctrl->cldma_lock, flags);
t7xx_cldma_hw_resume_queue(&md_ctrl->hw_info, qno, MTK_TX);
diff --git a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c
index 236d632cf591..e1cb6e59c4cf 100644
--- a/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c
+++ b/drivers/net/wwan/t7xx/t7xx_hif_dpmaif_tx.c
@@ -378,12 +378,13 @@ static int t7xx_txq_burst_send_skb(struct dpmaif_tx_queue *txq)
for (i = 0; i < DPMAIF_SKB_TX_BURST_CNT; i++) {
struct sk_buff *skb;
- skb = skb_peek(&txq->tx_skb_head);
+ skb = skb_dequeue(&txq->tx_skb_head);
if (!skb)
break;
send_drb_cnt = t7xx_skb_drb_cnt(skb);
if (drb_remain_cnt < send_drb_cnt) {
+ skb_queue_head(&txq->tx_skb_head, skb);
drb_remain_cnt = t7xx_txq_drb_wr_available(txq);
continue;
}
@@ -394,11 +395,11 @@ static int t7xx_txq_burst_send_skb(struct dpmaif_tx_queue *txq)
if (ret < 0) {
dev_err(txq->dpmaif_ctrl->dev,
"Failed to add skb to device's ring: %d\n", ret);
+ skb_queue_head(&txq->tx_skb_head, skb);
break;
}
drb_cnt += send_drb_cnt;
- skb_unlink(skb, &txq->tx_skb_head);
}
if (drb_cnt > 0)
diff --git a/drivers/net/wwan/t7xx/t7xx_modem_ops.c b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
index e5065bf55bd6..31936a0406f4 100644
--- a/drivers/net/wwan/t7xx/t7xx_modem_ops.c
+++ b/drivers/net/wwan/t7xx/t7xx_modem_ops.c
@@ -115,6 +115,7 @@ int t7xx_pci_mhccif_isr(struct t7xx_pci_dev *t7xx_dev)
if ((md->exp_id & D2H_INT_ASYNC_MD_HK) && !(mask & D2H_INT_ASYNC_MD_HK)) {
md->exp_id &= ~D2H_INT_ASYNC_MD_HK;
queue_work(md->handshake_wq, &md->handshake_work);
+ t7xx_mhccif_mask_set(t7xx_dev, D2H_INT_ASYNC_MD_HK);
}
}
spin_unlock_bh(&md->exp_lock);
@@ -503,8 +504,10 @@ static int t7xx_core_reset(struct t7xx_modem *md)
{
struct device *dev = &md->t7xx_dev->pdev->dev;
struct t7xx_fsm_ctl *ctl = md->fsm_ctl;
+ int ret;
md->core_md.ready = false;
+ md->core_ap.ready = false;
if (!ctl) {
dev_err(dev, "FSM is not initialized\n");
@@ -512,13 +515,19 @@ static int t7xx_core_reset(struct t7xx_modem *md)
}
if (md->core_md.handshake_ongoing) {
- int ret = t7xx_fsm_append_event(ctl, FSM_EVENT_MD_HS2_EXIT, NULL, 0);
+ ret = t7xx_fsm_append_event(ctl, FSM_EVENT_MD_HS2_EXIT, NULL, 0);
+ if (ret)
+ dev_err(dev, "Failed to append MD HS2 exit: %d\n", ret);
+ }
+ if (md->core_ap.handshake_ongoing) {
+ ret = t7xx_fsm_append_event(ctl, FSM_EVENT_AP_HS2_EXIT, NULL, 0);
if (ret)
- return ret;
+ dev_err(dev, "Failed to append AP HS2 exit: %d\n", ret);
}
md->core_md.handshake_ongoing = false;
+ md->core_ap.handshake_ongoing = false;
return 0;
}
@@ -732,15 +741,23 @@ static struct t7xx_modem *t7xx_md_alloc(struct t7xx_pci_dev *t7xx_dev)
int t7xx_md_reset(struct t7xx_pci_dev *t7xx_dev)
{
struct t7xx_modem *md = t7xx_dev->md;
+ int ret;
md->md_init_finish = false;
md->exp_id = 0;
t7xx_fsm_reset(md);
+
+ ret = t7xx_core_reset(md);
+
+ cancel_work_sync(&md->handshake_work);
+ cancel_work_sync(&md->ap_handshake_work);
+
t7xx_cldma_reset(md->md_ctrl[CLDMA_ID_MD]);
t7xx_cldma_reset(md->md_ctrl[CLDMA_ID_AP]);
t7xx_port_proxy_reset(md->port_prox);
md->md_init_finish = true;
- return t7xx_core_reset(md);
+
+ return ret;
}
/**
diff --git a/drivers/net/wwan/t7xx/t7xx_port_proxy.c b/drivers/net/wwan/t7xx/t7xx_port_proxy.c
index 4fc131f9632f..fa056f315562 100644
--- a/drivers/net/wwan/t7xx/t7xx_port_proxy.c
+++ b/drivers/net/wwan/t7xx/t7xx_port_proxy.c
@@ -398,7 +398,7 @@ int t7xx_port_proxy_recv_skb_from_dedicated_queue(struct cldma_queue *queue, str
port = &port_prox->ports[0];
if (WARN_ON_ONCE(port->port_conf->rxq_index != queue->index)) {
dev_kfree_skb_any(skb);
- return -EINVAL;
+ return 0;
}
port_conf = port->port_conf;
@@ -406,6 +406,7 @@ int t7xx_port_proxy_recv_skb_from_dedicated_queue(struct cldma_queue *queue, str
if (ret < 0 && ret != -ENOBUFS) {
dev_err(port->dev, "drop on RX ch %d, %d\n", port_conf->rx_ch, ret);
dev_kfree_skb_any(skb);
+ return 0;
}
return ret;
diff --git a/drivers/net/wwan/t7xx/t7xx_state_monitor.c b/drivers/net/wwan/t7xx/t7xx_state_monitor.c
index 091d7cabd630..c284f971e347 100644
--- a/drivers/net/wwan/t7xx/t7xx_state_monitor.c
+++ b/drivers/net/wwan/t7xx/t7xx_state_monitor.c
@@ -417,6 +417,7 @@ static void fsm_routine_start(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_command
break;
t7xx_cldma_hif_hw_init(md->md_ctrl[CLDMA_ID_AP]);
t7xx_cldma_hif_hw_init(md->md_ctrl[CLDMA_ID_MD]);
+ t7xx_cldma_stop(md->md_ctrl[CLDMA_ID_AP]);
t7xx_port_proxy_set_cfg(md, PORT_CFG_ID_NORMAL);
ret = fsm_routine_starting(ctl);
break;
--
2.53.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
` (4 preceding siblings ...)
2026-12-03 6:26 ` [PATCH net 5/5] t7xx: fix handshake races and skb double-free on TX/RX Wanquan Zhong
@ 2026-12-03 6:33 ` netdev-bot+sinfo
5 siblings, 0 replies; 8+ messages in thread
From: netdev-bot+sinfo @ 2026-12-03 6:33 UTC (permalink / raw)
To: Wanquan Zhong
Cc: netdev, chandrashekar.devegowda, haijun.liu, ricardo.martinez,
loic.poulain, ryazanov.s.a, johannes, andrew+netdev, davem,
edumazet, kuba, pabeni, linux-kernel
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] 8+ messages in thread
* Re: [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill
2026-12-03 6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
@ 2026-12-03 13:47 ` kernel test robot
0 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2026-12-03 13:47 UTC (permalink / raw)
To: Wanquan Zhong, netdev
Cc: oe-kbuild-all, chandrashekar.devegowda, haijun.liu,
ricardo.martinez, loic.poulain, ryazanov.s.a, johannes,
andrew+netdev, davem, edumazet, kuba, pabeni, linux-kernel,
zwq2226404116
Hi Wanquan,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/Wanquan-Zhong/t7xx-validate-PIT-BAT-ids-and-restore-failed-RX-BAT-refill/20261203-142631
base: net/main
patch link: https://lore.kernel.org/r/0cfb6f26ef0a027fbfc9e74fb19e7a4e66a5d21b.1796279181.git.zwq2226404116%40163.com
patch subject: [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261203/20261203213305.WYnNc84t-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261203/20261203213305.WYnNc84t-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261203213305.WYnNc84t-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> Warning: drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c:241 function parameter 'allocated_cnt' not described in 't7xx_dpmaif_rx_buf_alloc'
>> Warning: drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c:407 function parameter 'allocated_cnt' not described in 't7xx_dpmaif_rx_frag_alloc'
>> Warning: drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c:241 function parameter 'allocated_cnt' not described in 't7xx_dpmaif_rx_buf_alloc'
>> Warning: drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c:407 function parameter 'allocated_cnt' not described in 't7xx_dpmaif_rx_frag_alloc'
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-12-03 13:48 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 6:26 [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 1/5] t7xx: validate PIT/BAT ids and restore failed RX BAT refill Wanquan Zhong
2026-12-03 13:47 ` kernel test robot
2026-12-03 6:26 ` [PATCH net 2/5] t7xx: validate control-message and PORT_ENUM payload lengths Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 3/5] t7xx: reject malformed runtime-feature handshake data Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 4/5] t7xx: stop in-flight CLDMA IRQ and work before ring teardown Wanquan Zhong
2026-12-03 6:26 ` [PATCH net 5/5] t7xx: fix handshake races and skb double-free on TX/RX Wanquan Zhong
2026-12-03 6:33 ` [PATCH net 0/5] t7xx: validate DPMAIF RX, handshake bounds, and CLDMA teardown 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