* [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx
@ 2020-03-16 12:28 Xiao Yang
2020-03-17 1:04 ` Xiao Yang
0 siblings, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2020-03-16 12:28 UTC (permalink / raw)
To: yamada.masahiro, michal.lkml; +Cc: linux-kbuild, linux-kernel, Xiao Yang
(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
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 <yangx.jy@cn.fujitsu.com>
---
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;
--
2.21.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx
2020-03-16 12:28 [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx Xiao Yang
@ 2020-03-17 1:04 ` Xiao Yang
2020-03-18 9:49 ` Masahiro Yamada
0 siblings, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2020-03-17 1:04 UTC (permalink / raw)
To: yamada.masahiro, michal.lkml; +Cc: Xiao Yang, linux-kbuild, linux-kernel
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<yangx.jy@cn.fujitsu.com>
> ---
> 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;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx
2020-03-17 1:04 ` Xiao Yang
@ 2020-03-18 9:49 ` Masahiro Yamada
2020-03-18 10:08 ` Xiao Yang
0 siblings, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2020-03-18 9:49 UTC (permalink / raw)
To: Xiao Yang
Cc: Michal Marek, Linux Kbuild mailing list, Linux Kernel Mailing List
On Tue, Mar 17, 2020 at 10:05 AM Xiao Yang <yangx.jy@cn.fujitsu.com> wrote:
>
> On 2020/3/16 20:28, Xiao Yang wrote:
Thanks for catching this bug.
> > (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.
Sounds good to me.
> 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
Could you delete this dump?
I'd like to avoid garbling where possible.
> > ...
> > [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")
Strictly speaking, this commit does not introduce any bug.
The CRC bug for MODVERSIONS exists since
56067812d5b0 ("kbuild: modversions: add infrastructure for emitting
relative CRCs")
> > Fixes: 5545322c86d9 ("modpost: refactor namespace_from_kstrtabns() to not hard-code section name")
This commit hash is wrong.
The correct one is
Fixes: e84f9fbbece1 ("modpost: refactor namespace_from_kstrtabns() to
not hard-code section name")
> > Signed-off-by: Xiao Yang<yangx.jy@cn.fujitsu.com>
> > ---
> > 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;
>
>
>
--
Best Regards
Masahiro Yamada
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx
2020-03-18 9:49 ` Masahiro Yamada
@ 2020-03-18 10:08 ` Xiao Yang
0 siblings, 0 replies; 4+ messages in thread
From: Xiao Yang @ 2020-03-18 10:08 UTC (permalink / raw)
To: Masahiro Yamada
Cc: Michal Marek, Linux Kbuild mailing list, Linux Kernel Mailing List
On 2020/3/18 17:49, Masahiro Yamada wrote:
> On Tue, Mar 17, 2020 at 10:05 AM Xiao Yang<yangx.jy@cn.fujitsu.com> wrote:
>>
>> On 2020/3/16 20:28, Xiao Yang wrote:
>
> Thanks for catching this bug.
>
>
>>> (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.
>
>
> Sounds good to me.
>
>
>> 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
>
>
> Could you delete this dump?
> I'd like to avoid garbling where possible.
>
Hi Masahiro,
Sure, it is OK to delete it.
>
>>> ...
>>> [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")
>
> Strictly speaking, this commit does not introduce any bug.
>
> The CRC bug for MODVERSIONS exists since
> 56067812d5b0 ("kbuild: modversions: add infrastructure for emitting
> relative CRCs")
>
Will replace it with your suggested commit.
>
>>> Fixes: 5545322c86d9 ("modpost: refactor namespace_from_kstrtabns() to not hard-code section name")
>
> This commit hash is wrong.
> The correct one is
>
> Fixes: e84f9fbbece1 ("modpost: refactor namespace_from_kstrtabns() to
> not hard-code section name")
>
>
Sorry for the wrong commit hash.
Thanks a lot for your quick review.
I will send v2 patch soon.
Best Regards,
Xiao Yang
>
>
>
>>> Signed-off-by: Xiao Yang<yangx.jy@cn.fujitsu.com>
>>> ---
>>> 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;
>>
>>
>>
>
>
> --
> Best Regards
> Masahiro Yamada
>
>
> .
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-18 10:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 12:28 [PATCH] modpost: Get proper section index by get_secindex() instead of st_shndx Xiao Yang
2020-03-17 1:04 ` Xiao Yang
2020-03-18 9:49 ` Masahiro Yamada
2020-03-18 10:08 ` Xiao Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).