sfc: allocate a big enough SKB for loopback selftest packet
Subsystems (3)
PATCH 1/1 sfc: allocate a big enough SKB for loopback selftest packet
From: Edward Cree <[email protected]>
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.
--- drivers/net/ethernet/sfc/falcon/selftest.c | 2 +- drivers/net/ethernet/sfc/selftest.c | 2 +- drivers/net/ethernet/sfc/siena/selftest.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/sfc/falcon/selftest.c +1 -1
@@ -428,7 +428,7 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue)for (i =0 ; i < state->packet_count; i++) {/* Allocate an skb, holding an extra reference for * transmit completion counting */ - skb =alloc_skb (EF4_LOOPBACK_PAYLOAD_LEN ,GFP_KERNEL ); + skb =alloc_skb (sizeof (state->payload),GFP_KERNEL );if (!skb)return -ENOMEM ; state->skbs[i] = skb;
drivers/net/ethernet/sfc/selftest.c +1 -1
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)for (i =0 ; i < state->packet_count; i++) {/* Allocate an skb, holding an extra reference for * transmit completion counting */ - skb =alloc_skb (EFX_LOOPBACK_PAYLOAD_LEN ,GFP_KERNEL ); + skb =alloc_skb (sizeof (state->payload),GFP_KERNEL );if (!skb)return -ENOMEM ; state->skbs[i] = skb;
drivers/net/ethernet/sfc/siena/selftest.c +1 -1
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)for (i =0 ; i < state->packet_count; i++) {/* Allocate an skb, holding an extra reference for * transmit completion counting */ - skb =alloc_skb (EFX_LOOPBACK_PAYLOAD_LEN ,GFP_KERNEL ); + skb =alloc_skb (sizeof (state->payload),GFP_KERNEL );if (!skb)return -ENOMEM ; state->skbs[i] = skb;
Quoted 10 lines · On Mon, Aug 21, 2023 at 07:01:53PM +0100, [email protected] wrote:
From: Edward Cree <[email protected]>
Cited commits passed a size to
alloc_skbthat was only big enough for
the actual packet contents, but the followingskb_put+ memcpy writes the whole structefx_loopback_payloadincluding leading and trailing padding bytes (which are then stripped off with skb_pull/skb_trim).
This could cause anskb_over_panic, although in practice we get saved
bykmalloc_size_roundup.
Pass the entire size we use, instead of the size of the final packet.
Quoted 5 lines
Reported-by Andy Moreton <[email protected]>Fixes cf60ed469629 ("sfc: use padding to fix alignment in loopback test")Fixes 30c24dd87f3f ("sfc: siena: use padding to fix alignment in loopback test")Fixes 1186c6b31ee1 ("sfc: falcon: use padding to fix alignment in loopback test")Signed-off-by Edward Cree <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Mon, 21 Aug 2023 19:01:53 +0100 you wrote:
From: Edward Cree <[email protected]>
Cited commits passed a size to
alloc_skbthat was only big enough for
the actual packet contents, but the followingskb_put+ memcpy writes the whole structefx_loopback_payloadincluding leading and trailing padding bytes (which are then stripped off with skb_pull/skb_trim).
This could cause anskb_over_panic, although in practice we get saved
bykmalloc_size_roundup.
Pass the entire size we use, instead of the size of the final packet.[...]
Here is the summary with links:
- [net] sfc: allocate a big enough SKB for loopback selftest packet
https://git.kernel.org/netdev/net/c/6dc5774deefe
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html