]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf, xsk: Init all ring members in xsk_umem__create and xsk_socket__create
authorFletcher Dunn <fletcherd@valvesoftware.com>
Fri, 27 Mar 2020 03:24:07 +0000 (03:24 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 28 Mar 2020 16:12:56 +0000 (17:12 +0100)
commita08204c2b91aef40b0b974a00f88331397bd4f74
tree1470d902a48b8056ab3006894c8865e724322e0b
parentfc4dbe30bb87ca4a4089e4afa4addf013f259f0e
libbpf, xsk: Init all ring members in xsk_umem__create and xsk_socket__create

Fix a sharp edge in xsk_umem__create and xsk_socket__create.  Almost all of
the members of the ring buffer structs are initialized, but the "cached_xxx"
variables are not all initialized.  The caller is required to zero them.
This is needlessly dangerous.  The results if you don't do it can be very bad.
For example, they can cause xsk_prod_nb_free and xsk_cons_nb_avail to return
values greater than the size of the queue.  xsk_ring_cons__peek can return an
index that does not refer to an item that has been queued.

I have confirmed that without this change, my program misbehaves unless I
memset the ring buffers to zero before calling the function.  Afterwards,
my program works without (or with) the memset.

Signed-off-by: Fletcher Dunn <fletcherd@valvesoftware.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Magnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/85f12913cde94b19bfcb598344701c38@valvesoftware.com
tools/lib/bpf/xsk.c