mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Quentin Casasnovas <quentin.casasnovas@oracle.com>
To: Quentin Casasnovas <quentin.casasnovas@oracle.com>,
	Rusty Russell <rusty@rustcorp.com.au>,
	Michal Marek <mmarek@suse.cz>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Oleg Nesterov <oleg@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 3/7] modpost: add handler function pointer to sectioncheck.
Date: Wed, 18 Mar 2015 10:08:25 +0100	[thread overview]
Message-ID: <20150318090825.GH19131@chrystal.uk.oracle.com> (raw)
In-Reply-To: <1426596002-26128-4-git-send-email-quentin.casasnovas@oracle.com>

Adding Rusty and Michal to CC.

On Tue, Mar 17, 2015 at 01:39:58PM +0100, Quentin Casasnovas wrote:
> This will be useful when we want to have special handlers which need to go
> through more hops to print useful information to the user.
> 
> Signed-off-by: Quentin Casasnovas <quentin.casasnovas@oracle.com>
> ---
>  scripts/mod/modpost.c | 68 +++++++++++++++++++++++++++++++--------------------
>  1 file changed, 42 insertions(+), 26 deletions(-)
> 
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 8cef46b..0f48f8b 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -930,6 +930,10 @@ struct sectioncheck {
>  	const char *good_tosec[20];
>  	enum mismatch mismatch;
>  	const char *symbol_white_list[20];
> +	void (*handler)(const char *modname, struct elf_info *elf,
> +			const struct sectioncheck* const mismatch,
> +			Elf_Rela *r, Elf_Sym *sym, const char *fromsec);
> +
>  };
>  
>  static const struct sectioncheck sectioncheck[] = {
> @@ -1417,37 +1421,49 @@ static void report_sec_mismatch(const char *modname,
>  	fprintf(stderr, "\n");
>  }
>  
> -static void check_section_mismatch(const char *modname, struct elf_info *elf,
> -				   Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
> +static void default_mismatch_handler(const char *modname, struct elf_info *elf,
> +				     const struct sectioncheck* const mismatch,
> +				     Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
>  {
>  	const char *tosec;
> -	const struct sectioncheck *mismatch;
> +	Elf_Sym *to;
> +	Elf_Sym *from;
> +	const char *tosym;
> +	const char *fromsym;
>  
>  	tosec = sec_name(elf, get_secindex(elf, sym));
> -	mismatch = section_mismatch(fromsec, tosec);
> +	from = find_elf_symbol2(elf, r->r_offset, fromsec);
> +	fromsym = sym_name(elf, from);
> +	to = find_elf_symbol(elf, r->r_addend, sym);
> +	tosym = sym_name(elf, to);
> +
> +	if (!strncmp(fromsym, "reference___initcall",
> +		     sizeof("reference___initcall")-1))
> +		return;
> +
> +	/* check whitelist - we may ignore it */
> +	if (secref_whitelist(mismatch,
> +			     fromsec, fromsym, tosec, tosym)) {
> +		report_sec_mismatch(modname, mismatch,
> +				    fromsec, r->r_offset, fromsym,
> +				    is_function(from), tosec, tosym,
> +				    is_function(to));
> +	}
> +}
> +
> +static void check_section_mismatch(const char *modname, struct elf_info *elf,
> +				   Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
> +{
> +	const char *tosec = sec_name(elf, get_secindex(elf, sym));;
> +	const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
> +
>  	if (mismatch) {
> -		Elf_Sym *to;
> -		Elf_Sym *from;
> -		const char *tosym;
> -		const char *fromsym;
> -
> -		from = find_elf_symbol2(elf, r->r_offset, fromsec);
> -		fromsym = sym_name(elf, from);
> -		to = find_elf_symbol(elf, r->r_addend, sym);
> -		tosym = sym_name(elf, to);
> -
> -		if (!strncmp(fromsym, "reference___initcall",
> -				sizeof("reference___initcall")-1))
> -			return;
> -
> -		/* check whitelist - we may ignore it */
> -		if (secref_whitelist(mismatch,
> -					fromsec, fromsym, tosec, tosym)) {
> -			report_sec_mismatch(modname, mismatch,
> -			   fromsec, r->r_offset, fromsym,
> -			   is_function(from), tosec, tosym,
> -			   is_function(to));
> -		}
> +		if (mismatch->handler)
> +			mismatch->handler(modname, elf,  mismatch,
> +					  r, sym, fromsec);
> +		else
> +			default_mismatch_handler(modname, elf, mismatch,
> +						 r, sym, fromsec);
>  	}
>  }
>  
> -- 
> 2.0.5
> 

  reply	other threads:[~2015-03-18  9:06 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-17 12:39 [PATCH 0/7] Detect future mis-uses of __ex_table section Quentin Casasnovas
2015-03-17 12:39 ` [PATCH 1/7] modpost: add strict white-listing when referencing sections Quentin Casasnovas
2015-03-17 16:25   ` Linus Torvalds
2015-03-18  9:14     ` Quentin Casasnovas
2015-03-20  1:29   ` Rusty Russell
2015-04-13  9:04     ` Quentin Casasnovas
2015-04-13 11:19       ` Rusty Russell
2015-04-13 11:24       ` Rusty Russell
2015-03-17 12:39 ` [PATCH 2/7] modpost: add .sched.text and .kprobes.text to the TEXT_SECTIONS list Quentin Casasnovas
2015-03-18  9:08   ` Quentin Casasnovas
2015-03-17 12:39 ` [PATCH 3/7] modpost: add handler function pointer to sectioncheck Quentin Casasnovas
2015-03-18  9:08   ` Quentin Casasnovas [this message]
2015-03-17 12:39 ` [PATCH 4/7] modpost: factorize symbol pretty print in get_pretty_name() Quentin Casasnovas
2015-03-18  9:08   ` Quentin Casasnovas
2015-03-17 12:40 ` [PATCH 5/7] modpost: mismatch_handler: retrieve tosym information only when needed Quentin Casasnovas
2015-03-18  9:09   ` Quentin Casasnovas
2015-03-17 12:40 ` [PATCH 6/7] scripts: add check_extable.sh script Quentin Casasnovas
2015-03-18  9:09   ` Quentin Casasnovas
2015-03-17 12:40 ` [PATCH 7/7] modpost: handle relocations mismatch in __ex_table Quentin Casasnovas
2015-03-18  9:09   ` Quentin Casasnovas
2015-04-13 11:18   ` Rusty Russell
2015-04-13 13:33     ` Quentin Casasnovas
2015-04-14 12:14   ` Thierry Reding
2015-04-14 12:35     ` Quentin Casasnovas
2015-04-15  3:27       ` Rusty Russell
2015-04-15  8:35         ` Quentin Casasnovas

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=20150318090825.GH19131@chrystal.uk.oracle.com \
    --to=quentin.casasnovas@oracle.com \
    --cc=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=oleg@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®