mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-27 18:43:12 -04:00
bpf: Log error code on trampoline unlink failure
Replace silent WARN_ON_ONCE with WARN_ONCE that prints the actual error code from bpf_trampoline_unlink_prog(). This aids debugging of race conditions during link teardown, while keeping the warning rate limited to avoid log flooding. This will be very helpful for speeding up trouble-shooting of some crash UAF due to bpf_trampoline_unlink_prog failures. No change to unlink behavior. Signed-off-by: Xu Xin <xu.xin16@zte.com.cn> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Acked-by: Leon Hwang <leon.hwang@linux.dev> Link: https://lore.kernel.org/bpf/20260729141159128mEJmS_aujBKr-cBu1p_UI@zte.com.cn
This commit is contained in:
@@ -3555,10 +3555,12 @@ static void bpf_tracing_link_release(struct bpf_link *link)
|
||||
{
|
||||
struct bpf_tracing_link *tr_link =
|
||||
container_of(link, struct bpf_tracing_link, link.link);
|
||||
int err;
|
||||
|
||||
WARN_ON_ONCE(bpf_trampoline_unlink_prog(&tr_link->link.node,
|
||||
tr_link->trampoline,
|
||||
tr_link->tgt_prog));
|
||||
err = bpf_trampoline_unlink_prog(&tr_link->link.node,
|
||||
tr_link->trampoline,
|
||||
tr_link->tgt_prog);
|
||||
WARN_ONCE(err, "bpf_trampoline_unlink_prog failed: %d\n", err);
|
||||
|
||||
bpf_trampoline_put(tr_link->trampoline);
|
||||
|
||||
|
||||
@@ -1004,12 +1004,15 @@ static void bpf_shim_tramp_link_release(struct bpf_link *link)
|
||||
{
|
||||
struct bpf_shim_tramp_link *shim_link =
|
||||
container_of(link, struct bpf_shim_tramp_link, link.link);
|
||||
int err;
|
||||
|
||||
/* paired with 'shim_link->trampoline = tr' in bpf_trampoline_link_cgroup_shim */
|
||||
if (!shim_link->trampoline)
|
||||
return;
|
||||
|
||||
WARN_ON_ONCE(bpf_trampoline_unlink_prog(&shim_link->link.node, shim_link->trampoline, NULL));
|
||||
err = bpf_trampoline_unlink_prog(&shim_link->link.node, shim_link->trampoline, NULL);
|
||||
WARN_ONCE(err, "bpf_trampoline_unlink_prog failed: %d\n", err);
|
||||
|
||||
bpf_trampoline_put(shim_link->trampoline);
|
||||
}
|
||||
|
||||
@@ -1720,15 +1723,16 @@ int bpf_trampoline_multi_detach(struct bpf_prog *prog, struct bpf_tracing_multi_
|
||||
{
|
||||
struct bpf_tracing_multi_data *data = &link->data;
|
||||
struct bpf_tracing_multi_node *mnode;
|
||||
int i;
|
||||
int i, err;
|
||||
|
||||
trampoline_lock_all();
|
||||
|
||||
for_each_mnode(mnode, link) {
|
||||
data->entry = &mnode->entry;
|
||||
bpf_trampoline_multi_attach_init(mnode->trampoline);
|
||||
WARN_ON_ONCE(__bpf_trampoline_unlink_prog(&mnode->node, mnode->trampoline,
|
||||
NULL, &trampoline_multi_ops, data));
|
||||
err = __bpf_trampoline_unlink_prog(&mnode->node, mnode->trampoline, NULL,
|
||||
&trampoline_multi_ops, data);
|
||||
WARN_ONCE(err, "__bpf_trampoline_unlink_prog failed: %d\n", err);
|
||||
}
|
||||
|
||||
if (ftrace_hash_count(data->unreg))
|
||||
|
||||
Reference in New Issue
Block a user