lkml.org 
[lkml]   [2013]   [Oct]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 11/19] Check if the process is an ELF executable
From
Date
From:Suzuki K. Poulose <suzuki@in.ibm.com>

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@in.ibm.com>
---
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@in.ibm.com>
*/

+#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);


\
 
 \ /
  Last update: 2013-10-04 13:41    [W:0.103 / U:0.260 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site