Skip to content

Commit

Permalink
xsk: Fix for xp_aligned_validate_desc() when len == chunk_size
Browse files Browse the repository at this point in the history
When desc->len is equal to chunk_size, it is legal. But when the
xp_aligned_validate_desc() got chunk_end from desc->addr + desc->len
pointing to the next chunk during the check, it caused the check to
fail.

This problem was first introduced in bbff2f3 ("xsk: new descriptor
addressing scheme"). Later in 2b43470 ("xsk: Introduce AF_XDP buffer
allocation API") this piece of code was moved into the new function called
xp_aligned_validate_desc(). This function was then moved into xsk_queue.h
via 26062b1 ("xsk: Explicitly inline functions and move definitions").

Fixes: bbff2f3 ("xsk: new descriptor addressing scheme")
Signed-off-by: Xuan Zhuo <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Magnus Karlsson <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
fengidri authored and borkmann committed May 3, 2021
1 parent 2a30f94 commit ac31565
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions net/xdp/xsk_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,12 @@ static inline bool xskq_cons_read_addr_unchecked(struct xsk_queue *q, u64 *addr)
static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
struct xdp_desc *desc)
{
u64 chunk, chunk_end;
u64 chunk;

chunk = xp_aligned_extract_addr(pool, desc->addr);
chunk_end = xp_aligned_extract_addr(pool, desc->addr + desc->len);
if (chunk != chunk_end)
if (desc->len > pool->chunk_size)
return false;

chunk = xp_aligned_extract_addr(pool, desc->addr);
if (chunk >= pool->addrs_cnt)
return false;

Expand Down

0 comments on commit ac31565

Please sign in to comment.