Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 0 · High: 0 (2) · Medium: 1 · 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 fix is incomplete on the AEN branch of ncsi_rcv_rsp(). - [Low] The commit message says 'ALIGN(payload, 4) on an unsigned short wraps to 0 for payload values 65533..65535' and gives that as the… Pre-existing issues: - [High] This problem wasn't introduced by this patch, but the variable- length response handlers the commit message names (GP, OEM) still read… - [High] This problem wasn't introduced by this patch, but ncsi_rsp_handler_gp(), one of the variable-length handlers named in… -- net/ncsi: validate response packet lengths against skb This patch unshares the NCSI response skb and pulls the common header in ncsi_rcv_rsp(). It also makes ncsi_validate_rsp_pkt() require a minimum payload and pull the full header, the aligned payload and the checksum before reading them. Log messages after validation now use nrh->type instead of hdr->type.
> Additionally, ALIGN(payload, 4) on an unsigned short wraps to 0 > for payload values 65533..65535, and dereferencing hdr->type after
[Severity: Low] Is this part of the commit message accurate? ALIGN(x, a) expands to __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1), which is ((x) + (mask)) & ~(mask). When x is an unsigned short, both operands are promoted to int. For 65533..65535, x + 3 gives 65536..65538, and & ~3 gives 65536, not 0. The old code used the result directly in pointer arithmetic. The new code stores it in a size_t. So there was no wrap with or without the size_t cast. The 65533..65535 KUnit cases appear to be rejected only because the skb is shorter than pkt_len. Could the commit message drop or reword the wraparound claim? Since the patch carries a Fixes: tag, it would help backporters to know exactly what is being fixed.
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c > index 84cc8ac0ca2f8..e917cefd408b1 100644 > --- a/net/ncsi/ncsi-rsp.c > +++ b/net/ncsi/ncsi-rsp.c > @@ -35,9 +35,25 @@ static u8 decode_bcd_u8(u8 x) > static int ncsi_validate_rsp_pkt(struct ncsi_request *nr, > unsigned short payload) > { > + size_t payload_len, pkt_len; > struct ncsi_rsp_pkt_hdr *h; > - u32 checksum; > __be32 *pchecksum; > + u32 checksum; > + > + if (payload < sizeof(*h) - sizeof(h->common)) { > + netdev_dbg(nr->ndp->ndev.dev, > + "NCSI: response payload too short (%u)\n", payload); > + return -EINVAL; > + } > + > + payload_len = ALIGN((size_t)payload, 4); > + pkt_len = sizeof(h->common) + payload_len + sizeof(*pchecksum); > + if (!pskb_may_pull(nr->rsp, pkt_len)) { > + netdev_dbg(nr->ndp->ndev.dev, > + "NCSI: response packet truncated (len %u, need %zu)\n", > + nr->rsp->len, pkt_len); > + return -EINVAL; > + }
[Severity: High] This is a pre-existing issue and was not introduced by this patch. The GP and OEM variable-length handlers named in the commit message still read past the region this validation guarantees. For payload == -1 types, the payload comes from hdr->length. A response with hdr->length = 4 passes this check, and only 24 bytes are pulled. After that, ncsi_rsp_handler_gp() reads link_mode, bc_mode, valid_modes and aen_mode up to offset 48. It then walks the filter tables: ncsi_rsp_handler_gp() { ... pdata = (unsigned char *)rsp + 48; enable = rsp->mac_enable; ... for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) { ... for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) { ... } None of these reads are compared with hdr->length or skb->len. With mac_cnt = vlan_cnt = 255, the handler reads about 2088 bytes past the network header. That is beyond the 1536-byte RX buffer used by ftgmac100. ncsi_rsp_handler_oem_gma() has the same pattern: memcpy(saddr->__data, &rsp->data[mac_addr_off], ETH_ALEN); For Broadcom, rsp->data starts at offset 24 and mac_addr_off is 28, so this reads bytes 52..57 without checking hdr->length. The bytes it reads end up in ndp->pending_mac and are applied as the interface MAC. Because ncsi_rcv_rsp() does not check the response type against nr->cmd, any outstanding request id is enough to reach these handlers. The second patch in this series ("net/ncsi: validate GMCMA address_count against packet length") adds a check based on hdr->length to ncsi_rsp_handler_gmcma() only. Should GP and OEM get the same treatment? [Severity: High] This is also a pre-existing issue, not something this patch introduced. ncsi_rsp_handler_gp() can write past heap allocations, because its loops are bounded only by the u8 counts in the packet: for (i = 0; i < rsp->mac_cnt; i++, pdata += 6) { assign_bit(i, bitmap, enable & (0x1 << i)); memcpy(&ncmf->addrs[i * ETH_ALEN], pdata, ETH_ALEN); } ... for (i = 0; i < rsp->vlan_cnt; i++, pdata += 2) { assign_bit(i, bitmap, enable & (0x1 << i)); ncvf->vids[i] = ntohs(*(__be16 *)pdata); } ncmf->addrs and ncvf->vids were allocated in ncsi_rsp_handler_gc() using counts from an earlier, independent GC response: size = (rsp->uc_cnt + rsp->mc_cnt + rsp->mixed_cnt) * ETH_ALEN; nc->mac_filter.addrs = kzalloc(size, GFP_ATOMIC); GP never compares mac_cnt with n_uc + n_mc + n_mixed. It never compares vlan_cnt with n_vids, or either count with the width of the u64 bitmap. In struct ncsi_channel_mac_filter, the u64 bitmap is followed directly by the addrs pointer: struct ncsi_channel_mac_filter { u8 n_uc; u8 n_mc; u8 n_mixed; u64 bitmap; unsigned char *addrs; }; Can assign_bit() with i >= 64 overwrite ncmf->addrs, so the next memcpy() writes through a corrupted pointer? The vlan filter struct has the same layout. If GC reported zero filters, addrs is ZERO_SIZE_PTR. If no GC was handled for the channel, addrs and vids are NULL. GP is unchanged at the end of this series. [ ... ]
> @@ -1184,6 +1200,15 @@ int ncsi_rcv_rsp(struct sk_buff *skb, struct net_device *dev, > goto err_free_skb; > } > > + skb = skb_share_check(skb, GFP_ATOMIC); > + if (!skb) > + return -ENOMEM; > + > + if (!pskb_may_pull(skb, sizeof(*hdr))) { > + ret = -EINVAL; > + goto err_free_skb; > + } > + > /* Check if it is AEN packet */ > hdr = (struct ncsi_pkt_hdr *)skb_network_header(skb); > if (hdr->type == NCSI_PKT_AEN)
[Severity: Medium] Is the AEN branch still exposed to the same short or non-linear skb problem? This pull guarantees only sizeof(struct ncsi_pkt_hdr), which is 16 bytes. The skb is then passed to ncsi_aen_handler(), which reads further: ncsi_aen_handler() { ... h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb); for (i = 0; i < ARRAY_SIZE(ncsi_aen_handlers); i++) { if (ncsi_aen_handlers[i].type == h->type) { ... } struct ncsi_aen_pkt_hdr is 20 bytes, and h->type sits at offset 19. ncsi_validate_aen_pkt() only compares h->common.length with the fixed payload. After that comparison it reads the checksum and computes the checksum over the packet: pchecksum = (__be32 *)((void *)(h + 1) + payload - 4); if (ntohl(*pchecksum) == 0) return 0; checksum = ncsi_calculate_checksum((unsigned char *)h, sizeof(*h) + payload - 4); None of this is checked against skb->len or skb_headlen(). The patch removes this same dereference and computation from ncsi_validate_rsp_pkt(). With ftgmac100's linear 1536-byte buffers, these reads return stale data from inside the allocation. A driver that produces short or non-linear heads, which is the case this patch says it handles, would read out of bounds. Would it make sense to add pskb_may_pull(skb, sizeof(struct ncsi_aen_pkt_hdr)) before the AEN type lookup, and to pull sizeof(*h) + payload in ncsi_validate_aen_pkt()?
-- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40google.com