Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 252052
b: refs/heads/master
c: 3864601
h: refs/heads/master
v: v3
  • Loading branch information
Jiri Slaby authored and Linus Torvalds committed May 27, 2011
1 parent 0172e5c commit a6fb09a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 83 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 63ab25ebbc50f74550bd8d164a34724b498f6fb9
refs/heads/master: 3864601387cf4196371e3c1897fdffa5228296f9
1 change: 0 additions & 1 deletion trunk/fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include <linux/pid_namespace.h>
#include <linux/module.h>
#include <linux/namei.h>
#include <linux/proc_fs.h>
#include <linux/mount.h>
#include <linux/security.h>
#include <linux/syscalls.h>
Expand Down
51 changes: 0 additions & 51 deletions trunk/fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,57 +1576,6 @@ static const struct file_operations proc_pid_set_comm_operations = {
.release = single_release,
};

/*
* We added or removed a vma mapping the executable. The vmas are only mapped
* during exec and are not mapped with the mmap system call.
* Callers must hold down_write() on the mm's mmap_sem for these
*/
void added_exe_file_vma(struct mm_struct *mm)
{
mm->num_exe_file_vmas++;
}

void removed_exe_file_vma(struct mm_struct *mm)
{
mm->num_exe_file_vmas--;
if ((mm->num_exe_file_vmas == 0) && mm->exe_file){
fput(mm->exe_file);
mm->exe_file = NULL;
}

}

void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
{
if (new_exe_file)
get_file(new_exe_file);
if (mm->exe_file)
fput(mm->exe_file);
mm->exe_file = new_exe_file;
mm->num_exe_file_vmas = 0;
}

struct file *get_mm_exe_file(struct mm_struct *mm)
{
struct file *exe_file;

/* We need mmap_sem to protect against races with removal of
* VM_EXECUTABLE vmas */
down_read(&mm->mmap_sem);
exe_file = mm->exe_file;
if (exe_file)
get_file(exe_file);
up_read(&mm->mmap_sem);
return exe_file;
}

void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm)
{
/* It's safe to write the exe_file pointer without exe_file_lock because
* this is called during fork when the task is not yet in /proc */
newmm->exe_file = get_mm_exe_file(oldmm);
}

static int proc_exe_link(struct inode *inode, struct path *exe_path)
{
struct task_struct *task;
Expand Down
10 changes: 2 additions & 8 deletions trunk/include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1408,17 +1408,11 @@ extern void exit_mmap(struct mm_struct *);
extern int mm_take_all_locks(struct mm_struct *mm);
extern void mm_drop_all_locks(struct mm_struct *mm);

#ifdef CONFIG_PROC_FS
/* From fs/proc/base.c. callers must _not_ hold the mm's exe_file_lock */
extern void added_exe_file_vma(struct mm_struct *mm);
extern void removed_exe_file_vma(struct mm_struct *mm);
#else
static inline void added_exe_file_vma(struct mm_struct *mm)
{}

static inline void removed_exe_file_vma(struct mm_struct *mm)
{}
#endif /* CONFIG_PROC_FS */
extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
extern struct file *get_mm_exe_file(struct mm_struct *mm);

extern int may_expand_vm(struct mm_struct *mm, unsigned long npages);
extern int install_special_mapping(struct mm_struct *mm,
Expand Down
2 changes: 0 additions & 2 deletions trunk/include/linux/mm_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,9 @@ struct mm_struct {
struct task_struct __rcu *owner;
#endif

#ifdef CONFIG_PROC_FS
/* store ref to file /proc/<pid>/exe symlink points to */
struct file *exe_file;
unsigned long num_exe_file_vmas;
#endif
#ifdef CONFIG_MMU_NOTIFIER
struct mmu_notifier_mm *mmu_notifier_mm;
#endif
Expand Down
19 changes: 0 additions & 19 deletions trunk/include/linux/proc_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ extern void proc_net_remove(struct net *net, const char *name);
extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
struct proc_dir_entry *parent);

/* While the {get|set|dup}_mm_exe_file functions are for mm_structs, they are
* only needed to implement /proc/<pid>|self/exe so we define them here. */
extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file);
extern struct file *get_mm_exe_file(struct mm_struct *mm);
extern void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm);

extern struct file *proc_ns_fget(int fd);

#else
Expand Down Expand Up @@ -230,19 +224,6 @@ static inline void pid_ns_release_proc(struct pid_namespace *ns)
{
}

static inline void set_mm_exe_file(struct mm_struct *mm,
struct file *new_exe_file)
{}

static inline struct file *get_mm_exe_file(struct mm_struct *mm)
{
return NULL;
}

static inline void dup_mm_exe_file(struct mm_struct *oldmm,
struct mm_struct *newmm)
{}

static inline struct file *proc_ns_fget(int fd)
{
return ERR_PTR(-EINVAL);
Expand Down
52 changes: 51 additions & 1 deletion trunk/kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#include <linux/taskstats_kern.h>
#include <linux/random.h>
#include <linux/tty.h>
#include <linux/proc_fs.h>
#include <linux/blkdev.h>
#include <linux/fs_struct.h>
#include <linux/magic.h>
Expand Down Expand Up @@ -597,6 +596,57 @@ void mmput(struct mm_struct *mm)
}
EXPORT_SYMBOL_GPL(mmput);

/*
* We added or removed a vma mapping the executable. The vmas are only mapped
* during exec and are not mapped with the mmap system call.
* Callers must hold down_write() on the mm's mmap_sem for these
*/
void added_exe_file_vma(struct mm_struct *mm)
{
mm->num_exe_file_vmas++;
}

void removed_exe_file_vma(struct mm_struct *mm)
{
mm->num_exe_file_vmas--;
if ((mm->num_exe_file_vmas == 0) && mm->exe_file){
fput(mm->exe_file);
mm->exe_file = NULL;
}

}

void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
{
if (new_exe_file)
get_file(new_exe_file);
if (mm->exe_file)
fput(mm->exe_file);
mm->exe_file = new_exe_file;
mm->num_exe_file_vmas = 0;
}

struct file *get_mm_exe_file(struct mm_struct *mm)
{
struct file *exe_file;

/* We need mmap_sem to protect against races with removal of
* VM_EXECUTABLE vmas */
down_read(&mm->mmap_sem);
exe_file = mm->exe_file;
if (exe_file)
get_file(exe_file);
up_read(&mm->mmap_sem);
return exe_file;
}

static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm)
{
/* It's safe to write the exe_file pointer without exe_file_lock because
* this is called during fork when the task is not yet in /proc */
newmm->exe_file = get_mm_exe_file(oldmm);
}

/**
* get_task_mm - acquire a reference to the task's mm
*
Expand Down

0 comments on commit a6fb09a

Please sign in to comment.