From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.cn.fujitsu.com ([183.91.158.132]:9749 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387413AbgCQBFD (ORCPT ); Mon, 16 Mar 2020 21:05:03 -0400 Message-ID: <5E702236.8070109@cn.fujitsu.com> Date: Tue, 17 Mar 2020 09:04:54 +0800 From: Xiao Yang MIME-Version: 1.0 Subject: Re: [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx References: <20200316122820.11032-1-yangx.jy@cn.fujitsu.com> In-Reply-To: <20200316122820.11032-1-yangx.jy@cn.fujitsu.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit Sender: linux-kbuild-owner@vger.kernel.org List-ID: To: yamada.masahiro@socionext.com, michal.lkml@markovi.net Cc: Xiao Yang , linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org On 2020/3/16 20:28, Xiao Yang wrote: > (uint16_t) st_shndx is limited to 65535(i.e. SHN_XINDEX) so sym_get_data() gets > wrong section index by st_shndx if object file(e.g. vmlinux.o) has more than Hi, It seems better to say that sym_get_data() gets wrong section index by st_shndx if requested symbol contains extended section index that is more than 65535. Thanks, Xiao Yang > 65535 sessions. In this case, we need to get proper section index by .symtab_shndx > section. > > Module.symvers generated by building kernel with "-ffunction-sections -fdata-sections" > shows the issue(i.e. cannot get 89902 by st_shndx): > ------------------------------------------------------------------- > [root@Fedora-30 linux]# file Module.symvers > Module.symvers: data > [root@Fedora-30 linux]# head -n1 Module.symvers > 0x5caf3011 ipv6_chk_custom_prefix ▒▒▒▒▒▒▒▒ vmlinux EXPORT_SYMBOL > ... > [root@Fedora-30 linux]# readelf -s -W vmlinux.o | grep __kstrtabns_ipv6_chk_custom_prefix > 199174: 0000000000032578 1 OBJECT LOCAL DEFAULT 89902 __kstrtabns_ipv6_chk_custom_prefix > [root@Fedora-30 linux]# readelf -S -W vmlinux.o | grep 89902 > [89902] __ksymtab_strings PROGBITS 0000000000000000 a94e00 0345a2 00 A 0 0 1 > ------------------------------------------------------------------- > > Fixes: afa0459daa7b ("modpost: add a helper to get data pointed by a symbol") > Fixes: 5545322c86d9 ("modpost: refactor namespace_from_kstrtabns() to not hard-code section name") > Signed-off-by: Xiao Yang > --- > scripts/mod/modpost.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index d9418c58a8c0..c1fec8cac257 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -310,7 +310,8 @@ static const char *sec_name(struct elf_info *elf, int secindex) > > static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) > { > - Elf_Shdr *sechdr =&info->sechdrs[sym->st_shndx]; > + unsigned int secindex = get_secindex(info, sym); > + Elf_Shdr *sechdr =&info->sechdrs[secindex]; > unsigned long offset; > > offset = sym->st_value; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F295C0044D for ; Tue, 17 Mar 2020 01:05:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5FCF62051A for ; Tue, 17 Mar 2020 01:05:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387515AbgCQBFE (ORCPT ); Mon, 16 Mar 2020 21:05:04 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:9749 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387413AbgCQBFD (ORCPT ); Mon, 16 Mar 2020 21:05:03 -0400 X-IronPort-AV: E=Sophos;i="5.70,562,1574092800"; d="scan'208";a="86431452" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Mar 2020 09:05:00 +0800 Received: from G08CNEXMBPEKD06.g08.fujitsu.local (unknown [10.167.33.206]) by cn.fujitsu.com (Postfix) with ESMTP id CD3CE50A9967; Tue, 17 Mar 2020 08:54:53 +0800 (CST) Received: from [10.167.220.69] (10.167.220.69) by G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 17 Mar 2020 09:04:56 +0800 Message-ID: <5E702236.8070109@cn.fujitsu.com> Date: Tue, 17 Mar 2020 09:04:54 +0800 From: Xiao Yang User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.2; zh-CN; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: , CC: Xiao Yang , , Subject: Re: [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx References: <20200316122820.11032-1-yangx.jy@cn.fujitsu.com> In-Reply-To: <20200316122820.11032-1-yangx.jy@cn.fujitsu.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.167.220.69] X-ClientProxiedBy: G08CNEXCHPEKD05.g08.fujitsu.local (10.167.33.203) To G08CNEXMBPEKD06.g08.fujitsu.local (10.167.33.206) X-yoursite-MailScanner-ID: CD3CE50A9967.AB563 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/3/16 20:28, Xiao Yang wrote: > (uint16_t) st_shndx is limited to 65535(i.e. SHN_XINDEX) so sym_get_data() gets > wrong section index by st_shndx if object file(e.g. vmlinux.o) has more than Hi, It seems better to say that sym_get_data() gets wrong section index by st_shndx if requested symbol contains extended section index that is more than 65535. Thanks, Xiao Yang > 65535 sessions. In this case, we need to get proper section index by .symtab_shndx > section. > > Module.symvers generated by building kernel with "-ffunction-sections -fdata-sections" > shows the issue(i.e. cannot get 89902 by st_shndx): > ------------------------------------------------------------------- > [root@Fedora-30 linux]# file Module.symvers > Module.symvers: data > [root@Fedora-30 linux]# head -n1 Module.symvers > 0x5caf3011 ipv6_chk_custom_prefix ▒▒▒▒▒▒▒▒ vmlinux EXPORT_SYMBOL > ... > [root@Fedora-30 linux]# readelf -s -W vmlinux.o | grep __kstrtabns_ipv6_chk_custom_prefix > 199174: 0000000000032578 1 OBJECT LOCAL DEFAULT 89902 __kstrtabns_ipv6_chk_custom_prefix > [root@Fedora-30 linux]# readelf -S -W vmlinux.o | grep 89902 > [89902] __ksymtab_strings PROGBITS 0000000000000000 a94e00 0345a2 00 A 0 0 1 > ------------------------------------------------------------------- > > Fixes: afa0459daa7b ("modpost: add a helper to get data pointed by a symbol") > Fixes: 5545322c86d9 ("modpost: refactor namespace_from_kstrtabns() to not hard-code section name") > Signed-off-by: Xiao Yang > --- > scripts/mod/modpost.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c > index d9418c58a8c0..c1fec8cac257 100644 > --- a/scripts/mod/modpost.c > +++ b/scripts/mod/modpost.c > @@ -310,7 +310,8 @@ static const char *sec_name(struct elf_info *elf, int secindex) > > static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym) > { > - Elf_Shdr *sechdr =&info->sechdrs[sym->st_shndx]; > + unsigned int secindex = get_secindex(info, sym); > + Elf_Shdr *sechdr =&info->sechdrs[secindex]; > unsigned long offset; > > offset = sym->st_value;