All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sheng Yong <shengyong1@huawei.com>
To: mmarek@suse.cz, sam@ravnborg.org
Cc: linux-kbuild@vger.kernel.org
Subject: [PATCH V2] genksyms: fix segmentation fault if `name' is NULL
Date: Sat, 7 Mar 2015 04:08:45 +0000	[thread overview]
Message-ID: <1425701325-165693-1-git-send-email-shengyong1@huawei.com> (raw)

For case where redefines typedef in both .h and .c files, the parser
will get a `name' with value NULL, which leads to segmentation fault
when generating crc32 value in __add_symbol().

if CONFIG_MODVERSIONS is selected, and a kernel module looks like:
==================
/* foo.c */

typedef int (*foo)(int);

int test(void) { return 0; }
EXPORT_SYMBOL(test);

static int __init foo_init(void) { return 0; }
static void __exit foo_exit(void) { return; }
module_init(foo_init);
module_exit(foo_exit);

/* foo.h */
typedef int (*foo)(int);
==================
When compiling, we could get a segmentation fault. We can also reproduce
this error by compiling a userspace program like the following:
==================
/* foo.c */
typedef int (*foo)(int);
int main() { return 0; }

/* foo.h */
typedef int (*foo)(int);

$ $ gcc -E -D__GENKSYMS__ foo.c | ./scripts/genksyms/genksyms
Segmentation fault
==================

So before generating crc32 value, check whether `name' is NULL. If so,
report the location and error message.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
---
 scripts/genksyms/genksyms.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
index 88632df..bedf3ee 100644
--- a/scripts/genksyms/genksyms.c
+++ b/scripts/genksyms/genksyms.c
@@ -238,6 +238,12 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
 			return NULL;
 	}
 
+	if (!name) {
+		print_location();
+		fprintf(stderr, "Unexpected symbol with NULL name\n");
+		return NULL;
+	}
+
 	h = crc32(name) % HASH_BUCKETS;
 	for (sym = symtab[h]; sym; sym = sym->hash_next) {
 		if (map_to_ns(sym->type) == map_to_ns(type) &&
-- 
1.8.3.4


                 reply	other threads:[~2015-03-07  3:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1425701325-165693-1-git-send-email-shengyong1@huawei.com \
    --to=shengyong1@huawei.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=sam@ravnborg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.