Commit 55760083 authored by Ian Rogers's avatar Ian Rogers Committed by Greg Kroah-Hartman
Browse files

selftests/xsk: Avoid use-after-free on ctx

[ Upstream commit af515a55 ]

The put lowers the reference count to 0 and frees ctx, reading it
afterwards is invalid. Move the put after the uses and determine the
last use by the reference count being 1.

Fixes: 39e940d4

 ("selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0")
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMagnus Karlsson <magnus.karlsson@intel.com>
Link: https://lore.kernel.org/bpf/20220901202645.1463552-1-irogers@google.com

Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent c823df06
linux-5.10.y Tags unavailable
No related merge requests found
Showing with 3 additions and 3 deletions
+3 -3
......@@ -930,13 +930,13 @@ void xsk_socket__delete(struct xsk_socket *xsk)
ctx = xsk->ctx;
umem = ctx->umem;
xsk_put_ctx(ctx, true);
if (!ctx->refcount) {
if (ctx->refcount == 1) {
xsk_delete_bpf_maps(xsk);
close(ctx->prog_fd);
}
xsk_put_ctx(ctx, true);
err = xsk_get_mmap_offsets(xsk->fd, &off);
if (!err) {
if (xsk->rx) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment