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)
commitb16a87d0aef7a6be766f6618976dc5ff2c689291
treef11fe5d40a3ad84d2fa05b301c0484282f9dbe40
parentd04322a0da1e86aedaa322ce933cfb8c0191d1eb
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: c0c77d8fb787 ("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