diff mbox

modpost: Fix modpost's license checking V3

Message ID 1310626276-4541-1-git-send-email-abogani@kernel.org (mailing list archive)
State New, archived
Headers show

Commit Message

Alessio Igor Bogani July 14, 2011, 6:51 a.m. UTC
The commit f02e8a6 sorts symbols placing each of them in its own elf section.
The sorting and merging into the canonical sections are done by the linker.
Unfortunately modpost to generate Module.symvers file parses vmlinux
(already linked) and all modules object files (which aren't linked yet).
These aren't sanitized by the linker yet. That breaks modpost that can't
detect license properly for modules. This patch makes modpost aware of
the new exported symbols structure.

Thanks to Arnaud Lacombe <lacombar@gmail.com> and Anders Kaseorg
<andersk@ksplice.com> for providing useful suggestions about code.

This work was supported by a hardware donation from the CE Linux Forum.

Reported-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Alessio Igor Bogani <abogani@kernel.org>
---
 scripts/mod/modpost.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

Comments

Rusty Russell July 18, 2011, 11:38 p.m. UTC | #1
On Thu, 14 Jul 2011 08:51:16 +0200, Alessio Igor Bogani <abogani@kernel.org> wrote:
> The commit f02e8a6 sorts symbols placing each of them in its own elf section.
> The sorting and merging into the canonical sections are done by the linker.
> Unfortunately modpost to generate Module.symvers file parses vmlinux
> (already linked) and all modules object files (which aren't linked yet).
> These aren't sanitized by the linker yet. That breaks modpost that can't
> detect license properly for modules. This patch makes modpost aware of
> the new exported symbols structure.
> 
> Thanks to Arnaud Lacombe <lacombar@gmail.com> and Anders Kaseorg
> <andersk@ksplice.com> for providing useful suggestions about code.
> 
> This work was supported by a hardware donation from the CE Linux Forum.

Applied.

Thanks!
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michal Marek July 20, 2011, 3:25 p.m. UTC | #2
On 14.7.2011 08:51, Alessio Igor Bogani wrote:
> The commit f02e8a6 sorts symbols placing each of them in its own elf section.
> The sorting and merging into the canonical sections are done by the linker.
> Unfortunately modpost to generate Module.symvers file parses vmlinux
> (already linked) and all modules object files (which aren't linked yet).
> These aren't sanitized by the linker yet. That breaks modpost that can't
> detect license properly for modules. This patch makes modpost aware of
> the new exported symbols structure.
>
> Thanks to Arnaud Lacombe<lacombar@gmail.com>  and Anders Kaseorg
> <andersk@ksplice.com>  for providing useful suggestions about code.
>
> This work was supported by a hardware donation from the CE Linux Forum.
>
> Reported-by: Jan Beulich<jbeulich@novell.com>
> Signed-off-by: Alessio Igor Bogani<abogani@kernel.org>
> ---
>   scripts/mod/modpost.c |   29 ++++++++++++++++++++++++++++-
>   1 files changed, 28 insertions(+), 1 deletions(-)

Rusty, will you take this patch or should I apply it to kbuild-2.6.git?

Michal


> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 413c536..a509ff8 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -254,6 +254,28 @@ static enum export export_no(const char *s)
>   	return export_unknown;
>   }
>
> +static const char *sec_name(struct elf_info *elf, int secindex);
> +
> +#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
> +
> +static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
> +{
> +	const char *secname = sec_name(elf, sec);
> +
> +	if (strstarts(secname, "___ksymtab+"))
> +		return export_plain;
> +	else if (strstarts(secname, "___ksymtab_unused+"))
> +		return export_unused;
> +	else if (strstarts(secname, "___ksymtab_gpl+"))
> +		return export_gpl;
> +	else if (strstarts(secname, "___ksymtab_unused_gpl+"))
> +		return export_unused_gpl;
> +	else if (strstarts(secname, "___ksymtab_gpl_future+"))
> +		return export_gpl_future;
> +	else
> +		return export_unknown;
> +}
> +
>   static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
>   {
>   	if (sec == elf->export_sec)
> @@ -563,7 +585,12 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
>   			       Elf_Sym *sym, const char *symname)
>   {
>   	unsigned int crc;
> -	enum export export = export_from_sec(info, get_secindex(info, sym));
> +	enum export export;
> +
> +	if (!is_vmlinux(mod->name)&&  strncmp(symname, "__ksymtab", 9) == 0)
> +		export = export_from_secname(info, get_secindex(info, sym));
> +	else
> +		export = export_from_sec(info, get_secindex(info, sym));
>
>   	switch (sym->st_shndx) {
>   	case SHN_COMMON:

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Rusty Russell July 21, 2011, 6:46 a.m. UTC | #3
On Wed, 20 Jul 2011 17:25:18 +0200, Michal Marek <mmarek@suse.cz> wrote:
> On 14.7.2011 08:51, Alessio Igor Bogani wrote:
> > The commit f02e8a6 sorts symbols placing each of them in its own elf section.
> > The sorting and merging into the canonical sections are done by the linker.
> > Unfortunately modpost to generate Module.symvers file parses vmlinux
> > (already linked) and all modules object files (which aren't linked yet).
> > These aren't sanitized by the linker yet. That breaks modpost that can't
> > detect license properly for modules. This patch makes modpost aware of
> > the new exported symbols structure.
> >
> > Thanks to Arnaud Lacombe<lacombar@gmail.com>  and Anders Kaseorg
> > <andersk@ksplice.com>  for providing useful suggestions about code.
> >
> > This work was supported by a hardware donation from the CE Linux Forum.
> >
> > Reported-by: Jan Beulich<jbeulich@novell.com>
> > Signed-off-by: Alessio Igor Bogani<abogani@kernel.org>
> > ---
> >   scripts/mod/modpost.c |   29 ++++++++++++++++++++++++++++-
> >   1 files changed, 28 insertions(+), 1 deletions(-)
> 
> Rusty, will you take this patch or should I apply it to kbuild-2.6.git?

I took it.

Thanks,
Rusty.
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 413c536..a509ff8 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -254,6 +254,28 @@  static enum export export_no(const char *s)
 	return export_unknown;
 }
 
+static const char *sec_name(struct elf_info *elf, int secindex);
+
+#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
+
+static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
+{
+	const char *secname = sec_name(elf, sec);
+
+	if (strstarts(secname, "___ksymtab+"))
+		return export_plain;
+	else if (strstarts(secname, "___ksymtab_unused+"))
+		return export_unused;
+	else if (strstarts(secname, "___ksymtab_gpl+"))
+		return export_gpl;
+	else if (strstarts(secname, "___ksymtab_unused_gpl+"))
+		return export_unused_gpl;
+	else if (strstarts(secname, "___ksymtab_gpl_future+"))
+		return export_gpl_future;
+	else
+		return export_unknown;
+}
+
 static enum export export_from_sec(struct elf_info *elf, unsigned int sec)
 {
 	if (sec == elf->export_sec)
@@ -563,7 +585,12 @@  static void handle_modversions(struct module *mod, struct elf_info *info,
 			       Elf_Sym *sym, const char *symname)
 {
 	unsigned int crc;
-	enum export export = export_from_sec(info, get_secindex(info, sym));
+	enum export export;
+
+	if (!is_vmlinux(mod->name) && strncmp(symname, "__ksymtab", 9) == 0)
+		export = export_from_secname(info, get_secindex(info, sym));
+	else
+		export = export_from_sec(info, get_secindex(info, sym));
 
 	switch (sym->st_shndx) {
 	case SHN_COMMON: