2020-05-05 14:16:28

by Thomas Gleixner

[permalink] [raw]
Subject: [patch V4 part 1 15/36] kprobes: Lock kprobe_mutex while showing kprobe_blacklist

From: Masami Hiramatsu <[email protected]>

Lock kprobe_mutex while showing kprobe_blacklist to prevent updating the
kprobe_blacklist.

Signed-off-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://lkml.kernel.org/r/158523417665.24735.10253198878535635600.stgit@devnote2

---
kernel/kprobes.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2426,6 +2426,7 @@ static const struct file_operations debu
/* kprobes/blacklist -- shows which functions can not be probed */
static void *kprobe_blacklist_seq_start(struct seq_file *m, loff_t *pos)
{
+ mutex_lock(&kprobe_mutex);
return seq_list_start(&kprobe_blacklist, *pos);
}

@@ -2452,10 +2453,15 @@ static int kprobe_blacklist_seq_show(str
return 0;
}

+static void kprobe_blacklist_seq_stop(struct seq_file *f, void *v)
+{
+ mutex_unlock(&kprobe_mutex);
+}
+
static const struct seq_operations kprobe_blacklist_seq_ops = {
.start = kprobe_blacklist_seq_start,
.next = kprobe_blacklist_seq_next,
- .stop = kprobe_seq_stop, /* Reuse void function */
+ .stop = kprobe_blacklist_seq_stop,
.show = kprobe_blacklist_seq_show,
};



2020-05-06 15:43:10

by Alexandre Chartre

[permalink] [raw]
Subject: Re: [patch V4 part 1 15/36] kprobes: Lock kprobe_mutex while showing kprobe_blacklist


On 5/5/20 3:16 PM, Thomas Gleixner wrote:
> From: Masami Hiramatsu <[email protected]>
>
> Lock kprobe_mutex while showing kprobe_blacklist to prevent updating the
> kprobe_blacklist.
>
> Signed-off-by: Masami Hiramatsu <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Link: https://lkml.kernel.org/r/158523417665.24735.10253198878535635600.stgit@devnote2
>
> ---
> kernel/kprobes.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)

Reviewed-by: Alexandre Chartre <[email protected]>

alex.

> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2426,6 +2426,7 @@ static const struct file_operations debu
> /* kprobes/blacklist -- shows which functions can not be probed */
> static void *kprobe_blacklist_seq_start(struct seq_file *m, loff_t *pos)
> {
> + mutex_lock(&kprobe_mutex);
> return seq_list_start(&kprobe_blacklist, *pos);
> }
>
> @@ -2452,10 +2453,15 @@ static int kprobe_blacklist_seq_show(str
> return 0;
> }
>
> +static void kprobe_blacklist_seq_stop(struct seq_file *f, void *v)
> +{
> + mutex_unlock(&kprobe_mutex);
> +}
> +
> static const struct seq_operations kprobe_blacklist_seq_ops = {
> .start = kprobe_blacklist_seq_start,
> .next = kprobe_blacklist_seq_next,
> - .stop = kprobe_seq_stop, /* Reuse void function */
> + .stop = kprobe_blacklist_seq_stop,
> .show = kprobe_blacklist_seq_show,
> };
>
>

Subject: [tip: core/kprobes] kprobes: Lock kprobe_mutex while showing kprobe_blacklist

The following commit has been merged into the core/kprobes branch of tip:

Commit-ID: 4fdd88877e5259dcc5e504dca449acc0324d71b9
Gitweb: https://git.kernel.org/tip/4fdd88877e5259dcc5e504dca449acc0324d71b9
Author: Masami Hiramatsu <[email protected]>
AuthorDate: Thu, 26 Mar 2020 23:49:36 +09:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Tue, 12 May 2020 17:15:31 +02:00

kprobes: Lock kprobe_mutex while showing kprobe_blacklist

Lock kprobe_mutex while showing kprobe_blacklist to prevent updating the
kprobe_blacklist.

Signed-off-by: Masami Hiramatsu <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Alexandre Chartre <[email protected]>
Acked-by: Peter Zijlstra <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]

---
kernel/kprobes.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 2625c24..570d608 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -2420,6 +2420,7 @@ static const struct file_operations debugfs_kprobes_operations = {
/* kprobes/blacklist -- shows which functions can not be probed */
static void *kprobe_blacklist_seq_start(struct seq_file *m, loff_t *pos)
{
+ mutex_lock(&kprobe_mutex);
return seq_list_start(&kprobe_blacklist, *pos);
}

@@ -2446,10 +2447,15 @@ static int kprobe_blacklist_seq_show(struct seq_file *m, void *v)
return 0;
}

+static void kprobe_blacklist_seq_stop(struct seq_file *f, void *v)
+{
+ mutex_unlock(&kprobe_mutex);
+}
+
static const struct seq_operations kprobe_blacklist_seq_ops = {
.start = kprobe_blacklist_seq_start,
.next = kprobe_blacklist_seq_next,
- .stop = kprobe_seq_stop, /* Reuse void function */
+ .stop = kprobe_blacklist_seq_stop,
.show = kprobe_blacklist_seq_show,
};