Skip to content

Commit 58ca14e

Browse files
magnus-karlssonborkmann
authored andcommitted
xsk: Fix corrupted packets for XDP_SHARED_UMEM
Fix an issue in XDP_SHARED_UMEM mode together with aligned mode where packets are corrupted for the second and any further sockets bound to the same umem. In other words, this does not affect the first socket bound to the umem. The culprit for this bug is that the initialization of the DMA addresses for the pre-populated xsk buffer pool entries was not performed for any socket but the first one bound to the umem. Only the linear array of DMA addresses was populated. Fix this by populating the DMA addresses in the xsk buffer pool for every socket bound to the same umem. Fixes: 94033cd ("xsk: Optimize for aligned case") Reported-by: Alasdair McWilliam <[email protected]> Reported-by: Intrusion Shield Team <[email protected]> Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Alasdair McWilliam <[email protected]> Acked-by: Maciej Fijalkowski <[email protected]> Link: https://lore.kernel.org/xdp-newbies/[email protected]/ Link: https://lore.kernel.org/bpf/[email protected]
1 parent 27e2383 commit 58ca14e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

net/xdp/xsk_buff_pool.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,16 @@ static void xp_check_dma_contiguity(struct xsk_dma_map *dma_map)
379379

380380
static int xp_init_dma_info(struct xsk_buff_pool *pool, struct xsk_dma_map *dma_map)
381381
{
382+
if (!pool->unaligned) {
383+
u32 i;
384+
385+
for (i = 0; i < pool->heads_cnt; i++) {
386+
struct xdp_buff_xsk *xskb = &pool->heads[i];
387+
388+
xp_init_xskb_dma(xskb, pool, dma_map->dma_pages, xskb->orig_addr);
389+
}
390+
}
391+
382392
pool->dma_pages = kvcalloc(dma_map->dma_pages_cnt, sizeof(*pool->dma_pages), GFP_KERNEL);
383393
if (!pool->dma_pages)
384394
return -ENOMEM;
@@ -428,12 +438,6 @@ int xp_dma_map(struct xsk_buff_pool *pool, struct device *dev,
428438

429439
if (pool->unaligned)
430440
xp_check_dma_contiguity(dma_map);
431-
else
432-
for (i = 0; i < pool->heads_cnt; i++) {
433-
struct xdp_buff_xsk *xskb = &pool->heads[i];
434-
435-
xp_init_xskb_dma(xskb, pool, dma_map->dma_pages, xskb->orig_addr);
436-
}
437441

438442
err = xp_init_dma_info(pool, dma_map);
439443
if (err) {

0 commit comments

Comments
 (0)