All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu <mhiramat@kernel.org>
To: Andrea Righi <righi.andrea@gmail.com>
Cc: "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Yonghong Song <yhs@fb.com>, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] kprobes: x86_64: blacklist non-attachable interrupt functions
Date: Sat, 8 Dec 2018 12:48:59 +0900	[thread overview]
Message-ID: <20181208124859.7318e32abfab4cc6dc2da3a8@kernel.org> (raw)
In-Reply-To: <20181207175805.GA1369@Dell>

On Fri, 7 Dec 2018 18:58:05 +0100
Andrea Righi <righi.andrea@gmail.com> wrote:

> On Sat, Dec 08, 2018 at 01:01:20AM +0900, Masami Hiramatsu wrote:
> > Hi Andrea and Ingo,
> > 
> > Here is the patch what I meant. I just ran it on qemu-x86, and seemed working.
> > After introducing this patch, I will start adding arch_populate_kprobe_blacklist()
> > to some arches.
> > 
> > Thank you,
> > 
> > [RFC] kprobes: x86/kprobes: Blacklist symbols in arch-defined prohibited area
> > 
> > From: Masami Hiramatsu <mhiramat@kernel.org>
> > 
> > Blacklist symbols in arch-defined probe-prohibited areas.
> > With this change, user can see all symbols which are prohibited
> > to probe in debugfs.
> > 
> > All archtectures which have custom prohibit areas should define
> > its own arch_populate_kprobe_blacklist() function, but unless that,
> > all symbols marked __kprobes are blacklisted.
> 
> What about iterating all symbols and use arch_within_kprobe_blacklist()
> to check if we need to blacklist them or not.

Sorry, I don't want to iterate all ksyms since it may take a long time
(especially embedded small devices.)

> 
> In this way we don't have to introduce an
> arch_populate_kprobe_blacklist() for each architecture.

Hmm, I had a same idea, but there are some arch which prohibit probing
extable entries (e.g. arm64.) For correctness of the blacklist, I think
it should be listed (not entire the function body).
I also rather like to remove arch_within_kprobe_blacklist() instead.

Thank you,

> 
> Something like the following maybe.
> 
> Thanks.
> 
> [RFC] kprobes: blacklist all symbols in arch-defined prohibited area
> 
> From: Andrea Righi <righi.andrea@gmail.com>
> 
> Blacklist symbols in arch-defined probe-prohibited areas.
> With this change, user can see all symbols which are prohibited
> to probe in debugfs.
> 
> Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
> Signed-off-by: Andrea Righi <righi.andrea@gmail.com>
> ---
>  kernel/kprobes.c | 55 +++++++++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 41 insertions(+), 14 deletions(-)
> 
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 90e98e233647..e67598dd7468 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -2093,6 +2093,35 @@ void dump_kprobe(struct kprobe *kp)
>  }
>  NOKPROBE_SYMBOL(dump_kprobe);
>  
> +static int kprobe_blacklist_add(unsigned long entry)
> +{
> +	struct kprobe_blacklist_entry *ent;
> +	unsigned long offset = 0, size = 0;
> +
> +	if (!kernel_text_address(entry) ||
> +	    !kallsyms_lookup_size_offset(entry, &size, &offset))
> +		return -EINVAL;
> +
> +	ent = kmalloc(sizeof(*ent), GFP_KERNEL);
> +	if (!ent)
> +		return -ENOMEM;
> +	ent->start_addr = entry;
> +	ent->end_addr = entry + size;
> +	INIT_LIST_HEAD(&ent->list);
> +	list_add_tail(&ent->list, &kprobe_blacklist);
> +
> +	return 0;
> +}
> +
> +static int arch_populate_kprobe_blacklist(void *data, const char *name,
> +					  struct module *mod,
> +					  unsigned long entry)
> +{
> +	if (arch_within_kprobe_blacklist(entry))
> +		kprobe_blacklist_add(entry);
> +	return 0;
> +}
> +
>  /*
>   * Lookup and populate the kprobe_blacklist.
>   *
> @@ -2104,24 +2133,22 @@ NOKPROBE_SYMBOL(dump_kprobe);
>  static int __init populate_kprobe_blacklist(unsigned long *start,
>  					     unsigned long *end)
>  {
> -	unsigned long *iter;
> -	struct kprobe_blacklist_entry *ent;
> -	unsigned long entry, offset = 0, size = 0;
> +	unsigned long entry, *iter;
> +	int ret;
>  
> +	/* Blacklist all arch_within_kprobe_blacklist() symbols */
> +        mutex_lock(&module_mutex);
> +	kallsyms_on_each_symbol(arch_populate_kprobe_blacklist, NULL);
> +        mutex_unlock(&module_mutex);
> +
> +	/* Add explicitly blacklisted symbols */
>  	for (iter = start; iter < end; iter++) {
>  		entry = arch_deref_entry_point((void *)*iter);
> -
> -		if (!kernel_text_address(entry) ||
> -		    !kallsyms_lookup_size_offset(entry, &size, &offset))
> +		ret = kprobe_blacklist_add(entry);
> +		if (ret == -EINVAL)
>  			continue;
> -
> -		ent = kmalloc(sizeof(*ent), GFP_KERNEL);
> -		if (!ent)
> -			return -ENOMEM;
> -		ent->start_addr = entry;
> -		ent->end_addr = entry + size;
> -		INIT_LIST_HEAD(&ent->list);
> -		list_add_tail(&ent->list, &kprobe_blacklist);
> +		if (ret < 0)
> +			return ret;
>  	}
>  	return 0;
>  }


-- 
Masami Hiramatsu <mhiramat@kernel.org>

  reply	other threads:[~2018-12-08  3:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06  9:56 [PATCH] kprobes: x86_64: blacklist non-attachable interrupt functions Andrea Righi
2018-12-06 16:39 ` [tip:perf/urgent] kprobes/x86: Blacklist " tip-bot for Andrea Righi
2018-12-07 14:47 ` [PATCH] kprobes: x86_64: blacklist " Masami Hiramatsu
2018-12-07 16:01   ` Masami Hiramatsu
2018-12-07 17:00     ` Andrea Righi
2018-12-08  3:42       ` Masami Hiramatsu
2018-12-08  7:07         ` Andrea Righi
2018-12-07 17:58     ` Andrea Righi
2018-12-08  3:48       ` Masami Hiramatsu [this message]
2018-12-08  7:09         ` Andrea Righi
2018-12-16 16:07           ` 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=20181208124859.7318e32abfab4cc6dc2da3a8@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=bp@alien8.de \
    --cc=davem@davemloft.net \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=righi.andrea@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.