Skip to content
/ linux Public

Commit a5bd5a2

Browse files
tobgaertnergregkh
authored andcommitted
net: usb: cdc_ncm: add ndpoffset to NDP32 nframes bounds check
[ Upstream commit 7791425 ] The same bounds-check bug fixed for NDP16 in the previous patch also exists in cdc_ncm_rx_verify_ndp32(). The DPE array size is validated against the total skb length without accounting for ndpoffset, allowing out-of-bounds reads when the NDP32 is placed near the end of the NTB. Add ndpoffset to the nframes bounds check and use struct_size_t() to express the NDP-plus-DPE-array size more clearly. Compile-tested only. Fixes: 0fa81b3 ("cdc_ncm: Implement the 32-bit version of NCM Transfer Block") Signed-off-by: Tobi Gaertner <tob.gaertner@me.com> Link: https://patch.msgid.link/20260314054640.2895026-3-tob.gaertner@me.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 403f94d commit a5bd5a2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/net/usb/cdc_ncm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,7 @@ int cdc_ncm_rx_verify_ndp32(struct sk_buff *skb_in, int ndpoffset)
16931693
struct usbnet *dev = netdev_priv(skb_in->dev);
16941694
struct usb_cdc_ncm_ndp32 *ndp32;
16951695
int ret = -EINVAL;
1696+
size_t ndp_len;
16961697

16971698
if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp32)) > skb_in->len) {
16981699
netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n",
@@ -1712,8 +1713,8 @@ int cdc_ncm_rx_verify_ndp32(struct sk_buff *skb_in, int ndpoffset)
17121713
sizeof(struct usb_cdc_ncm_dpe32));
17131714
ret--; /* we process NDP entries except for the last one */
17141715

1715-
if ((sizeof(struct usb_cdc_ncm_ndp32) +
1716-
ret * (sizeof(struct usb_cdc_ncm_dpe32))) > skb_in->len) {
1716+
ndp_len = struct_size_t(struct usb_cdc_ncm_ndp32, dpe32, ret);
1717+
if (ndpoffset + ndp_len > skb_in->len) {
17171718
netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret);
17181719
ret = -EINVAL;
17191720
}

0 commit comments

Comments
 (0)