modpost: fix segfault with short symbol names
PATCH 1/1 modpost: fix segfault with short symbol names
memcmp() is wrong here, the symbol name can be shorter than KSYMTAB_PFX or CRC_PFX.
--- scripts/mod/modpost.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
scripts/mod/modpost.c +2 -2
@@ -515,7 +515,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,break ;case SHN_ABS :/* CRC'd symbol */ -if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { crc = (unsigned int ) sym->st_value;sym_update_crc (symname +strlen (CRC_PFX ), mod, crc, export);
@@ -559,7 +559,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,break ;default :/* All exported symbols */ -if (memcmp (symname,KSYMTAB_PFX ,strlen (KSYMTAB_PFX )) ==0 ) { +if (strncmp (symname,KSYMTAB_PFX ,strlen (KSYMTAB_PFX )) ==0 ) {sym_add_exported (symname +strlen (KSYMTAB_PFX ), mod, export); }
Signature · 1 line
1.6.5.3
scripts/mod/modpost.c static void handle_modversions(struct module *mod, struct elf_info *info, · line 518
Quoted 5 lines
memcmp()is wrong here, the symbol name can be shorter thanKSYMTAB_PFXorCRC_PFX.scripts/mod/modpost.c +1
-1-if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) {
This doesn't change anything. In both cases the function will return 0 only if all strlen(CRC_PFX) chars match, and in both cases it can access strlen(CRC_PFX) chars (strncmp() is allowed to access characters after the first \0 just fine).
Segher
Quoted 11 lines · Segher Boessenkool
scripts/mod/modpost.c static void handle_modversions(struct module *mod, struct elf_info *info, · line 518
Quoted 6 lines
memcmp()is wrong here, the symbol name can be shorter thanKSYMTAB_PFX
orCRC_PFX.scripts/mod/modpost.c +1
-1-if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) {This doesn't change anything. In both cases the function will return 0 only if all
strlen(CRC_PFX)chars match, and in both cases it can accessstrlen(CRC_PFX)chars (strncmp()is allowed to access characters after the first \0 just fine).
str(n)cmp is not allowed to access characters past the NUL byte.
Michal
Quoted 12 lines
Quoted 11 lines
scripts/mod/modpost.c static void handle_modversions(struct module *mod, struct elf_info *info, · line 518
Quoted 6 lines
memcmp()is wrong here, the symbol name can be shorter thanKSYMTAB_PFX
orCRC_PFX.scripts/mod/modpost.c +1
-1-if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) {This doesn't change anything. In both cases the function will return 0 only if all
strlen(CRC_PFX)chars match, and in both cases it can accessstrlen(CRC_PFX)chars (strncmp()is allowed to access characters after the first \0 just fine).
Quoted 1 line
str(n)cmp is not allowed to access characters past the NUL byte.
You are wrong. strncmp() _is_ allowed to do that. So this patch doesn't change anything.
Segher
Segher Boessenkool
Acked-byQuoted 13 lines · Segher Boessenkool
Quoted 11 lines
scripts/mod/modpost.c static void handle_modversions(struct module *mod, struct elf_info *info, · line 518
Quoted 6 lines
memcmp()is wrong here, the symbol name can be shorter thanKSYMTAB_PFX
orCRC_PFX.scripts/mod/modpost.c +1
-1-if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) {This doesn't change anything. In both cases the function will return 0 only if all
strlen(CRC_PFX)chars match, and in both cases it can accessstrlen(CRC_PFX)chars (strncmp()is allowed to access characters after the first \0 just fine).
Quoted 1 line
str(n)cmp is not allowed to access characters past the NUL byte.
Let me apologise for the confusion.
strncmp() _can_ access characters past the first NUL byte; and many implementations do so (they do accesses per 32-bit word, for example). But strncmp() behaves as-if it didn't compare anything past the first null character, so for example causing a page fault if the string ends just before the end of a memory page isn't allowed; OTOH, the parameters to memcmp() are required to point to two objects, each at least "len" bytes big.
So the patch fixes a real problem. I'm sorry for being dense.
Segher
Quoted 3 lines · Segher Boessenkool
So the patch fixes a real problem. I'm sorry for being dense.
Thanks :). Rusty, I sent the patch to you because you have some other modpost stuff in the rr tree. But I can add it to the kbuild tree as well if you want.
Michal
Quoted 9 lines · Segher Boessenkool
Quoted 9 lines · Segher Boessenkool
Quoted 7 lines
scripts/mod/modpost.c static void handle_modversions(struct module *mod, struct elf_info *info, · line 518
Quoted 2 lines
scripts/mod/modpost.c +1
-1-if (memcmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) { +if (strncmp (symname,CRC_PFX ,strlen (CRC_PFX )) ==0 ) {This doesn't change anything. In both cases the function will return 0 only if all
strlen(CRC_PFX)chars match, and in both cases it can accessstrlen(CRC_PFX)chars (strncmp()is allowed to access characters after the first \0 just fine).
Quoted 3 lines
Quoted 1 line
str(n)cmp is not allowed to access characters past the NUL byte.
Let me apologise for the confusion.
Mea culpas must be short, to avoid wasting even more time. And they must be at least as absolute as the incorrect assertion was. This helps us lurkers and archive readers flush the crap from their brains.
Your mails used _ for emphasis and "You are wrong.". Ouch. I suggest:
"I am *wrong*. Sorry Michal for the brain fart."
Also, please stop channeling Richard B. Johnson.
Rusty.
Rusty Russell
AppliedQuoted 4 lines · Michal Marek
memcmp()is wrong here, the symbol name can be shorter thanKSYMTAB_PFXorCRC_PFX.Signed-off-by Michal Marek <[email protected]>
Thanks, applied.
Rusty.