lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aD1bozP0l67f_wbs@example.org>
Date: Mon, 2 Jun 2025 10:06:59 +0200
From: Alexey Gladkov <legion@...nel.org>
To: Masahiro Yamada <masahiroy@...nel.org>
Cc: Petr Pavlu <petr.pavlu@...e.com>, Luis Chamberlain <mcgrof@...nel.org>,
	Sami Tolvanen <samitolvanen@...gle.com>,
	Daniel Gomez <da.gomez@...sung.com>,
	Nathan Chancellor <nathan@...nel.org>,
	Nicolas Schier <nicolas.schier@...ux.dev>,
	linux-kernel@...r.kernel.org, linux-modules@...r.kernel.org,
	linux-kbuild@...r.kernel.org
Subject: Re: [PATCH v3 3/6] modpost: Make mod_device_table aliases more unique

On Mon, Jun 02, 2025 at 04:45:36PM +0900, Masahiro Yamada wrote:
> On Tue, May 27, 2025 at 6:08 PM Alexey Gladkov <legion@...nel.org> wrote:
> >
> > In order to avoid symbol conflicts if they appear in the same binary, a
> > more unique alias identifier can be generated.
> 
> Why must this be unique?
> 
> What problem would happen if the same symbol names
> appear in MODULE_DEVICE_TABLE()?

Before these patches this was not a problem as non-unique characters are
in separate object files when the module is compiled separately.

But when the modules are compiled into the kernel, there is a symbol
conflict when linking vmlinuz. We have modules that export multiple device
tables from different object files.

> 
> >
> > Signed-off-by: Alexey Gladkov <legion@...nel.org>
> > Reviewed-by: Petr Pavlu <petr.pavlu@...e.com>
> > ---
> >  include/linux/module.h   | 14 ++++++++++++--
> >  scripts/mod/file2alias.c | 18 ++++++++++++++----
> >  2 files changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/linux/module.h b/include/linux/module.h
> > index 88048561360f..e7506684069d 100644
> > --- a/include/linux/module.h
> > +++ b/include/linux/module.h
> > @@ -249,10 +249,20 @@ struct module_kobject *lookup_or_create_module_kobject(const char *name);
> >  /* What your module does. */
> >  #define MODULE_DESCRIPTION(_description) MODULE_INFO(description, _description)
> >
> > +/* Format: __mod_device_table__<counter>__kmod_<modname>__<type>__<name> */
> > +#define __mod_device_table(type, name) \
> > +       __PASTE(__mod_device_table__,   \
> > +       __PASTE(__COUNTER__,            \
> > +       __PASTE(__,                     \
> > +       __PASTE(__KBUILD_MODNAME,       \
> > +       __PASTE(__,                     \
> > +       __PASTE(type,                   \
> > +       __PASTE(__, name)))))))
> > +
> >  #ifdef MODULE
> >  /* Creates an alias so file2alias.c can find device table. */
> > -#define MODULE_DEVICE_TABLE(type, name)                                        \
> > -extern typeof(name) __mod_device_table__##type##__##name               \
> > +#define MODULE_DEVICE_TABLE(type, name)                        \
> > +extern typeof(name) __mod_device_table(type, name)     \
> >    __attribute__ ((unused, alias(__stringify(name))))
> >  #else  /* !MODULE */
> >  #define MODULE_DEVICE_TABLE(type, name)
> > diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> > index 00586119a25b..dff1799a4c79 100644
> > --- a/scripts/mod/file2alias.c
> > +++ b/scripts/mod/file2alias.c
> > @@ -1476,8 +1476,8 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> >  {
> >         void *symval;
> >         char *zeros = NULL;
> > -       const char *type, *name;
> > -       size_t typelen;
> > +       const char *type, *name, *modname;
> > +       size_t typelen, modnamelen;
> >         static const char *prefix = "__mod_device_table__";
> >
> >         /* We're looking for a section relative symbol */
> > @@ -1488,10 +1488,20 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> >         if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
> >                 return;
> >
> > -       /* All our symbols are of form __mod_device_table__<type>__<name>. */
> > +       /* All our symbols are of form __mod_device_table__<counter>__kmod_<modname>__<type>__<name>. */
> >         if (!strstarts(symname, prefix))
> >                 return;
> > -       type = symname + strlen(prefix);
> > +
> > +       modname = strstr(symname, "__kmod_");
> > +       if (!modname)
> > +               return;
> > +       modname += strlen("__kmod_");
> > +
> > +       type = strstr(modname, "__");
> > +       if (!type)
> > +               return;
> > +       modnamelen = type - modname;
> > +       type += strlen("__");
> >
> >         name = strstr(type, "__");
> >         if (!name)
> > --
> > 2.49.0
> >
> 
> 
> -- 
> Best Regards
> Masahiro Yamada
> 

-- 
Rgrds, legion


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ