lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140320093947.14878.48540.stgit@localhost.localdomain>
Date:	Thu, 20 Mar 2014 15:09:47 +0530
From:	Janani Venkataraman <jananive@...ux.vnet.ibm.com>
To:	linux-kernel@...r.kernel.org
Cc:	amwang@...hat.com, procps@...elists.org, rdunlap@...otime.net,
	james.hogan@...tec.com, aravinda@...ux.vnet.ibm.com, hch@....de,
	mhiramat@...hat.com, jeremy.fitzhardinge@...rix.com,
	xemul@...allels.com, d.hatayama@...fujitsu.com, coreutils@....org,
	kosaki.motohiro@...fujitsu.com, adobriyan@...il.com,
	util-linux@...r.kernel.org, tarundsk@...ux.vnet.ibm.com,
	vapier@...too.org, roland@...k.frob.com, ananth@...ux.vnet.ibm.com,
	gorcunov@...nvz.org, avagin@...nvz.org, oleg@...hat.com,
	eparis@...hat.com, suzuki@...ux.vnet.ibm.com, andi@...stfloor.org,
	tj@...nel.org, akpm@...ux-foundation.org,
	torvalds@...ux-foundation.org
Subject: [PATCH 06/33] Check ELF class

The process to be dumped can be either a 32bit application or a 64 bit
application. We first need to check this and proceed with the dump accordingly.

Signed-off-by: Janani Venkataraman <jananive@...ux.vnet.ibm.com>
---
 src/coredump.c |    5 +++++
 src/coredump.h |    1 +
 src/proc.c     |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/src/coredump.c b/src/coredump.c
index 7a559e2..f9c7176 100644
--- a/src/coredump.c
+++ b/src/coredump.c
@@ -188,6 +188,11 @@ int do_coredump(int pid, char *core_file)
 	if (ret)
 		goto cleanup;
 
+	/* Compat Support */
+	cp.elf_class = ret = get_elf_class(pid, &cp);
+	if (ret == -1)
+		goto cleanup;
+
 cleanup:
 
 	/* Release the threads */
diff --git a/src/coredump.h b/src/coredump.h
index 291e13b..25042f5 100644
--- a/src/coredump.h
+++ b/src/coredump.h
@@ -31,4 +31,5 @@ struct core_proc {
 	int *t_id;			/* Threads_ids of all the threads */
 	struct maps *vmas;		/* VMAs */
 	int phdrs_count;		/* Number of Program headers */
+	int elf_class;			/* Elf class of the process */
 };
diff --git a/src/proc.c b/src/proc.c
index a401aa5..3a4a387 100644
--- a/src/proc.c
+++ b/src/proc.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <coredump.h>
+#include <elf.h>
 
 /* Get Process Stats */
 int get_pid_stat(int pid, struct pid_stat *ps)
@@ -231,3 +232,47 @@ int get_vmas(int pid, struct core_proc *cp)
 	fclose(fin);
 	return 0;
 }
+
+/* Check if its ELF */
+int check_elf_hdr(unsigned char *elf_ident)
+{
+	if (memcmp(elf_ident, ELFMAG, SELFMAG) != 0)
+		return -1;
+
+	return 0;
+}
+
+/* Get ELF Class */
+int get_elf_class(int pid, struct core_proc *cp)
+{
+	FILE *fin;
+	unsigned char elf_magic[EI_NIDENT];
+	char filename[40];
+	int ret;
+
+	snprintf(filename, 40, "/proc/%d/exe", pid);
+	fin = fopen(filename, "r");
+	if (fin == NULL) {
+		status = errno;
+		gencore_log("Failure while fetching the ELF header of the executable from %s.\n", filename);
+		return -1;
+	}
+
+	ret = fread(elf_magic, EI_NIDENT, 1, fin);
+	if (ret != 1) {
+		status = errno;
+		gencore_log("Failure while fetching the ELF header of the executable from %s.\n", filename);
+		fclose(fin);
+		return -1;
+	}
+
+	if (check_elf_hdr(elf_magic)) {
+		status = EINVAL;
+		gencore_log("Process to be dumped is not an ELF.\n");
+		return -1;
+	}
+
+	fclose(fin);
+
+	return elf_magic[EI_CLASS];
+}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ