Skip to content

Commit 0fae7d2

Browse files
magnus-karlssongregkh
authored andcommitted
xsk: Fix memory leak for failed bind
commit 8bee683 upstream. 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: 7361f9c ("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 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 563135e commit 0fae7d2

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎net/xdp/xsk.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
772772
}
773773
}
774774

775+
/* FQ and CQ are now owned by the buffer pool and cleaned up with it. */
776+
xs->fq_tmp = NULL;
777+
xs->cq_tmp = NULL;
778+
775779
xs->dev = dev;
776780
xs->zc = xs->umem->zc;
777781
xs->queue_id = qid;

‎net/xdp/xsk_buff_pool.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ struct xsk_buff_pool *xp_create_and_assign_umem(struct xdp_sock *xs,
7575

7676
pool->fq = xs->fq_tmp;
7777
pool->cq = xs->cq_tmp;
78-
xs->fq_tmp = NULL;
79-
xs->cq_tmp = NULL;
8078

8179
for (i = 0; i < pool->free_heads_cnt; i++) {
8280
xskb = &pool->heads[i];

0 commit comments

Comments
 (0)