Skip to content

Commit 66f48ff

Browse files
committed
Merge: fprobe: Release rethook after the ftrace_ops is unregistered
MR: https://gitlab.com/redhat/rhel/src/kernel/rhel-9/-/merge_requests/1357 JIRA: https://issues.redhat.com/browse/RHEL-26131 There is a known bug in the fprobe subsystem which may cause a fault while running bpf selftests. This MR backports the upstream commits fixing the issue. Signed-off-by: Viktor Malik <vmalik@redhat.com> Approved-by: Jerome Marchand <jmarchan@redhat.com> Approved-by: John B. Wyatt IV <jwyatt@redhat.com> Merged-by: Scott Weaver <scweaver@redhat.com>
2 parents eb20720 + 7f41350 commit 66f48ff

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

include/linux/rethook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct rethook_node {
5959
};
6060

6161
struct rethook *rethook_alloc(void *data, rethook_handler_t handler);
62+
void rethook_stop(struct rethook *rh);
6263
void rethook_free(struct rethook *rh);
6364
void rethook_add_node(struct rethook *rh, struct rethook_node *node);
6465
struct rethook_node *rethook_try_get(struct rethook *rh);

kernel/trace/fprobe.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,16 @@ int unregister_fprobe(struct fprobe *fp)
349349
fp->ops.saved_func != fprobe_kprobe_handler))
350350
return -EINVAL;
351351

352-
/*
353-
* rethook_free() starts disabling the rethook, but the rethook handlers
354-
* may be running on other processors at this point. To make sure that all
355-
* current running handlers are finished, call unregister_ftrace_function()
356-
* after this.
357-
*/
358352
if (fp->rethook)
359-
rethook_free(fp->rethook);
353+
rethook_stop(fp->rethook);
360354

361355
ret = unregister_ftrace_function(&fp->ops);
362356
if (ret < 0)
363357
return ret;
364358

359+
if (fp->rethook)
360+
rethook_free(fp->rethook);
361+
365362
ftrace_free_filter(&fp->ops);
366363

367364
return ret;

kernel/trace/rethook.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ static void rethook_free_rcu(struct rcu_head *head)
5353
kfree(rh);
5454
}
5555

56+
/**
57+
* rethook_stop() - Stop using a rethook.
58+
* @rh: the struct rethook to stop.
59+
*
60+
* Stop using a rethook to prepare for freeing it. If you want to wait for
61+
* all running rethook handler before calling rethook_free(), you need to
62+
* call this first and wait RCU, and call rethook_free().
63+
*/
64+
void rethook_stop(struct rethook *rh)
65+
{
66+
WRITE_ONCE(rh->handler, NULL);
67+
}
68+
5669
/**
5770
* rethook_free() - Free struct rethook.
5871
* @rh: the struct rethook to be freed.

0 commit comments

Comments
 (0)