Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36027604 authored by Magnus Damm's avatar Magnus Damm Committed by Linus Torvalds
Browse files

[PATCH] elf: fix kcore note size calculation



 - Define "CORE" string as CORE_STR in single common place.
 - Include terminating zero in CORE_STR length calculation for elf_buflen.
 - Use roundup(,4) to include alignment in elf_buflen calculation.

[akpm@osdl.org: simplification suggested by Roland]
Signed-off-by: default avatarMagnus Damm <magnus@valinux.co.jp>
Cc: Daniel Jacobowitz <drow@false.org>
Cc: Roland McGrath <roland@redhat.com>
Cc: Jakub Jelinek <jakub@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 584236ac
Loading
Loading
Loading
Loading
+9 −7
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/io.h>


#define CORE_STR "CORE"


static int open_kcore(struct inode * inode, struct file * filp)
static int open_kcore(struct inode * inode, struct file * filp)
{
{
@@ -82,10 +83,11 @@ static size_t get_kcore_size(int *nphdr, size_t *elf_buflen)
	}
	}
	*elf_buflen =	sizeof(struct elfhdr) + 
	*elf_buflen =	sizeof(struct elfhdr) + 
			(*nphdr + 2)*sizeof(struct elf_phdr) + 
			(*nphdr + 2)*sizeof(struct elf_phdr) + 
			3 * (sizeof(struct elf_note) + 4) +
			3 * ((sizeof(struct elf_note)) +
			sizeof(struct elf_prstatus) +
			     roundup(sizeof(CORE_STR), 4)) +
			sizeof(struct elf_prpsinfo) +
			roundup(sizeof(struct elf_prstatus), 4) +
			sizeof(struct task_struct);
			roundup(sizeof(struct elf_prpsinfo), 4) +
			roundup(sizeof(struct task_struct), 4);
	*elf_buflen = PAGE_ALIGN(*elf_buflen);
	*elf_buflen = PAGE_ALIGN(*elf_buflen);
	return size + *elf_buflen;
	return size + *elf_buflen;
}
}
@@ -210,7 +212,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
	nhdr->p_offset	= offset;
	nhdr->p_offset	= offset;


	/* set up the process status */
	/* set up the process status */
	notes[0].name = "CORE";
	notes[0].name = CORE_STR;
	notes[0].type = NT_PRSTATUS;
	notes[0].type = NT_PRSTATUS;
	notes[0].datasz = sizeof(struct elf_prstatus);
	notes[0].datasz = sizeof(struct elf_prstatus);
	notes[0].data = &prstatus;
	notes[0].data = &prstatus;
@@ -221,7 +223,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
	bufp = storenote(&notes[0], bufp);
	bufp = storenote(&notes[0], bufp);


	/* set up the process info */
	/* set up the process info */
	notes[1].name	= "CORE";
	notes[1].name	= CORE_STR;
	notes[1].type	= NT_PRPSINFO;
	notes[1].type	= NT_PRPSINFO;
	notes[1].datasz	= sizeof(struct elf_prpsinfo);
	notes[1].datasz	= sizeof(struct elf_prpsinfo);
	notes[1].data	= &prpsinfo;
	notes[1].data	= &prpsinfo;
@@ -238,7 +240,7 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
	bufp = storenote(&notes[1], bufp);
	bufp = storenote(&notes[1], bufp);


	/* set up the task structure */
	/* set up the task structure */
	notes[2].name	= "CORE";
	notes[2].name	= CORE_STR;
	notes[2].type	= NT_TASKSTRUCT;
	notes[2].type	= NT_TASKSTRUCT;
	notes[2].datasz	= sizeof(struct task_struct);
	notes[2].datasz	= sizeof(struct task_struct);
	notes[2].data	= current;
	notes[2].data	= current;