Skip to content

Commit

Permalink
kprobes: Warn if the kprobe is reregistered
Browse files Browse the repository at this point in the history
Warn if the kprobe is reregistered, since there must be
a software bug (actively used resource must not be re-registered)
and caller must be fixed.

Link: https://lkml.kernel.org/r/161236436734.194052.4058506306336814476.stgit@devnote2

Acked-by: Naveen N. Rao <[email protected]>
Acked-by: Ananth N Mavinakayanahalli <[email protected]>
Signed-off-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Steven Rostedt (VMware) <[email protected]>
  • Loading branch information
mhiramat authored and rostedt committed Feb 9, 2021
1 parent a1320e0 commit 33b1d14
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1520,13 +1520,16 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p)
return ap;
}

/* Return error if the kprobe is being re-registered */
static inline int check_kprobe_rereg(struct kprobe *p)
/*
* Warn and return error if the kprobe is being re-registered since
* there must be a software bug.
*/
static inline int warn_kprobe_rereg(struct kprobe *p)
{
int ret = 0;

mutex_lock(&kprobe_mutex);
if (__get_valid_kprobe(p))
if (WARN_ON_ONCE(__get_valid_kprobe(p)))
ret = -EINVAL;
mutex_unlock(&kprobe_mutex);

Expand Down Expand Up @@ -1614,7 +1617,7 @@ int register_kprobe(struct kprobe *p)
return PTR_ERR(addr);
p->addr = addr;

ret = check_kprobe_rereg(p);
ret = warn_kprobe_rereg(p);
if (ret)
return ret;

Expand Down Expand Up @@ -1995,7 +1998,7 @@ int register_kretprobe(struct kretprobe *rp)
return ret;

/* If only rp->kp.addr is specified, check reregistering kprobes */
if (rp->kp.addr && check_kprobe_rereg(&rp->kp))
if (rp->kp.addr && warn_kprobe_rereg(&rp->kp))
return -EINVAL;

if (kretprobe_blacklist_size) {
Expand Down

0 comments on commit 33b1d14

Please sign in to comment.