Skip to contentSkip to conversation

Kcore elf note namesz field fix

PATCH In review Vivek Goyal 2 participants 2 messages Sep 5, 2006 – Sep 8, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Kcore elf note namesz field fix

o As per ELF specifications, it looks like that elf note "namesz" field contains the length of "name" including the size of null character. And currently we are filling "namesz" without taking into the consideration the null character size.

o Kexec-tools performs this check deligently hence I ran into the issue while trying to open /proc/kcore in kexec-tools for some info.

---

 fs/proc/kcore.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/kcore.c renamed from fs/proc/kcore.c~kcore-elf-note-namesz-fix +2 -2
diff -puN fs/proc/kcore.c~kcore-elf-note-namesz-fix fs/proc/kcore.c
@@ -100,7 +100,7 @@ static int notesize(struct memelfnote *e
 	int sz;
 
 	sz = sizeof(struct elf_note);
-	sz += roundup(strlen(en->name), 4);
+	sz += roundup((strlen(en->name) + 1), 4);
 	sz += roundup(en->datasz, 4);
 
 	return sz;
@@ -116,7 +116,7 @@ static char *storenote(struct memelfnote
 
 #define DUMP_WRITE(addr,nr) do { memcpy(bufp,addr,nr); bufp += nr; } while(0)
 
-	en.n_namesz = strlen(men->name);
+	en.n_namesz = strlen(men->name) + 1;
 	en.n_descsz = men->datasz;
 	en.n_type = men->type;
 

_

#1 lore raw

[ This is a repost, I mucked up the headers the first time around ]

Quoted 8 lines · Vivek Goyal

o As per ELF specifications, it looks like that elf note "namesz" field contains the length of "name" including the size of null character. And currently we are filling "namesz" without taking into the consideration the null character size.

Quoted 4 lines

o Kexec-tools performs this check deligently hence I ran into the issue while trying to open /proc/kcore in kexec-tools for some info.

That is in keeping with my reading of pages 2-4 and 2-5 of version 1.1 of the specification (is there a later version?)

Acked: Simon Horman <[email protected]>

Quoted 27 lines

---

fs/proc/kcore.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN fs/proc/kcore.c~kcore-elf-note-namesz-fix fs/proc/kcore.c

fs/proc/kcore.c renamed from fs/proc/kcore.c~kcore-elf-note-namesz-fix +2 -2
@@ -100,7 +100,7 @@ static int notesize(struct memelfnote *e
 	int sz;
 
 	sz = sizeof(struct elf_note);
-	sz += roundup(strlen(en->name), 4);
+	sz += roundup((strlen(en->name) + 1), 4);
 	sz += roundup(en->datasz, 4);
 
 	return sz;
@@ -116,7 +116,7 @@ static char *storenote(struct memelfnote
 
 #define DUMP_WRITE(addr,nr) do { memcpy(bufp,addr,nr); bufp += nr; } while(0)
 
-	en.n_namesz = strlen(men->name);
+	en.n_namesz = strlen(men->name) + 1;
 	en.n_descsz = men->datasz;
 	en.n_type = men->type;
 

_