From: netdev-bot+sashiko@kernel.org
To: fangxy@xiaopeng.com
Cc: chandrashekar.devegowda@intel.com, loic.poulain@oss.qualcomm.com,
ryazanov.s.a@gmail.com, ilpo.jarvinen@linux.intel.com,
netdev@vger.kernel.org, haijun.liu@mediatek.com,
johannes@sipsolutions.net, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, linqj@xiaopeng.com
Subject: Re: [PATCH net] net: wwan: t7xx: validate PIT data offset before skb_reserve
Date: Mon, 23 Nov 2026 06:39:27 +0000 [thread overview]
Message-ID: <179541596756.3135.6965744505387412637@kernel.org> (raw)
In-Reply-To: <20261119062044.72261-1-fangxy@xiaopeng.com>
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
prev parent reply other threads:[~2026-11-23 6:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 6:20 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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179541596756.3135.6965744505387412637@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=chandrashekar.devegowda@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=fangxy@xiaopeng.com \
--cc=haijun.liu@mediatek.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linqj@xiaopeng.com \
--cc=linux-kernel@vger.kernel.org \
--cc=loic.poulain@oss.qualcomm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ryazanov.s.a@gmail.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®