Skip to contentSkip to conversation

powerpc: module: fix TOC symbol CRC

PATCH Superseded Laurent Dufour 3 participants 5 messages Jun 17, 2014 – Jun 24, 2014 PowerPC

lore
Share & tools
lore
#0 lore raw

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
index 077d2ce..a80c933 100644
@@ -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.) */
#1 lore raw

Hi Laurent,

Quoted 11 lines

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).

Adding Rusty since he maintains the module loader code.

Anton

Quoted 28 lines
---
 arch/powerpc/kernel/module_64.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/arch/powerpc/kernel/module_64.c index 077d2ce..a80c933 100644

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.) */

#2 lore raw
Quoted 9 lines · Anton Blanchard

Hi Laurent,

Quoted 7 lines

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.

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 in maybe_relocated called by check_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.

#3 lore raw
Quoted 15 lines · Benjamin Herrenschmidt
Quoted 14 lines · Anton Blanchard

Hi Laurent,

Quoted 11 lines

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).

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.

#4 lore raw

PATCH v2 1/1 powerpc: module: fix TOC symbol CRC

In reply to Benjamin Herrenschmidt

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).

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
index 077d2ce..d807ee6 100644
@@ -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.) */