Commit 6dc5774d authored by Edward Cree's avatar Edward Cree Committed by Jakub Kicinski
Browse files

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: default avatarAndy Moreton <andy.moreton@amd.com>
Fixes: cf60ed46 ("sfc: use padding to fix alignment in loopback test")
Fixes: 30c24dd8 ("sfc: siena: use padding to fix alignment in loopback test")
Fixes: 1186c6b3 ("sfc: falcon: use padding to fix alignment in loopback test")
Signed-off-by: default avatarEdward Cree <ecree.xilinx@gmail.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20230821180153.18652-1-edward.cree@amd.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1a866054
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -428,7 +428,7 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue)
	for (i = 0; i < state->packet_count; i++) {
	for (i = 0; i < state->packet_count; i++) {
		/* Allocate an skb, holding an extra reference for
		/* Allocate an skb, holding an extra reference for
		 * transmit completion counting */
		 * transmit completion counting */
		skb = alloc_skb(EF4_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
		skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
		if (!skb)
		if (!skb)
			return -ENOMEM;
			return -ENOMEM;
		state->skbs[i] = skb;
		state->skbs[i] = skb;
+1 −1
Original line number Original line Diff line number Diff line
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
	for (i = 0; i < state->packet_count; i++) {
	for (i = 0; i < state->packet_count; i++) {
		/* Allocate an skb, holding an extra reference for
		/* Allocate an skb, holding an extra reference for
		 * transmit completion counting */
		 * transmit completion counting */
		skb = alloc_skb(EFX_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
		skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
		if (!skb)
		if (!skb)
			return -ENOMEM;
			return -ENOMEM;
		state->skbs[i] = skb;
		state->skbs[i] = skb;
+1 −1
Original line number Original line Diff line number Diff line
@@ -426,7 +426,7 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
	for (i = 0; i < state->packet_count; i++) {
	for (i = 0; i < state->packet_count; i++) {
		/* Allocate an skb, holding an extra reference for
		/* Allocate an skb, holding an extra reference for
		 * transmit completion counting */
		 * transmit completion counting */
		skb = alloc_skb(EFX_LOOPBACK_PAYLOAD_LEN, GFP_KERNEL);
		skb = alloc_skb(sizeof(state->payload), GFP_KERNEL);
		if (!skb)
		if (!skb)
			return -ENOMEM;
			return -ENOMEM;
		state->skbs[i] = skb;
		state->skbs[i] = skb;