Skip to contentSkip to conversation

objtool: initialize all of struct elf

PATCH Applied Michal Kubecek 3 participants 3 messages Jun 29, 2023 – Jul 10, 2023 objtool

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: initialize all of struct elf

Function elf_open_read() only zero initializes the initial part of allocated struct elf; num_relocs member was recently added outside the zeroed part so that it was left uninitialized, resulting in build failures on some systems.

The partial initialization is a relic of times when struct elf had large hash tables embedded. This is no longer the case so remove the trap and initialize the whole structure instead.

Fixes eb0481bbc4ce ("objtool: Fix reloc_hash size")
---
 tools/objtool/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +1 -1
index d420b5d2e2b6..081befa4674b 100644
@@ -1005,7 +1005,7 @@ struct elf *elf_open_read(const char *name, int flags)
 		perror("malloc");
 		return NULL;
 	}
-	memset(elf, 0, offsetof(struct elf, sections));
+	memset(elf, 0, sizeof(*elf));
 
 	INIT_LIST_HEAD(&elf->sections);
 
Signature · 1 line
2.41.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Michal Kubecek

Function elf_open_read() only zero initializes the initial part of allocated struct elf; num_relocs member was recently added outside the zeroed part so that it was left uninitialized, resulting in build failures on some systems.

The partial initialization is a relic of times when struct elf had large hash tables embedded. This is no longer the case so remove the trap and initialize the whole structure instead.

Fixes eb0481bbc4ce ("objtool: Fix reloc_hash size")
---
 tools/objtool/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +0 -0
index d420b5d2e2b6..081befa4674b 100644

tools/objtool/elf.c struct elf *elf_open_read(const char *name, int flags) · line 1010

Quoted 7 lines
tools/objtool/elf.c +1 -1
@@ -1005,7 +1005,7 @@ struct elf *elf_open_read(const char *name, int flags)
 		perror("malloc");
 		return NULL;
 	}
-	memset(elf, 0, offsetof(struct elf, sections));
+	memset(elf, 0, sizeof(*elf));
 
 	INIT_LIST_HEAD(&elf->sections);

Thanks!

Signature · 1 line
Josh
merge bot Applied
#2 lore raw
In reply to Michal Kubecek
The following commit has been merged into the objtool/urgent branch of tip:

The following commit has been merged into the objtool/urgent branch of tip:

Commit-ID:     9f71fbcde2820f2af4658313e808cf1e579190a4
Gitweb:        https://git.kernel.org/tip/9f71fbcde2820f2af4658313e808cf1e579190a4
Author:        Michal Kubecek <[email protected]>
AuthorDate:    Thu, 29 Jun 2023 12:05:05 +02:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Mon, 10 Jul 2023 09:52:28 +02:00

objtool: initialize all of struct elf

Function elf_open_read() only zero initializes the initial part of allocated struct elf; num_relocs member was recently added outside the zeroed part so that it was left uninitialized, resulting in build failures on some systems.

The partial initialization is a relic of times when struct elf had large hash tables embedded. This is no longer the case so remove the trap and initialize the whole structure instead.

---
 tools/objtool/elf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/objtool/elf.c +1 -1
index d420b5d..081befa 100644
@@ -1005,7 +1005,7 @@ struct elf *elf_open_read(const char *name, int flags)
 		perror("malloc");
 		return NULL;
 	}
-	memset(elf, 0, offsetof(struct elf, sections));
+	memset(elf, 0, sizeof(*elf));
 
 	INIT_LIST_HEAD(&elf->sections);