linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Punit Agrawal <punitagrawal@gmail.com>
To: Masami Hiramatsu <mhiramat@kernel.org>
Cc: naveen.n.rao@linux.ibm.com, anil.s.keshavamurthy@intel.com,
	davem@davemloft.net, linux-kernel@vger.kernel.org,
	guoren@kernel.org, linux-csky@vger.kernel.org
Subject: Re: [PATCH 1/5] kprobes: Do not use local variable when creating debugfs file
Date: Fri, 11 Jun 2021 08:31:44 +0900	[thread overview]
Message-ID: <87im2ljnz3.fsf@stealth> (raw)
In-Reply-To: <20210609233543.e846251ccaa227317de26b11@kernel.org> (Masami Hiramatsu's message of "Wed, 9 Jun 2021 23:35:43 +0900")

Hi Masami,

Masami Hiramatsu <mhiramat@kernel.org> writes:

> On Wed,  9 Jun 2021 19:50:15 +0900
> Punit Agrawal <punitagrawal@gmail.com> wrote:
>
>> debugfs_create_file() takes a pointer argument that can be used during
>> file operation callbacks (accessible via i_private in the inode
>> structure). An obvious requirement is for the pointer to refer to
>> valid memory when used.
>> 
>> When creating the debugfs file to dynamically enable / disable
>> kprobes, a pointer to local variable is passed to
>> debugfs_create_file(); which will go out of scope when the init
>> function returns. The reason this hasn't triggered random memory
>> corruption is because the pointer is not accessed during the debugfs
>> file callbacks.
>> 
>> Fix the incorrect (and unnecessary) usage of local variable during
>> debugfs_file_create() by passing NULL instead.
>> 
>
> Good catch! Since the enabled state is managed by the kprobes_all_disabled
> global variable, it is not needed.
>
> Fixes: bf8f6e5b3e51 ("Kprobes: The ON/OFF knob thru debugfs")
> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Thanks a lot for reviewing the patches.

I am assuming the tags can be picked up when applying. Let me know if I
need to resend.

Thanks,
Punit

>
> Thank you!
>
>> Signed-off-by: Punit Agrawal <punitagrawal@gmail.com>
>> ---
>>  kernel/kprobes.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>> 
>> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
>> index 745f08fdd7a6..fdb1ea2e963b 100644
>> --- a/kernel/kprobes.c
>> +++ b/kernel/kprobes.c
>> @@ -2816,13 +2816,12 @@ static const struct file_operations fops_kp = {
>>  static int __init debugfs_kprobe_init(void)
>>  {
>>  	struct dentry *dir;
>> -	unsigned int value = 1;
>>  
>>  	dir = debugfs_create_dir("kprobes", NULL);
>>  
>>  	debugfs_create_file("list", 0400, dir, NULL, &kprobes_fops);
>>  
>> -	debugfs_create_file("enabled", 0600, dir, &value, &fops_kp);
>> +	debugfs_create_file("enabled", 0600, dir, NULL, &fops_kp);
>>  
>>  	debugfs_create_file("blacklist", 0400, dir, NULL,
>>  			    &kprobe_blacklist_fops);
>> -- 
>> 2.30.2
>> 

  reply	other threads:[~2021-06-10 23:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 10:50 [PATCH 0/5] kprobes: Bugfix and improvements Punit Agrawal
2021-06-09 10:50 ` [PATCH 1/5] kprobes: Do not use local variable when creating debugfs file Punit Agrawal
2021-06-09 14:35   ` Masami Hiramatsu
2021-06-10 23:31     ` Punit Agrawal [this message]
2021-06-09 10:50 ` [RFC PATCH 2/5] kprobes: Use helper to parse boolean input from userspace Punit Agrawal
2021-06-09 14:37   ` Masami Hiramatsu
2021-06-09 10:50 ` [RFC PATCH 3/5] kprobe: Simplify prepare_kprobe() by dropping redundant version Punit Agrawal
2021-06-09 14:42   ` Masami Hiramatsu
2021-06-09 10:50 ` [RFC PATCH 4/5] csky: ftrace: Drop duplicate implementation of arch_check_ftrace_location() Punit Agrawal
2021-06-09 12:33   ` Guo Ren
2021-06-09 14:29     ` Masami Hiramatsu
2021-06-09 15:47       ` Guo Ren
2021-06-10  0:07   ` Masami Hiramatsu
2021-06-09 10:50 ` [RFC PATCH 5/5] kprobes: Make arch_check_ftrace_location static Punit Agrawal
2021-06-10  0:37   ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87im2ljnz3.fsf@stealth \
    --to=punitagrawal@gmail.com \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=davem@davemloft.net \
    --cc=guoren@kernel.org \
    --cc=linux-csky@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=naveen.n.rao@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).