lkml.org 
[lkml]   [2008]   [Oct]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] CRED: ptrace_attach() should use the target process\'s mutex
From
Date
Hello.

David Howells wrote:
> Tetsuo Handa wrote:
>
> > Thus, I'm trying to use
> >
> > struct execve_entry {
> > struct list_head list;
> > struct task_struct *task;
> > };
> > ...
>
> It might be better to see about setting a flag in the task_struct. All you
> need is a single bit, and since it's process-local it doesn't need any funny
> locking stuff.

Indeed. If I can use one bit in the task_struct, I don't need to add
security_start_execve() / security_finish_execve() hooks.

Now, I cancel the previous patch and propose this patch.

Thanks.
----------
Subject: Add in_execve flag into task_struct.

This patch allows LSM modules determine whether current process is in an execve
operation or not so that they can behave differently while an execve operation
is in progress.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
fs/compat.c | 4 ++++
fs/exec.c | 4 ++++
include/linux/sched.h | 1 +
3 files changed, 9 insertions(+)

--- linux-2.6.27-rc8-mm1.orig/fs/compat.c
+++ linux-2.6.27-rc8-mm1/fs/compat.c
@@ -1387,6 +1387,8 @@ int compat_do_execve(char * filename,
struct linux_binprm *bprm;
struct file *file;
int retval;
+ struct task_struct *task = current;
+ task->in_execve = 1;

retval = -ENOMEM;
bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
@@ -1443,6 +1445,7 @@ int compat_do_execve(char * filename,
security_bprm_free(bprm);
acct_update_integrals(current);
free_bprm(bprm);
+ task->in_execve = 0;
return retval;
}

@@ -1464,6 +1467,7 @@ out_kfree:
free_bprm(bprm);

out_ret:
+ task->in_execve = 0;
return retval;
}

--- linux-2.6.27-rc8-mm1.orig/fs/exec.c
+++ linux-2.6.27-rc8-mm1/fs/exec.c
@@ -1275,6 +1275,8 @@ int do_execve(char * filename,
struct file *file;
struct files_struct *displaced;
int retval;
+ struct task_struct *task = current;
+ task->in_execve = 1;

retval = unshare_files(&displaced);
if (retval)
@@ -1338,6 +1340,7 @@ int do_execve(char * filename,
free_bprm(bprm);
if (displaced)
put_files_struct(displaced);
+ task->in_execve = 0;
return retval;
}

@@ -1361,6 +1364,7 @@ out_files:
if (displaced)
reset_files_struct(displaced);
out_ret:
+ task->in_execve = 0;
return retval;
}

--- linux-2.6.27-rc8-mm1.orig/include/linux/sched.h
+++ linux-2.6.27-rc8-mm1/include/linux/sched.h
@@ -1088,6 +1088,7 @@ struct task_struct {
/* ??? */
unsigned int personality;
unsigned did_exec:1;
+ unsigned in_execve:1;
pid_t pid;
pid_t tgid;


\
 
 \ /
  Last update: 2008-10-03 06:57    [W:0.351 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site