Skip to content

Commit 55c1528

Browse files
Edward Creekuba-moo
authored andcommitted
sfc: fix field-spanning memcpy in selftest
Add a struct_group for the whole packet body so we can copy it in one go without triggering FORTIFY_SOURCE complaints. 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") Reviewed-by: Andy Moreton <[email protected]> Tested-by: Andy Moreton <[email protected]> Signed-off-by: Edward Cree <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d4480c9 commit 55c1528

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@
4040
*/
4141
struct ef4_loopback_payload {
4242
char pad[2]; /* Ensures ip is 4-byte aligned */
43-
struct ethhdr header;
44-
struct iphdr ip;
45-
struct udphdr udp;
46-
__be16 iteration;
47-
char msg[64];
43+
struct_group_attr(packet, __packed,
44+
struct ethhdr header;
45+
struct iphdr ip;
46+
struct udphdr udp;
47+
__be16 iteration;
48+
char msg[64];
49+
);
4850
} __packed __aligned(4);
49-
#define EF4_LOOPBACK_PAYLOAD_LEN (sizeof(struct ef4_loopback_payload) - \
50-
offsetof(struct ef4_loopback_payload, \
51-
header))
51+
#define EF4_LOOPBACK_PAYLOAD_LEN \
52+
sizeof_field(struct ef4_loopback_payload, packet)
5253

5354
/* Loopback test source MAC address */
5455
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
@@ -299,7 +300,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
299300

300301
payload = &state->payload;
301302

302-
memcpy(&received.header, buf_ptr,
303+
memcpy(&received.packet, buf_ptr,
303304
min_t(int, pkt_len, EF4_LOOPBACK_PAYLOAD_LEN));
304305
received.ip.saddr = payload->ip.saddr;
305306
if (state->offload_csum)
@@ -370,7 +371,7 @@ void ef4_loopback_rx_packet(struct ef4_nic *efx,
370371
buf_ptr, pkt_len, 0);
371372
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
372373
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
373-
&state->payload.header, EF4_LOOPBACK_PAYLOAD_LEN,
374+
&state->payload.packet, EF4_LOOPBACK_PAYLOAD_LEN,
374375
0);
375376
}
376377
#endif
@@ -440,6 +441,8 @@ static int ef4_begin_loopback(struct ef4_tx_queue *tx_queue)
440441
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
441442
/* Strip off the leading padding */
442443
skb_pull(skb, offsetof(struct ef4_loopback_payload, header));
444+
/* Strip off the trailing padding */
445+
skb_trim(skb, EF4_LOOPBACK_PAYLOAD_LEN);
443446

444447
/* Ensure everything we've written is visible to the
445448
* interrupt handler. */

drivers/net/ethernet/sfc/selftest.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@
4343
*/
4444
struct efx_loopback_payload {
4545
char pad[2]; /* Ensures ip is 4-byte aligned */
46-
struct ethhdr header;
47-
struct iphdr ip;
48-
struct udphdr udp;
49-
__be16 iteration;
50-
char msg[64];
46+
struct_group_attr(packet, __packed,
47+
struct ethhdr header;
48+
struct iphdr ip;
49+
struct udphdr udp;
50+
__be16 iteration;
51+
char msg[64];
52+
);
5153
} __packed __aligned(4);
52-
#define EFX_LOOPBACK_PAYLOAD_LEN (sizeof(struct efx_loopback_payload) - \
53-
offsetof(struct efx_loopback_payload, \
54-
header))
54+
#define EFX_LOOPBACK_PAYLOAD_LEN \
55+
sizeof_field(struct efx_loopback_payload, packet)
5556

5657
/* Loopback test source MAC address */
5758
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
@@ -297,7 +298,7 @@ void efx_loopback_rx_packet(struct efx_nic *efx,
297298

298299
payload = &state->payload;
299300

300-
memcpy(&received.header, buf_ptr,
301+
memcpy(&received.packet, buf_ptr,
301302
min_t(int, pkt_len, EFX_LOOPBACK_PAYLOAD_LEN));
302303
received.ip.saddr = payload->ip.saddr;
303304
if (state->offload_csum)
@@ -368,7 +369,7 @@ void efx_loopback_rx_packet(struct efx_nic *efx,
368369
buf_ptr, pkt_len, 0);
369370
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
370371
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
371-
&state->payload.header, EFX_LOOPBACK_PAYLOAD_LEN,
372+
&state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN,
372373
0);
373374
}
374375
#endif
@@ -438,6 +439,8 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
438439
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
439440
/* Strip off the leading padding */
440441
skb_pull(skb, offsetof(struct efx_loopback_payload, header));
442+
/* Strip off the trailing padding */
443+
skb_trim(skb, EFX_LOOPBACK_PAYLOAD_LEN);
441444

442445
/* Ensure everything we've written is visible to the
443446
* interrupt handler. */

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@
4343
*/
4444
struct efx_loopback_payload {
4545
char pad[2]; /* Ensures ip is 4-byte aligned */
46-
struct ethhdr header;
47-
struct iphdr ip;
48-
struct udphdr udp;
49-
__be16 iteration;
50-
char msg[64];
46+
struct_group_attr(packet, __packed,
47+
struct ethhdr header;
48+
struct iphdr ip;
49+
struct udphdr udp;
50+
__be16 iteration;
51+
char msg[64];
52+
);
5153
} __packed __aligned(4);
52-
#define EFX_LOOPBACK_PAYLOAD_LEN (sizeof(struct efx_loopback_payload) - \
53-
offsetof(struct efx_loopback_payload, \
54-
header))
54+
#define EFX_LOOPBACK_PAYLOAD_LEN \
55+
sizeof_field(struct efx_loopback_payload, packet)
5556

5657
/* Loopback test source MAC address */
5758
static const u8 payload_source[ETH_ALEN] __aligned(2) = {
@@ -297,7 +298,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
297298

298299
payload = &state->payload;
299300

300-
memcpy(&received.header, buf_ptr,
301+
memcpy(&received.packet, buf_ptr,
301302
min_t(int, pkt_len, EFX_LOOPBACK_PAYLOAD_LEN));
302303
received.ip.saddr = payload->ip.saddr;
303304
if (state->offload_csum)
@@ -368,7 +369,7 @@ void efx_siena_loopback_rx_packet(struct efx_nic *efx,
368369
buf_ptr, pkt_len, 0);
369370
netif_err(efx, drv, efx->net_dev, "expected packet:\n");
370371
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_OFFSET, 0x10, 1,
371-
&state->payload.header, EFX_LOOPBACK_PAYLOAD_LEN,
372+
&state->payload.packet, EFX_LOOPBACK_PAYLOAD_LEN,
372373
0);
373374
}
374375
#endif
@@ -438,6 +439,8 @@ static int efx_begin_loopback(struct efx_tx_queue *tx_queue)
438439
payload->ip.saddr = htonl(INADDR_LOOPBACK | (i << 2));
439440
/* Strip off the leading padding */
440441
skb_pull(skb, offsetof(struct efx_loopback_payload, header));
442+
/* Strip off the trailing padding */
443+
skb_trim(skb, EFX_LOOPBACK_PAYLOAD_LEN);
441444

442445
/* Ensure everything we've written is visible to the
443446
* interrupt handler. */

0 commit comments

Comments
 (0)