Skip to content

Commit

Permalink
proc: do not allow negative offsets on /proc/<pid>/environ
Browse files Browse the repository at this point in the history
__mem_open() which is called by both /proc/<pid>/environ and
/proc/<pid>/mem ->open() handlers will allow the use of negative offsets.
/proc/<pid>/mem has negative offsets but not /proc/<pid>/environ.

Clean this by moving the 'force FMODE_UNSIGNED_OFFSET flag' to mem_open()
to allow negative offsets only on /proc/<pid>/mem.

Signed-off-by: Djalal Harouni <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Brad Spengler <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
tixxdz authored and torvalds committed Jul 31, 2012
1 parent e8905ec commit bc452b4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fs/proc/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,16 +695,19 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
mmput(mm);
}

/* OK to pass negative loff_t, we can catch out-of-range */
file->f_mode |= FMODE_UNSIGNED_OFFSET;
file->private_data = mm;

return 0;
}

static int mem_open(struct inode *inode, struct file *file)
{
return __mem_open(inode, file, PTRACE_MODE_ATTACH);
int ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);

/* OK to pass negative loff_t, we can catch out-of-range */
file->f_mode |= FMODE_UNSIGNED_OFFSET;

return ret;
}

static ssize_t mem_rw(struct file *file, char __user *buf,
Expand Down

0 comments on commit bc452b4

Please sign in to comment.