Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1201869 > unrolled thread

[PATCH] modpost: abort if a module symbol is too long

Started byTakashi Iwai <tiwai@suse.de>
First post2015-08-06 18:00 +0200
Last post2015-08-07 07:40 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] modpost: abort if a module symbol is too long Takashi Iwai <tiwai@suse.de> - 2015-08-06 18:00 +0200
    Re: [PATCH] modpost: abort if a module symbol is too long Rusty Russell <rusty@rustcorp.com.au> - 2015-08-06 23:30 +0200
      Re: [PATCH] modpost: abort if a module symbol is too long Takashi Iwai <tiwai@suse.de> - 2015-08-07 07:40 +0200

#1201869 — [PATCH] modpost: abort if a module symbol is too long

FromTakashi Iwai <tiwai@suse.de>
Date2015-08-06 18:00 +0200
Subject[PATCH] modpost: abort if a module symbol is too long
Message-ID<pUvKi-57B-11@gated-at.bofh.it>
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.

As of now, MODULE_NAME_LEN is copied in modpost.c.  At best, this
should be read directly from kernel headers.  But including
linux/module.h is too troublesome for now, so just paper over it.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 scripts/mod/modpost.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 12d3db3bd46b..25bda9d2868c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2133,6 +2133,9 @@ static void add_staging_flag(struct buffer *b, const char *name)
 		buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
 }
 
+/* FIXME: better to be included from kernel header */
+#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
+
 /**
  * Record CRCs for unresolved symbols
  **/
@@ -2177,6 +2180,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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1202087

FromRusty Russell <rusty@rustcorp.com.au>
Date2015-08-06 23:30 +0200
Message-ID<pUATD-4f3-1@gated-at.bofh.it>
In reply to#1201869
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.
>
> This patch adds the check of the symbol length in modpost and stops
> the build properly.
>
> As of now, MODULE_NAME_LEN is copied in modpost.c.  At best, this
> should be read directly from kernel headers.  But including
> linux/module.h is too troublesome for now, so just paper over it.
>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
>  scripts/mod/modpost.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 12d3db3bd46b..25bda9d2868c 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -2133,6 +2133,9 @@ static void add_staging_flag(struct buffer *b, const char *name)
>  		buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
>  }
>  
> +/* FIXME: better to be included from kernel header */
> +#define MODULE_NAME_LEN (64 - sizeof(unsigned long))

This isn't quite right, since modpost handles cross-compilation.

#define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))

Should work...

Thanks!
Rusty.

> +
>  /**
>   * Record CRCs for unresolved symbols
>   **/
> @@ -2177,6 +2180,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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1202299

FromTakashi Iwai <tiwai@suse.de>
Date2015-08-07 07:40 +0200
Message-ID<pUIxP-6MV-1@gated-at.bofh.it>
In reply to#1202087
On Thu, 06 Aug 2015 23:09:12 +0200,
Rusty Russell wrote:
> 
> 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.
> >
> > This patch adds the check of the symbol length in modpost and stops
> > the build properly.
> >
> > As of now, MODULE_NAME_LEN is copied in modpost.c.  At best, this
> > should be read directly from kernel headers.  But including
> > linux/module.h is too troublesome for now, so just paper over it.
> >
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> >  scripts/mod/modpost.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index 12d3db3bd46b..25bda9d2868c 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -2133,6 +2133,9 @@ static void add_staging_flag(struct buffer *b, const char *name)
> >  		buf_printf(b, "\nMODULE_INFO(staging, \"Y\");\n");
> >  }
> >  
> > +/* FIXME: better to be included from kernel header */
> > +#define MODULE_NAME_LEN (64 - sizeof(unsigned long))
> 
> This isn't quite right, since modpost handles cross-compilation.
> 
> #define MODULE_NAME_LEN (64 - sizeof(Elf_Addr))
> 
> Should work...

Alright, I'll resubmit with this fix.


Thanks!

Takashi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web