Skip to contentSkip to conversation

modpost: handle relocations mismatch in __ex_table.

bug report Dan Carpenter 3 participants 5 messages Jun 6, 2023 – Jun 12, 2023 Kbuild

lore
Share & tools
lore
#0 lore raw

[ Ancient code warning. - dan ]

Hello Quentin Casasnovas,

The patch 52dc0595d540: "modpost: handle relocations mismatch in __ex_table." from Apr 13, 2015, leads to the following Smatch static checker warning:

	./scripts/mod/modpost.c:1154 is_executable_section()
	warn: array off by one? 'elf->sechdrs[secndx]'

./scripts/mod/modpost.c

    1149 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
    1150 {
    1151         if (secndx > elf->num_sections)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not positive, but I think this should be >=.

    1152                 return false;
    1153 
--> 1154         return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
                                      ^^^^^^

out of bounds read.

    1155 }

regards,
dan carpenter

#1 lore raw
Quoted 12 lines · Dan Carpenter

[ Ancient code warning. - dan ]

Hello Quentin Casasnovas,

The patch 52dc0595d540: "modpost: handle relocations mismatch in __ex_table." from Apr 13, 2015, leads to the following Smatch static checker warning:

        ./scripts/mod/modpost.c:1154 is_executable_section()
        warn: array off by one? 'elf->sechdrs[secndx]'
Quoted 6 lines

./scripts/mod/modpost.c

    1149 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
    1150 {
    1151         if (secndx > elf->num_sections)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm not positive, but I think this should be >=.

Ah, right. This is a bug, and your fix is correct.

Quoted 11 lines
    1152                 return false;
    1153
--> 1154         return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
                                      ^^^^^^

out of bounds read.

    1155 }

regards,
dan carpenter

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw
In reply to Dan Carpenter
Quoted 16 lines · Dan Carpenter

[ Ancient code warning. - dan ]

Hello Quentin Casasnovas,

The patch 52dc0595d540: "modpost: handle relocations mismatch in __ex_table." from Apr 13, 2015, leads to the following Smatch static checker warning:

	./scripts/mod/modpost.c:1154 is_executable_section()
	warn: array off by one? 'elf->sechdrs[secndx]'

./scripts/mod/modpost.c

    1149 static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
    1150 {
    1151         if (secndx > elf->num_sections)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 8 lines

I'm not positive, but I think this should be >=.

    1152                 return false;
    1153 
--> 1154         return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
                                      ^^^^^^

out of bounds read.

Oops, that is embarassing - thanks for catching that!

Have you already prepared a fix or shall I send it over?

Q

Quoted 4 lines
    1155 }

regards,
dan carpenter

#4 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 3 lines · Quentin Casasnovas

Have you already prepared a fix or shall I send it over?

I sent the fix on Thursday and Masahiro Yamada already applied it. I Cc'd you but probably you're like me and respond to email in the order it's recieved?

Indeed, I just cleaned up my mailbox and saw your patch. Thanks for the fix!

Q