public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* [bug report] modpost: handle relocations mismatch in __ex_table.
@ 2023-06-06  8:31 Dan Carpenter
  2023-06-06  9:16 ` Masahiro Yamada
  2023-06-12  9:37 ` Quentin Casasnovas
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-06-06  8:31 UTC (permalink / raw)
  To: quentin.casasnovas, Masahiro Yamada
  Cc: Nathan Chancellor, Nick Desaulniers, Nicolas Schier, linux-kbuild

[ 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug report] modpost: handle relocations mismatch in __ex_table.
  2023-06-06  8:31 [bug report] modpost: handle relocations mismatch in __ex_table Dan Carpenter
@ 2023-06-06  9:16 ` Masahiro Yamada
  2023-06-12  9:37 ` Quentin Casasnovas
  1 sibling, 0 replies; 5+ messages in thread
From: Masahiro Yamada @ 2023-06-06  9:16 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: quentin.casasnovas, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-kbuild

On Tue, Jun 6, 2023 at 5:31 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> [ 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 >=.


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





>
>     1152                 return false;
>     1153
> --> 1154         return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
>                                       ^^^^^^
> out of bounds read.
>
>     1155 }
>
> regards,
> dan carpenter






-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug report] modpost: handle relocations mismatch in __ex_table.
  2023-06-06  8:31 [bug report] modpost: handle relocations mismatch in __ex_table Dan Carpenter
  2023-06-06  9:16 ` Masahiro Yamada
@ 2023-06-12  9:37 ` Quentin Casasnovas
  2023-06-12  9:51   ` Dan Carpenter
  1 sibling, 1 reply; 5+ messages in thread
From: Quentin Casasnovas @ 2023-06-12  9:37 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: quentin.casasnovas, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 1085 bytes --]

On Tue, Jun 06, 2023 at 11:31:00AM +0300, Dan Carpenter wrote:
> [ 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.
> 

Oops, that is embarassing - thanks for catching that!

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

Q


>     1155 }
> 
> regards,
> dan carpenter

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug report] modpost: handle relocations mismatch in __ex_table.
  2023-06-12  9:37 ` Quentin Casasnovas
@ 2023-06-12  9:51   ` Dan Carpenter
  2023-06-12 10:22     ` Quentin Casasnovas
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2023-06-12  9:51 UTC (permalink / raw)
  To: Quentin Casasnovas
  Cc: Masahiro Yamada, Nathan Chancellor, Nick Desaulniers,
	Nicolas Schier, linux-kbuild

On Mon, Jun 12, 2023 at 11:37:00AM +0200, Quentin Casasnovas wrote:
> 
> 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?

https://lore.kernel.org/all/CAK7LNATWmtiQdtvGLYL5b0Pyg4Bnmj0_Hn8xtWLzMJ_1oxkThA@mail.gmail.com/

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug report] modpost: handle relocations mismatch in __ex_table.
  2023-06-12  9:51   ` Dan Carpenter
@ 2023-06-12 10:22     ` Quentin Casasnovas
  0 siblings, 0 replies; 5+ messages in thread
From: Quentin Casasnovas @ 2023-06-12 10:22 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Quentin Casasnovas, Masahiro Yamada, Nathan Chancellor,
	Nick Desaulniers, Nicolas Schier, linux-kbuild

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

On Mon, Jun 12, 2023 at 12:51:40PM +0300, Dan Carpenter wrote:
> On Mon, Jun 12, 2023 at 11:37:00AM +0200, Quentin Casasnovas wrote:
> > 
> > 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-12 10:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06  8:31 [bug report] modpost: handle relocations mismatch in __ex_table Dan Carpenter
2023-06-06  9:16 ` Masahiro Yamada
2023-06-12  9:37 ` Quentin Casasnovas
2023-06-12  9:51   ` Dan Carpenter
2023-06-12 10:22     ` Quentin Casasnovas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox