]> git.baikalelectronics.ru Git - kernel.git/commit
xsk: Add overflow check for u64 division, stored into u32
authorBjörn Töpel <bjorn.topel@intel.com>
Mon, 25 May 2020 08:03:59 +0000 (10:03 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 25 May 2020 22:06:00 +0000 (00:06 +0200)
commit6ab6d1bec9c2518b032f17574c7a0f89b49ab1ef
treef11fe5d40a3ad84d2fa05b301c0484282f9dbe40
parent41027c890044f6438fb32bf9ba7ea9d588cfee33
xsk: Add overflow check for u64 division, stored into u32

The npgs member of struct xdp_umem is an u32 entity, and stores the
number of pages the UMEM consumes. The calculation of npgs

  npgs = size / PAGE_SIZE

can overflow.

To avoid overflow scenarios, the division is now first stored in a
u64, and the result is verified to fit into 32b.

An alternative would be storing the npgs as a u64, however, this
wastes memory and is an unrealisticly large packet area.

Fixes: 8b9341b67841 ("xsk: add user memory registration support sockopt")
Reported-by: "Minh Bùi Quang" <minhquangbui99@gmail.com>
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Link: https://lore.kernel.org/bpf/CACtPs=GGvV-_Yj6rbpzTVnopgi5nhMoCcTkSkYrJHGQHJWFZMQ@mail.gmail.com/
Link: https://lore.kernel.org/bpf/20200525080400.13195-1-bjorn.topel@gmail.com
net/xdp/xdp_umem.c