diff options
-rw-r--r-- | include/linux/security.h | 16 | ||||
-rw-r--r-- | kernel/fork.c | 2 | ||||
-rw-r--r-- | mm/mmap.c | 4 | ||||
-rw-r--r-- | mm/mprotect.c | 2 | ||||
-rw-r--r-- | mm/mremap.c | 2 | ||||
-rw-r--r-- | mm/shmem.c | 4 | ||||
-rw-r--r-- | mm/swapfile.c | 4 | ||||
-rw-r--r-- | security/security.c | 14 |
8 files changed, 10 insertions, 38 deletions
diff --git a/include/linux/security.h b/include/linux/security.h index 8325eddd9ee4..2fefad6d27a0 100644 --- a/include/linux/security.h +++ b/include/linux/security.h | |||
@@ -1679,9 +1679,7 @@ int security_quotactl(int cmds, int type, int id, struct super_block *sb); | |||
1679 | int security_quota_on(struct dentry *dentry); | 1679 | int security_quota_on(struct dentry *dentry); |
1680 | int security_syslog(int type); | 1680 | int security_syslog(int type); |
1681 | int security_settime(const struct timespec *ts, const struct timezone *tz); | 1681 | int security_settime(const struct timespec *ts, const struct timezone *tz); |
1682 | int security_vm_enough_memory(long pages); | ||
1683 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); | 1682 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages); |
1684 | int security_vm_enough_memory_kern(long pages); | ||
1685 | int security_bprm_set_creds(struct linux_binprm *bprm); | 1683 | int security_bprm_set_creds(struct linux_binprm *bprm); |
1686 | int security_bprm_check(struct linux_binprm *bprm); | 1684 | int security_bprm_check(struct linux_binprm *bprm); |
1687 | void security_bprm_committing_creds(struct linux_binprm *bprm); | 1685 | void security_bprm_committing_creds(struct linux_binprm *bprm); |
@@ -1902,25 +1900,11 @@ static inline int security_settime(const struct timespec *ts, | |||
1902 | return cap_settime(ts, tz); | 1900 | return cap_settime(ts, tz); |
1903 | } | 1901 | } |
1904 | 1902 | ||
1905 | static inline int security_vm_enough_memory(long pages) | ||
1906 | { | ||
1907 | WARN_ON(current->mm == NULL); | ||
1908 | return cap_vm_enough_memory(current->mm, pages); | ||
1909 | } | ||
1910 | |||
1911 | static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) | 1903 | static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) |
1912 | { | 1904 | { |
1913 | WARN_ON(mm == NULL); | ||
1914 | return cap_vm_enough_memory(mm, pages); | 1905 | return cap_vm_enough_memory(mm, pages); |
1915 | } | 1906 | } |
1916 | 1907 | ||
1917 | static inline int security_vm_enough_memory_kern(long pages) | ||
1918 | { | ||
1919 | /* If current->mm is a kernel thread then we will pass NULL, | ||
1920 | for this specific case that is fine */ | ||
1921 | return cap_vm_enough_memory(current->mm, pages); | ||
1922 | } | ||
1923 | |||
1924 | static inline int security_bprm_set_creds(struct linux_binprm *bprm) | 1908 | static inline int security_bprm_set_creds(struct linux_binprm *bprm) |
1925 | { | 1909 | { |
1926 | return cap_bprm_set_creds(bprm); | 1910 | return cap_bprm_set_creds(bprm); |
diff --git a/kernel/fork.c b/kernel/fork.c index f0e7781ba9b4..d5ebddf317a9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -355,7 +355,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) | |||
355 | charge = 0; | 355 | charge = 0; |
356 | if (mpnt->vm_flags & VM_ACCOUNT) { | 356 | if (mpnt->vm_flags & VM_ACCOUNT) { |
357 | unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT; | 357 | unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT; |
358 | if (security_vm_enough_memory(len)) | 358 | if (security_vm_enough_memory_mm(oldmm, len)) /* sic */ |
359 | goto fail_nomem; | 359 | goto fail_nomem; |
360 | charge = len; | 360 | charge = len; |
361 | } | 361 | } |
@@ -1235,7 +1235,7 @@ munmap_back: | |||
1235 | */ | 1235 | */ |
1236 | if (accountable_mapping(file, vm_flags)) { | 1236 | if (accountable_mapping(file, vm_flags)) { |
1237 | charged = len >> PAGE_SHIFT; | 1237 | charged = len >> PAGE_SHIFT; |
1238 | if (security_vm_enough_memory(charged)) | 1238 | if (security_vm_enough_memory_mm(mm, charged)) |
1239 | return -ENOMEM; | 1239 | return -ENOMEM; |
1240 | vm_flags |= VM_ACCOUNT; | 1240 | vm_flags |= VM_ACCOUNT; |
1241 | } | 1241 | } |
@@ -2169,7 +2169,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len) | |||
2169 | if (mm->map_count > sysctl_max_map_count) | 2169 | if (mm->map_count > sysctl_max_map_count) |
2170 | return -ENOMEM; | 2170 | return -ENOMEM; |
2171 | 2171 | ||
2172 | if (security_vm_enough_memory(len >> PAGE_SHIFT)) | 2172 | if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT)) |
2173 | return -ENOMEM; | 2173 | return -ENOMEM; |
2174 | 2174 | ||
2175 | /* Can we just expand an old private anonymous mapping? */ | 2175 | /* Can we just expand an old private anonymous mapping? */ |
diff --git a/mm/mprotect.c b/mm/mprotect.c index 5a688a2756be..9599fa2d0e92 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c | |||
@@ -168,7 +168,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, | |||
168 | if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB| | 168 | if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB| |
169 | VM_SHARED|VM_NORESERVE))) { | 169 | VM_SHARED|VM_NORESERVE))) { |
170 | charged = nrpages; | 170 | charged = nrpages; |
171 | if (security_vm_enough_memory(charged)) | 171 | if (security_vm_enough_memory_mm(mm, charged)) |
172 | return -ENOMEM; | 172 | return -ENOMEM; |
173 | newflags |= VM_ACCOUNT; | 173 | newflags |= VM_ACCOUNT; |
174 | } | 174 | } |
diff --git a/mm/mremap.c b/mm/mremap.c index 87bb8393e7d2..db8d983b5a7d 100644 --- a/mm/mremap.c +++ b/mm/mremap.c | |||
@@ -329,7 +329,7 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr, | |||
329 | 329 | ||
330 | if (vma->vm_flags & VM_ACCOUNT) { | 330 | if (vma->vm_flags & VM_ACCOUNT) { |
331 | unsigned long charged = (new_len - old_len) >> PAGE_SHIFT; | 331 | unsigned long charged = (new_len - old_len) >> PAGE_SHIFT; |
332 | if (security_vm_enough_memory(charged)) | 332 | if (security_vm_enough_memory_mm(mm, charged)) |
333 | goto Efault; | 333 | goto Efault; |
334 | *p = charged; | 334 | *p = charged; |
335 | } | 335 | } |
diff --git a/mm/shmem.c b/mm/shmem.c index 269d049294ab..d9c293952755 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -127,7 +127,7 @@ static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb) | |||
127 | static inline int shmem_acct_size(unsigned long flags, loff_t size) | 127 | static inline int shmem_acct_size(unsigned long flags, loff_t size) |
128 | { | 128 | { |
129 | return (flags & VM_NORESERVE) ? | 129 | return (flags & VM_NORESERVE) ? |
130 | 0 : security_vm_enough_memory_kern(VM_ACCT(size)); | 130 | 0 : security_vm_enough_memory_mm(current->mm, VM_ACCT(size)); |
131 | } | 131 | } |
132 | 132 | ||
133 | static inline void shmem_unacct_size(unsigned long flags, loff_t size) | 133 | static inline void shmem_unacct_size(unsigned long flags, loff_t size) |
@@ -145,7 +145,7 @@ static inline void shmem_unacct_size(unsigned long flags, loff_t size) | |||
145 | static inline int shmem_acct_block(unsigned long flags) | 145 | static inline int shmem_acct_block(unsigned long flags) |
146 | { | 146 | { |
147 | return (flags & VM_NORESERVE) ? | 147 | return (flags & VM_NORESERVE) ? |
148 | security_vm_enough_memory_kern(VM_ACCT(PAGE_CACHE_SIZE)) : 0; | 148 | security_vm_enough_memory_mm(current->mm, VM_ACCT(PAGE_CACHE_SIZE)) : 0; |
149 | } | 149 | } |
150 | 150 | ||
151 | static inline void shmem_unacct_blocks(unsigned long flags, long pages) | 151 | static inline void shmem_unacct_blocks(unsigned long flags, long pages) |
diff --git a/mm/swapfile.c b/mm/swapfile.c index d999f090dfda..f0d79296dd55 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -1563,6 +1563,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) | |||
1563 | if (!capable(CAP_SYS_ADMIN)) | 1563 | if (!capable(CAP_SYS_ADMIN)) |
1564 | return -EPERM; | 1564 | return -EPERM; |
1565 | 1565 | ||
1566 | BUG_ON(!current->mm); | ||
1567 | |||
1566 | pathname = getname(specialfile); | 1568 | pathname = getname(specialfile); |
1567 | err = PTR_ERR(pathname); | 1569 | err = PTR_ERR(pathname); |
1568 | if (IS_ERR(pathname)) | 1570 | if (IS_ERR(pathname)) |
@@ -1590,7 +1592,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) | |||
1590 | spin_unlock(&swap_lock); | 1592 | spin_unlock(&swap_lock); |
1591 | goto out_dput; | 1593 | goto out_dput; |
1592 | } | 1594 | } |
1593 | if (!security_vm_enough_memory(p->pages)) | 1595 | if (!security_vm_enough_memory_mm(current->mm, p->pages)) |
1594 | vm_unacct_memory(p->pages); | 1596 | vm_unacct_memory(p->pages); |
1595 | else { | 1597 | else { |
1596 | err = -ENOMEM; | 1598 | err = -ENOMEM; |
diff --git a/security/security.c b/security/security.c index 7d9426bb7442..44177add4713 100644 --- a/security/security.c +++ b/security/security.c | |||
@@ -187,25 +187,11 @@ int security_settime(const struct timespec *ts, const struct timezone *tz) | |||
187 | return security_ops->settime(ts, tz); | 187 | return security_ops->settime(ts, tz); |
188 | } | 188 | } |
189 | 189 | ||
190 | int security_vm_enough_memory(long pages) | ||
191 | { | ||
192 | WARN_ON(current->mm == NULL); | ||
193 | return security_ops->vm_enough_memory(current->mm, pages); | ||
194 | } | ||
195 | |||
196 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) | 190 | int security_vm_enough_memory_mm(struct mm_struct *mm, long pages) |
197 | { | 191 | { |
198 | WARN_ON(mm == NULL); | ||
199 | return security_ops->vm_enough_memory(mm, pages); | 192 | return security_ops->vm_enough_memory(mm, pages); |
200 | } | 193 | } |
201 | 194 | ||
202 | int security_vm_enough_memory_kern(long pages) | ||
203 | { | ||
204 | /* If current->mm is a kernel thread then we will pass NULL, | ||
205 | for this specific case that is fine */ | ||
206 | return security_ops->vm_enough_memory(current->mm, pages); | ||
207 | } | ||
208 | |||
209 | int security_bprm_set_creds(struct linux_binprm *bprm) | 195 | int security_bprm_set_creds(struct linux_binprm *bprm) |
210 | { | 196 | { |
211 | return security_ops->bprm_set_creds(bprm); | 197 | return security_ops->bprm_set_creds(bprm); |