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: <06cf88841dfb48d8ba89dd22adcd1db9@AcuMS.aculab.com>
Date:   Wed, 28 Sep 2022 09:53:26 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Masahiro Yamada' <masahiroy@...nel.org>,
        "linux-kbuild@...r.kernel.org" <linux-kbuild@...r.kernel.org>
CC:     "linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-ia64@...r.kernel.org" <linux-ia64@...r.kernel.org>,
        Al Viro <viro@...iv.linux.org.uk>,
        Ard Biesheuvel <ardb@...nel.org>,
        Nicolas Pitre <npitre@...libre.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        "Michal Marek" <michal.lkml@...kovi.net>
Subject: RE: [PATCH v3 6/8] modpost: use null string instead of NULL pointer
 for default namespace

From: Masahiro Yamada
> Sent: 28 September 2022 07:40
> 
> The default namespace is the null string, "".
> 
> When set, the null string "" is converted to NULL:
> 
>   s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
> 
> When printed, the NULL pointer is get back to the null string:
> 
>   sym->namespace ?: ""
> 
> This saves 1 byte memory allocated for "", but loses the readability.

The code size changes are far larger that any data sizes.

> In kernel-space, we strive to save memory, but modpost is a userspace
> tool used to build the kernel. On modern systems, such small piece of
> memory is not a big deal.
> 
> Handle the namespace string as is.
> 
> Signed-off-by: Masahiro Yamada <masahiroy@...nel.org>
> Reviewed-by: Nick Desaulniers <ndesaulniers@...gle.com>
> ---
> 
> (no changes since v1)
> 
>  scripts/mod/modpost.c | 17 +++++++++++------
>  1 file changed, 11 insertions(+), 6 deletions(-)
> 
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 0bb5bbd176b4..29f30558a398 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -297,6 +297,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace)
>  {
>  	struct namespace_list *list;
> 
> +	/*
> +	 * The default namespace is null string "", which is always implicitly
> +	 * contained.
> +	 */
> +	if (!namespace[0])
> +		return true;
> +
>  	list_for_each_entry(list, head, list) {
>  		if (!strcmp(list->namespace, namespace))
>  			return true;
> @@ -366,7 +373,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod,
>  	s = alloc_symbol(name);
>  	s->module = mod;
>  	s->is_gpl_only = gpl_only;
> -	s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL;
> +	s->namespace = NOFAIL(strdup(namespace));
>  	list_add_tail(&s->list, &mod->exported_symbols);
>  	hash_add_symbol(s);
> 
> @@ -1928,8 +1935,7 @@ static void check_exports(struct module *mod)
>  		else
>  			basename = mod->name;
> 
> -		if (exp->namespace &&
> -		    !contains_namespace(&mod->imported_namespaces, exp->namespace)) {
> +		if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) {

Do you still need to optimise/check for the default namespace?

	David

>  			modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
>  				    "module %s uses symbol %s from namespace %s, but does not import it.\n",
>  				    basename, exp->name, exp->namespace);
> @@ -2015,8 +2021,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod)
>  	list_for_each_entry(sym, &mod->exported_symbols, list)
>  		buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n",
>  			   sym->is_func ? "FUNC" : "DATA", sym->name,
> -			   sym->is_gpl_only ? "_gpl" : "",
> -			   sym->namespace ?: "");
> +			   sym->is_gpl_only ? "_gpl" : "", sym->namespace);
> 
>  	if (!modversions)
>  		return;
> @@ -2284,7 +2289,7 @@ static void write_dump(const char *fname)
>  			buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n",
>  				   sym->crc, sym->name, mod->name,
>  				   sym->is_gpl_only ? "_GPL" : "",
> -				   sym->namespace ?: "");
> +				   sym->namespace);
>  		}
>  	}
>  	write_buf(&buf, fname);
> --
> 2.34.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ