]> git.baikalelectronics.ru Git - kernel.git/commit
xsk: Fix memory leak for failed bind
authorMagnus Karlsson <magnus.karlsson@intel.com>
Mon, 14 Dec 2020 08:51:27 +0000 (09:51 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 17 Dec 2020 21:48:55 +0000 (22:48 +0100)
commit783afad414f826cf75528b95f0b88ca932fbb34d
treedb533ade0953c52fa78891861812cdddb30df62e
parentd2d9173346a1c8cb30f283aab9f5d87935a9c1d6
xsk: Fix memory leak for failed bind

Fix a possible memory leak when a bind of an AF_XDP socket fails. When
the fill and completion rings are created, they are tied to the
socket. But when the buffer pool is later created at bind time, the
ownership of these two rings are transferred to the buffer pool as
they might be shared between sockets (and the buffer pool cannot be
created until we know what we are binding to). So, before the buffer
pool is created, these two rings are cleaned up with the socket, and
after they have been transferred they are cleaned up together with
the buffer pool.

The problem is that ownership was transferred before it was absolutely
certain that the buffer pool could be created and initialized
correctly and when one of these errors occurred, the fill and
completion rings did neither belong to the socket nor the pool and
where therefore leaked. Solve this by moving the ownership transfer
to the point where the buffer pool has been completely set up and
there is no way it can fail.

Fixes: a87538dc82da ("xsk: Move fill and completion rings to buffer pool")
Reported-by: syzbot+cfa88ddd0655afa88763@syzkaller.appspotmail.com
Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Björn Töpel <bjorn.topel@intel.com>
Link: https://lore.kernel.org/bpf/20201214085127.3960-1-magnus.karlsson@gmail.com
net/xdp/xsk.c
net/xdp/xsk_buff_pool.c