From patchwork Sat Mar 7 04:08:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yong X-Patchwork-Id: 5958581 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B572C9F380 for ; Sat, 7 Mar 2015 03:57:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D98E4202FF for ; Sat, 7 Mar 2015 03:57:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA4B2202F2 for ; Sat, 7 Mar 2015 03:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752172AbbCGD5e (ORCPT ); Fri, 6 Mar 2015 22:57:34 -0500 Received: from szxga01-in.huawei.com ([58.251.152.64]:27707 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752617AbbCGD5d (ORCPT ); Fri, 6 Mar 2015 22:57:33 -0500 Received: from 172.24.2.119 (EHLO szxeml428-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CKK41361; Sat, 07 Mar 2015 11:57:29 +0800 (CST) Received: from linux-4hy3.site (10.107.197.200) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.158.1; Sat, 7 Mar 2015 11:57:18 +0800 From: Sheng Yong To: , CC: Subject: [PATCH V2] genksyms: fix segmentation fault if `name' is NULL Date: Sat, 7 Mar 2015 04:08:45 +0000 Message-ID: <1425701325-165693-1-git-send-email-shengyong1@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 X-Originating-IP: [10.107.197.200] X-CFilter-Loop: Reflected Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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) &&