Skip to content

Commit 6dc5774

Browse files
Edward Creekuba-moo
authored andcommitted
sfc: allocate a big enough SKB for loopback selftest packet
Cited commits passed a size to alloc_skb that was only big enough for the actual packet contents, but the following skb_put + memcpy writes the whole struct efx_loopback_payload including leading and trailing padding bytes (which are then stripped off with skb_pull/skb_trim). This could cause an skb_over_panic, although in practice we get saved by kmalloc_size_roundup. Pass the entire size we use, instead of the size of the final packet. Reported-by: Andy Moreton <andy.moreton@amd.com> Fixes: cf60ed4 ("sfc: use padding to fix alignment in loopback test") Fixes: 30c24dd ("sfc: siena: use padding to fix alignment in loopback test") Fixes: 1186c6b ("sfc: falcon: use padding to fix alignment in loopback test") Signed-off-by: Edward Cree <ecree.xilinx@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20230821180153.18652-1-edward.cree@amd.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 1a86605 commit 6dc5774

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/net/ethernet/sfc/falcon/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue)
428428
for (i = 0; i < state->packet_count; i++) {
429429
/* Allocate an skb, holding an extra reference for
430430
* transmit completion counting */
431-
skb = alloc_skb(EF4_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
431+
skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
432432
if (!skb)
433433
return -ENOMEM;
434434
state->skbs[i] = skb;

drivers/net/ethernet/sfc/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
426426
for (i = 0; i < state->packet_count; i++) {
427427
/* Allocate an skb, holding an extra reference for
428428
* transmit completion counting */
429-
skb = alloc_skb(EFX_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
429+
skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
430430
if (!skb)
431431
return -ENOMEM;
432432
state->skbs[i] = skb;

drivers/net/ethernet/sfc/siena/selftest.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
426426
for (i = 0; i < state->packet_count; i++) {
427427
/* Allocate an skb, holding an extra reference for
428428
* transmit completion counting */
429-
skb = alloc_skb(EFX_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
429+
skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
430430
if (!skb)
431431
return -ENOMEM;
432432
state->skbs[i] = skb;

0 commit comments

Comments
 (0)