powerpc: module: fix TOC symbol CRC
PATCH 1/1 powerpc: module: fix TOC symbol CRC
The commit 71ec7c55ed91 introduced the magic symbol ".TOC." for ELFv2 ABI. This symbol is built manually and has no CRC value computed. A zero value is put in the CRC section to avoid modpost complaining about a missing CRC. Unfortunately, this breaks the kernel module loading when the kernel is relocated (kdump case for instance) because of the relocation applied to the kcrctab values.
This patch compute a CRC value for the TOC symbol which will match the one compute by the kernel when it is relocated - aka '0 - relocate_start' done in maybe_relocated called by check_version (module.c).
--- arch/powerpc/kernel/module_64.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
arch/powerpc/kernel/module_64.c +8 -1
@@ -315,8 +315,15 @@ static void dedotify_versions(struct modversion_info *vers,struct modversion_info *end;for (end = (void *)vers + size; vers < end; vers++) -if (vers->name[0 ] =='.' ) +if (vers->name[0 ] =='.' ) {memmove (vers->name, vers->name+1 ,strlen (vers->name)); +/* The TOC symbol has no CRC computed. To avoid CRC +* check failing, we must force it to the expected +* value (see CRC check in module.c). +*/ +if (!strcmp (vers->name,"TOC." )) + vers->crc = -(unsigned long )reloc_start; + } }/* Undefined symbols which refer to .funcname, hack to funcname (or .TOC.) */
Hi Laurent,
Quoted 11 lines
The commit
71ec7c55ed91introduced the magic symbol ".TOC." for ELFv2 ABI. This symbol is built manually and has no CRC value computed. A zero value is put in the CRC section to avoid modpost complaining about a missing CRC. Unfortunately, this breaks the kernel module loading when the kernel is relocated (kdump case for instance) because of the relocation applied to the kcrctab values.This patch compute a CRC value for the TOC symbol which will match the one compute by the kernel when it is relocated - aka '0 -
relocate_start' done inmaybe_relocatedcalled bycheck_version(module.c).
Adding Rusty since he maintains the module loader code.
Anton
Quoted 28 lines
Signed-off-by Laurent Dufour <[email protected]>Cc Anton Blanchard <[email protected]>--- arch/powerpc/kernel/module_64.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)(quoted diff) +0
-0
b/arch/powerpc/kernel/module_64.cindex 077d2ce..a80c933 100644arch/powerpc/kernel/module_64.c +8
-1@@ -315,8 +315,15 @@ static void dedotify_versions(struct modversion_info *vers, struct modversion_info *end;for (end = (void *)vers + size; vers < end; vers++) -if (vers->name[0 ] =='.' ) +if (vers->name[0 ] =='.' ) {memmove (vers->name, vers->name+1 ,strlen (vers->name)); +/* The TOC symbol has no CRC computed. To avoid CRC +* check failing, we must force it to the expected +* value (see CRC check in module.c). +*/ +if (!strcmp (vers->name,"TOC." )) + vers->crc = -(unsigned long )reloc_start; + } }/* Undefined symbols which refer to .funcname, hack to funcname (or .TOC.) */
Quoted 9 lines · Anton Blanchard
Hi Laurent,
Quoted 7 lines
The commit
71ec7c55ed91introduced the magic symbol ".TOC." for ELFv2 ABI. This symbol is built manually and has no CRC value computed. A zero value is put in the CRC section to avoid modpost complaining about a missing CRC. Unfortunately, this breaks the kernel module loading when the kernel is relocated (kdump case for instance) because of the relocation applied to the kcrctab values.
Quoted 6 lines
Quoted 4 lines
This patch compute a CRC value for the TOC symbol which will match the one compute by the kernel when it is relocated - aka '0 -
relocate_start' done inmaybe_relocatedcalled bycheck_version(module.c).Adding Rusty since he maintains the module loader code.
This patch gives me:
arch/powerpc/kernel/module_64.c: In function 'dedotify_versions':arch/powerpc/kernel/module_64.c:325:33: error: 'reloc_start' undeclared (first use in this function) arch/powerpc/kernel/module_64.c:325:33: note: each undeclared identifier is reported only once for each function it appears in
Cheers,
Ben.
Quoted 15 lines · Benjamin Herrenschmidt
Quoted 14 lines · Anton Blanchard
Hi Laurent,
Quoted 11 lines
The commit
71ec7c55ed91introduced the magic symbol ".TOC." for ELFv2 ABI. This symbol is built manually and has no CRC value computed. A zero value is put in the CRC section to avoid modpost complaining about a missing CRC. Unfortunately, this breaks the kernel module loading when the kernel is relocated (kdump case for instance) because of the relocation applied to the kcrctab values.This patch compute a CRC value for the TOC symbol which will match the one compute by the kernel when it is relocated - aka '0 -
relocate_start' done inmaybe_relocatedcalled bycheck_version(module.c).
Quoted 7 lines
Quoted 1 line
Adding Rusty since he maintains the module loader code.
This patch gives me:
arch/powerpc/kernel/module_64.c: In function 'dedotify_versions':arch/powerpc/kernel/module_64.c:325:33: error: 'reloc_start' undeclared (first use in this function)arch/powerpc/kernel/module_64.c:325:33: note: each undeclared identifier is reported only once for each function it appears in
Hi Ben,
My mistake, I forgot to check building the kernel when module version checking is disabled. I'll send a v2 asap.
Cheers,
Laurent.
Quoted 4 lines
Cheers,
Ben.
PATCH v2 1/1 powerpc: module: fix TOC symbol CRC
In reply to Benjamin HerrenschmidtThe commit 71ec7c55ed91 introduced the magic symbol ".TOC." for ELFv2 ABI. This symbol is built manually and has no CRC value computed. A zero value is put in the CRC section to avoid modpost complaining about a missing CRC. Unfortunately, this breaks the kernel module loading when the kernel is relocated (kdump case for instance) because of the relocation applied to the kcrctab values.
This patch compute a CRC value for the TOC symbol which will match the one compute by the kernel when it is relocated - aka '0 - relocate_start' done in maybe_relocated called by check_version (module.c).
Changes in V2:
- fix only when relocation is applied to kcrctab.
--- arch/powerpc/kernel/module_64.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/kernel/module_64.c +10 -1
@@ -315,8 +315,17 @@ static void dedotify_versions(struct modversion_info *vers,struct modversion_info *end;for (end = (void *)vers + size; vers < end; vers++) -if (vers->name[0 ] =='.' ) +if (vers->name[0 ] =='.' ) {memmove (vers->name, vers->name+1 ,strlen (vers->name)); +#ifdef ARCH_RELOCATES_KCRCTAB +/* The TOC symbol has no CRC computed. To avoid CRC +* check failing, we must force it to the expected +* value (see CRC check in module.c). +*/ +if (!strcmp (vers->name,"TOC." )) + vers->crc = -(unsigned long )reloc_start; +#endif + } }/* Undefined symbols which refer to .funcname, hack to funcname (or .TOC.) */