Re: [PATCH net-next v3 4/4] net: dsa: qca8k: bound the data of a management ack frame
From: netdev-bot+sashiko
Date: Sun Nov 22 2026 - 06:04:15 EST
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 2
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] Use-after-free introduced by the new pskb_may_pull() in
qca8k_rw_reg_ack_handler() (drivers/net/dsa/qca/qca8k-8xxx.c).
- [Low] The commit message says that with the old `u32 data[4]` a frame
"announcing more than three registers writes past the buffer".
- [Low] The new comment in qca8k_rw_reg_ack_handler(), "The tagger made
only the tag linear", and the matching commit-message line…
--
net: dsa: qca8k: bound the data of a management ack frame
This patch resizes mgmt_eth_data->data to the largest payload a
management frame can carry. Before qca8k_rw_reg_ack_handler() copies the
announced DATA2 payload, it now pulls that payload into the linear area
with pskb_may_pull(). A frame that is too short for its announced length
is left unacknowledged.
> qca8k_rw_reg_ack_handler() answers a management read by copying the
> data that follows the Ethernet header into mgmt_eth_data->data. It
> trusts the frame for both the length and the layout: the length field
> of the frame allows up to 32 bytes while the buffer holds 16, so a
> frame announcing more than three registers writes past the buffer into
> the fields that follow it in qca8k_priv; and qca_tag_rcv() made only
[Severity: Low]
Is the threshold here off by one? With the old u32 data[4], data[0] is
filled from mdio_data, and the loop then writes data_len / 4 more words:
for (i = sizeof(u32); i <= data_len; i += sizeof(u32)) {
For len = 16 (four registers), data_len is 12, so three more words are
written and data[0..3] is filled exactly. len = 18 also gives three
words. Only at len = 20 (five registers) does data_len = 16 reach
data[4].
So does the old overflow start at more than four registers, not more
than three?
> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
> index 76c0f7c97b99d..cd3569902fcdb 100644
> --- a/drivers/net/dsa/qca/qca8k-8xxx.c
> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
[ ... ]
> @@ -190,6 +191,17 @@ static void qca8k_rw_reg_ack_handler(struct dsa_switch *ds, struct sk_buff *skb)
> /* We can ignore odd value, we always round up them in the alloc function. */
> len *= sizeof(u16);
>
> + if (cmd == MDIO_READ && len > QCA_HDR_MGMT_DATA1_LEN)
> + data_len = min_t(int, QCA_HDR_MGMT_DATA2_LEN,
> + len - QCA_HDR_MGMT_DATA1_LEN);
> +
> + /* The tagger made only the tag linear. Leave a frame that is too
[Severity: Low]
Is this comment accurate? qca_tag_rcv() in net/dsa/tag_qca.c does:
if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN))) {
...
phdr = dsa_etype_header_pos_rx(skb);
That pull makes QCA_HDR_LEN bytes linear starting at skb->data. For a
management ack those are the first two bytes of the DATA2 payload. The
tag itself is read at skb->data - 2, inside the MAC header, which was
already linear.
The commit message uses the same wording: "qca_tag_rcv() made only the
2 byte tag linear".
DATA2 still needs a pull, so that conclusion holds. Could the comment
and changelog say which bytes the tagger actually guarantees?
> + * short for the data it announces unacknowledged: the read fails
> + * and the caller falls back to MDIO.
> + */
> + if (data_len && !pskb_may_pull(skb, data_len))
> + goto complete;
> +
> /* Make sure the seq match the requested packet */
> if (get_unaligned_le32(&mgmt_ethhdr->seq) == mgmt_eth_data->seq)
> mgmt_eth_data->ack = true;
[Severity: High]
Can this new pskb_may_pull() leave mgmt_ethhdr pointing into a freed
skb head? The function caches the pointer before the pull:
mgmt_ethhdr = (struct qca_mgmt_ethhdr *)skb_mac_header(skb);
data_len can be up to 28 bytes. If it is larger than skb_headlen(skb) and
the head lacks tailroom, the call chain is:
pskb_may_pull()
__pskb_pull_tail()
pskb_expand_head()
pskb_expand_head() allocates a new head and frees the old one.
dsa_switch_rcv() has already run skb_unclone_full(), so no clone keeps
the old head alive.
mgmt_ethhdr is never reloaded after the pull. The read of
mgmt_ethhdr->seq here, and the read of mgmt_ethhdr->mdio_data below,
would then come from the freed buffer.
A garbage seq could set mgmt_eth_data->ack = true. The garbage
mdio_data would land in mgmt_eth_data->data[0], which qca8k_read_eth()
returns as the register value.
The kernel-doc for __pskb_pull_tail() says "All the pointers pointing
into skb header may change and must be reloaded after call to this
function". The sibling handler qca8k_mib_autocast_handler() in this
file reloads its pointer after the pull:
if (!pskb_may_pull(skb, len))
goto unlock;
mib_ethhdr = (struct mib_ethhdr *)skb_mac_header(skb);
Should mgmt_ethhdr be re-read after a successful pull here? The other
option is to read seq and mdio_data into locals before the pull, as is
already done for command.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118104104.26684-1-kuncy7%40gmail.com