patch-2.4.6 linux/fs/proc/base.c
Next file: linux/fs/proc/generic.c
Previous file: linux/fs/proc/array.c
Back to the patch index
Back to the overall index
- Lines: 80
- Date:
Tue Jul 3 08:04:00 2001
- Orig file:
v2.4.5/linux/fs/proc/base.c
- Orig date:
Fri May 4 14:44:06 2001
diff -u --recursive --new-file v2.4.5/linux/fs/proc/base.c linux/fs/proc/base.c
@@ -312,6 +312,13 @@
#define MAY_PTRACE(p) \
(p==current||(p->p_pptr==current&&(p->ptrace & PT_PTRACED)&&p->state==TASK_STOPPED))
+
+static int mem_open(struct inode* inode, struct file* file)
+{
+ file->private_data = (void*)((long)current->self_exec_id);
+ return 0;
+}
+
static ssize_t mem_read(struct file * file, char * buf,
size_t count, loff_t *ppos)
{
@@ -319,6 +326,8 @@
char *page;
unsigned long src = *ppos;
int copied = 0;
+ struct mm_struct *mm;
+
if (!MAY_PTRACE(task))
return -ESRCH;
@@ -327,6 +336,20 @@
if (!page)
return -ENOMEM;
+ task_lock(task);
+ mm = task->mm;
+ if (mm)
+ atomic_inc(&mm->mm_users);
+ task_unlock(task);
+ if (!mm)
+ return 0;
+
+ if (file->private_data != (void*)((long)current->self_exec_id) ) {
+ mmput(mm);
+ return -EIO;
+ }
+
+
while (count > 0) {
int this_len, retval;
@@ -347,6 +370,7 @@
count -= retval;
}
*ppos = src;
+ mmput(mm);
free_page((unsigned long) page);
return copied;
}
@@ -398,6 +422,7 @@
static struct file_operations proc_mem_operations = {
read: mem_read,
write: mem_write,
+ open: mem_open,
};
static struct inode_operations proc_mem_inode_operations = {
@@ -635,15 +660,14 @@
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
inode->i_ino = fake_ino(task->pid, ino);
- inode->u.proc_i.file = NULL;
+ if (!task->pid)
+ goto out_unlock;
+
/*
* grab the reference to task.
*/
- inode->u.proc_i.task = task;
get_task_struct(task);
- if (!task->pid)
- goto out_unlock;
-
+ inode->u.proc_i.task = task;
inode->i_uid = 0;
inode->i_gid = 0;
if (ino == PROC_PID_INO || task->dumpable) {
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)