[PATCH 11/19] Check if the process is an ELF executable
From: Janani Venkataraman
Date: Fri Oct 04 2013 - 06:32:11 EST
From:Suzuki K. Poulose <suzuki@xxxxxxxxxx>
Validate if the process is an ELF exec. This will be later extended to identify
if the task is a native ELF or a compat ELF.
Signed-off-by: Suzuki K. Poulose <suzuki@xxxxxxxxxx>
---
fs/proc/gencore.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/fs/proc/gencore.c b/fs/proc/gencore.c
index 580a8b5..5f56910 100644
--- a/fs/proc/gencore.c
+++ b/fs/proc/gencore.c
@@ -22,6 +22,7 @@
* Suzuki K. Poulose <suzuki@xxxxxxxxxx>
*/
+#include <linux/elf.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
#include "internal.h"
@@ -85,6 +86,29 @@ static int release_gencore(struct inode *inode, struct file *file)
return 0;
}
+ /*
+ * Determine whether the task is an ELF executable.
+ * Returns
+ * < 0 - Non-ELF
+ * 0 - Native ELF Executable
+ */
+static int get_elf_class(struct task_struct *task)
+{
+ struct elfhdr hdr;
+ int ret = 0;
+ ret = kernel_read(task->mm->exe_file, 0, (char*)&hdr, sizeof(hdr));
+ if (ret < 0)
+ return ret;
+
+ /* Verify the ELF magic on the exe_file */
+ if (memcmp(hdr.e_ident, ELFMAG, SELFMAG))
+ return -EINVAL;
+ if (elf_check_arch(&hdr))
+ return 0;
+
+ return -EINVAL;
+}
+
/*
* Validate if the call is valid. We also need to prevent >1 open
* of the same file.
@@ -93,10 +117,15 @@ static int open_gencore(struct inode *inode, struct file *filp)
{
struct task_struct *task = get_proc_task(inode);
struct core_proc *cp;
+ int elf_class;
int ret = 0;
if (!task)
return -ENOENT;
+ elf_class = get_elf_class(task);
+ if (elf_class < 0)
+ return elf_class;
+
mutex_lock(&core_mutex);
cp = get_core_proc(task);
mutex_unlock(&core_mutex);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/