selftests/xsk: Avoid use-after-free on ctx
[ Upstream commitaf515a5587] 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:39e940d4ab("selftests/xsk: Destroy BPF resources only when ctx refcount drops to 0") Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Magnus Karlsson <magnus.karlsson@intel.com> Link: https://lore.kernel.org/bpf/20220901202645.1463552-1-irogers@google.com Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
c823df0679
commit
5576008305
@@ -930,13 +930,13 @@ void xsk_socket__delete(struct xsk_socket *xsk)
|
|||||||
ctx = xsk->ctx;
|
ctx = xsk->ctx;
|
||||||
umem = ctx->umem;
|
umem = ctx->umem;
|
||||||
|
|
||||||
xsk_put_ctx(ctx, true);
|
if (ctx->refcount == 1) {
|
||||||
|
|
||||||
if (!ctx->refcount) {
|
|
||||||
xsk_delete_bpf_maps(xsk);
|
xsk_delete_bpf_maps(xsk);
|
||||||
close(ctx->prog_fd);
|
close(ctx->prog_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xsk_put_ctx(ctx, true);
|
||||||
|
|
||||||
err = xsk_get_mmap_offsets(xsk->fd, &off);
|
err = xsk_get_mmap_offsets(xsk->fd, &off);
|
||||||
if (!err) {
|
if (!err) {
|
||||||
if (xsk->rx) {
|
if (xsk->rx) {
|
||||||
|
|||||||
Reference in New Issue
Block a user