summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKal Conley <kal.conley@dectris.com>2023-04-11 15:00:25 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2023-04-13 15:00:11 +0200
commit1ba83f505c53d35eda892ac7f108ef1189da6fa8 (patch)
tree5ed7d9a1770a21249577fa2608f0e798c576c8b1 /net
parent4099be372faf7b3616634dfe6994b81b1edf1906 (diff)
downloadlinux-stable-1ba83f505c53d35eda892ac7f108ef1189da6fa8.tar.gz
linux-stable-1ba83f505c53d35eda892ac7f108ef1189da6fa8.tar.bz2
linux-stable-1ba83f505c53d35eda892ac7f108ef1189da6fa8.zip
xsk: Elide base_addr comparison in xp_unaligned_validate_desc
Remove redundant (base_addr >= pool->addrs_cnt) comparison from the conditional. In particular, addr is computed as: addr = base_addr + offset ... where base_addr and offset are stored as 48-bit and 16-bit unsigned integers, respectively. The above sum cannot overflow u64 since base_addr has a maximum value of 0x0000ffffffffffff and offset has a maximum value of 0xffff (implying a maximum sum of 0x000100000000fffe). Since overflow is impossible, it follows that addr >= base_addr. Now if (base_addr >= pool->addrs_cnt), then clearly: addr >= base_addr >= pool->addrs_cnt Thus, (base_addr >= pool->addrs_cnt) implies (addr >= pool->addrs_cnt). Subsequently, the former comparison is unnecessary in the conditional since for any boolean expressions A and B, (A || B) && (A -> B) is equivalent to B. Signed-off-by: Kal Conley <kal.conley@dectris.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Link: https://lore.kernel.org/bpf/20230411130025.19704-1-kal.conley@dectris.com
Diffstat (limited to 'net')
-rw-r--r--net/xdp/xsk_queue.h8
1 files changed, 2 insertions, 6 deletions
diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index 76b574bffd4a..6d40a77fccbe 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -149,16 +149,12 @@ static inline bool xp_aligned_validate_desc(struct xsk_buff_pool *pool,
static inline bool xp_unaligned_validate_desc(struct xsk_buff_pool *pool,
struct xdp_desc *desc)
{
- u64 addr, base_addr;
-
- base_addr = xp_unaligned_extract_addr(desc->addr);
- addr = xp_unaligned_add_offset_to_addr(desc->addr);
+ u64 addr = xp_unaligned_add_offset_to_addr(desc->addr);
if (desc->len > pool->chunk_size)
return false;
- if (base_addr >= pool->addrs_cnt || addr >= pool->addrs_cnt ||
- addr + desc->len > pool->addrs_cnt ||
+ if (addr >= pool->addrs_cnt || addr + desc->len > pool->addrs_cnt ||
xp_desc_crosses_non_contig_pg(pool, addr, desc->len))
return false;