Skip to content

Commit df18f2d

Browse files
haiyangzkuba-moo
authored andcommitted
net: mana: Check if netdev/napi_alloc_frag returns single page
netdev/napi_alloc_frag() may fall back to single page which is smaller than the requested size. Add error checking to avoid memory overwritten. Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 5c74064 commit df18f2d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,14 @@ static int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu)
553553
va = netdev_alloc_frag(mpc->rxbpre_alloc_size);
554554
if (!va)
555555
goto error;
556+
557+
page = virt_to_head_page(va);
558+
/* Check if the frag falls back to single page */
559+
if (compound_order(page) <
560+
get_order(mpc->rxbpre_alloc_size)) {
561+
put_page(page);
562+
goto error;
563+
}
556564
} else {
557565
page = dev_alloc_page();
558566
if (!page)
@@ -1504,6 +1512,13 @@ static void *mana_get_rxfrag(struct mana_rxq *rxq, struct device *dev,
15041512

15051513
if (!va)
15061514
return NULL;
1515+
1516+
page = virt_to_head_page(va);
1517+
/* Check if the frag falls back to single page */
1518+
if (compound_order(page) < get_order(rxq->alloc_size)) {
1519+
put_page(page);
1520+
return NULL;
1521+
}
15071522
} else {
15081523
page = dev_alloc_page();
15091524
if (!page)

0 commit comments

Comments
 (0)