All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] modpost: abort if a module symbol is too long
@ 2015-08-07  6:55 Takashi Iwai
  2015-08-08  5:47 ` Rusty Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Iwai @ 2015-08-07  6:55 UTC (permalink / raw)
  To: Rusty Russell; +Cc: linux-kernel

Module symbols have a limited length, but currently the build system
allows the build finishing even if the driver code contains a too long
symbol name, which eventually overflows the modversion_info[] item.
The compiler may catch at compiling *.mod.c like
  CC      xxx.mod.o
  xxx.mod.c:18:16: warning: initializer-string for array of chars is too long
but it's merely a warning.

This patch adds the check of the symbol length in modpost and stops
the build properly.

Currently MODULE_NAME_LEN is defined in modpost.c instead of referring
to the definition in kernel header because including linux/module.h is
messy and we must cover cross-compilation.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
v1->v2: Fix MODULE_NAME_LEN to use Elf_Addr

 scripts/mod/modpost.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 12d3db3bd46b..d583c98fde31 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2133,6 +2133,11 @@ static void add_staging_flag(struct buffer *b, const char *name)
 		buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
 }
 
+/* In kernel, this size is defined in linux/module.h;
+ * here we use Elf_Addr instead of long for covering cross-compile
+ */
+#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
+
 /**
  * Record CRCs for unresolved symbols
  **/
@@ -2177,6 +2182,12 @@ static int add_versions(struct buffer *b, struct module *mod)
 				s->name, mod->name);
 			continue;
 		}
+		if (strlen(s->name) >= MODULE_NAME_LEN) {
+			merror("too long symbol \"%s\" [%s.ko]\n",
+			       s->name, mod->name);
+			err = 1;
+			break;
+		}
 		buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n",
 			   s->crc, s->name);
 	}
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] modpost: abort if a module symbol is too long
  2015-08-07  6:55 [PATCH v2] modpost: abort if a module symbol is too long Takashi Iwai
@ 2015-08-08  5:47 ` Rusty Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2015-08-08  5:47 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: linux-kernel

Takashi Iwai <tiwai@suse.de> writes:
> Module symbols have a limited length, but currently the build system
> allows the build finishing even if the driver code contains a too long
> symbol name, which eventually overflows the modversion_info[] item.
> The compiler may catch at compiling *.mod.c like
>   CC      xxx.mod.o
>   xxx.mod.c:18:16: warning: initializer-string for array of chars is too long
> but it's merely a warning.

Thanks, applied!

Cheers,
Rusty.

>
> This patch adds the check of the symbol length in modpost and stops
> the build properly.
>
> Currently MODULE_NAME_LEN is defined in modpost.c instead of referring
> to the definition in kernel header because including linux/module.h is
> messy and we must cover cross-compilation.
>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> v1->v2: Fix MODULE_NAME_LEN to use Elf_Addr
>
>  scripts/mod/modpost.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 12d3db3bd46b..d583c98fde31 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -2133,6 +2133,11 @@ static void add_staging_flag(struct buffer *b, const char *name)
>  		buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
>  }
>  
> +/* In kernel, this size is defined in linux/module.h;
> + * here we use Elf_Addr instead of long for covering cross-compile
> + */
> +#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
> +
>  /**
>   * Record CRCs for unresolved symbols
>   **/
> @@ -2177,6 +2182,12 @@ static int add_versions(struct buffer *b, struct module *mod)
>  				s->name, mod->name);
>  			continue;
>  		}
> +		if (strlen(s->name) >= MODULE_NAME_LEN) {
> +			merror("too long symbol \"%s\" [%s.ko]\n",
> +			       s->name, mod->name);
> +			err = 1;
> +			break;
> +		}
>  		buf_printf(b, "\t{ %#8x, __VMLINUX_SYMBOL_STR(%s) },\n",
>  			   s->crc, s->name);
>  	}
> -- 
> 2.5.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-09 20:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-07  6:55 [PATCH v2] modpost: abort if a module symbol is too long Takashi Iwai
2015-08-08  5:47 ` Rusty Russell

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.