Skip to content

Commit

Permalink
split cap_mmap_addr() out of cap_file_mmap()
Browse files Browse the repository at this point in the history
... switch callers.

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed May 31, 2012
1 parent cf74d14 commit d007794
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ extern int cap_inode_setxattr(struct dentry *dentry, const char *name,
extern int cap_inode_removexattr(struct dentry *dentry, const char *name);
extern int cap_inode_need_killpriv(struct dentry *dentry);
extern int cap_inode_killpriv(struct dentry *dentry);
extern int cap_mmap_addr(unsigned long addr);
extern int cap_file_mmap(struct file *file, unsigned long reqprot,
unsigned long prot, unsigned long flags,
unsigned long addr, unsigned long addr_only);
Expand Down Expand Up @@ -2187,7 +2188,7 @@ static inline int security_file_mmap(struct file *file, unsigned long reqprot,
unsigned long addr,
unsigned long addr_only)
{
return cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
return cap_mmap_addr(addr);
}

static inline int security_file_mprotect(struct vm_area_struct *vma,
Expand Down
2 changes: 1 addition & 1 deletion security/apparmor/lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ static int apparmor_file_mmap(struct file *file, unsigned long reqprot,
int rc = 0;

/* do DAC check */
rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
rc = cap_mmap_addr(addr);
if (rc || addr_only)
return rc;

Expand Down
32 changes: 23 additions & 9 deletions security/commoncap.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,22 +958,15 @@ int cap_vm_enough_memory(struct mm_struct *mm, long pages)
}

/*
* cap_file_mmap - check if able to map given addr
* @file: unused
* @reqprot: unused
* @prot: unused
* @flags: unused
* cap_mmap_addr - check if able to map given addr
* @addr: address attempting to be mapped
* @addr_only: unused
*
* If the process is attempting to map memory below dac_mmap_min_addr they need
* CAP_SYS_RAWIO. The other parameters to this function are unused by the
* capability security module. Returns 0 if this mapping should be allowed
* -EPERM if not.
*/
int cap_file_mmap(struct file *file, unsigned long reqprot,
unsigned long prot, unsigned long flags,
unsigned long addr, unsigned long addr_only)
int cap_mmap_addr(unsigned long addr)
{
int ret = 0;

Expand All @@ -986,3 +979,24 @@ int cap_file_mmap(struct file *file, unsigned long reqprot,
}
return ret;
}

/*
* cap_file_mmap - check if able to map given addr
* @file: unused
* @reqprot: unused
* @prot: unused
* @flags: unused
* @addr: address attempting to be mapped
* @addr_only: unused
*
* If the process is attempting to map memory below dac_mmap_min_addr they need
* CAP_SYS_RAWIO. The other parameters to this function are unused by the
* capability security module. Returns 0 if this mapping should be allowed
* -EPERM if not.
*/
int cap_file_mmap(struct file *file, unsigned long reqprot,
unsigned long prot, unsigned long flags,
unsigned long addr, unsigned long addr_only)
{
return cap_mmap_addr(addr);
}
2 changes: 1 addition & 1 deletion security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3104,7 +3104,7 @@ static int selinux_file_mmap(struct file *file, unsigned long reqprot,
}

/* do DAC check on address space usage */
rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
rc = cap_mmap_addr(addr);
if (rc || addr_only)
return rc;

Expand Down
2 changes: 1 addition & 1 deletion security/smack/smack_lsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ static int smack_file_mmap(struct file *file,
int rc;

/* do DAC check on address space usage */
rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
rc = cap_mmap_addr(addr);
if (rc || addr_only)
return rc;

Expand Down

0 comments on commit d007794

Please sign in to comment.