selftests/xsk: Avoid use-after-free on ctx
authorIan Rogers <irogers@google.com>
Thu, 1 Sep 2022 20:26:45 +0000 (13:26 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:34:41 +0000 (12:34 +0200)
commit37005a948677c3305fab6a3354e5c2945568d7c0
tree423e9c1b35fd591eb02dcbaee09b117eb19dc10d
parent69995c64e50efcf6dcc33b30a1142eaa62c401c1
selftests/xsk: Avoid use-after-free on ctx

[ Upstream commit af515a5587b8f45f19e11657746e0c89411b0380 ]

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: 39e940d4abfa ("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>
tools/lib/bpf/xsk.c