Skip to content

Commit 191c542

Browse files
Al Viroxjamesmorris
authored andcommitted
mm: collapse security_vm_enough_memory() variants into a single function
Collapse security_vm_enough_memory() variants into a single function. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: James Morris <jmorris@namei.org>
1 parent bbd3656 commit 191c542

8 files changed

Lines changed: 10 additions & 38 deletions

File tree

‎include/linux/security.h‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,7 @@ int security_quotactl(int cmds, int type, int id, struct super_block *sb);
16791679
int security_quota_on(struct dentry *dentry);
16801680
int security_syslog(int type);
16811681
int security_settime(const struct timespec *ts, const struct timezone *tz);
1682-
int security_vm_enough_memory(long pages);
16831682
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages);
1684-
int security_vm_enough_memory_kern(long pages);
16851683
int security_bprm_set_creds(struct linux_binprm *bprm);
16861684
int security_bprm_check(struct linux_binprm *bprm);
16871685
void security_bprm_committing_creds(struct linux_binprm *bprm);
@@ -1902,25 +1900,11 @@ static inline int security_settime(const struct timespec *ts,
19021900
return cap_settime(ts, tz);
19031901
}
19041902

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-
19111903
static inline int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
19121904
{
1913-
WARN_ON(mm == NULL);
19141905
return cap_vm_enough_memory(mm, pages);
19151906
}
19161907

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-
19241908
static inline int security_bprm_set_creds(struct linux_binprm *bprm)
19251909
{
19261910
return cap_bprm_set_creds(bprm);

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
355355
charge = 0;
356356
if (mpnt->vm_flags & VM_ACCOUNT) {
357357
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 */
359359
goto fail_nomem;
360360
charge = len;
361361
}

‎mm/mmap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
12351235
*/
12361236
if (accountable_mapping(file, vm_flags)) {
12371237
charged = len >> PAGE_SHIFT;
1238-
if (security_vm_enough_memory(charged))
1238+
if (security_vm_enough_memory_mm(mm, charged))
12391239
return -ENOMEM;
12401240
vm_flags |= VM_ACCOUNT;
12411241
}
@@ -2169,7 +2169,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
21692169
if (mm->map_count > sysctl_max_map_count)
21702170
return -ENOMEM;
21712171

2172-
if (security_vm_enough_memory(len >> PAGE_SHIFT))
2172+
if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
21732173
return -ENOMEM;
21742174

21752175
/* Can we just expand an old private anonymous mapping? */

‎mm/mprotect.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
168168
if (!(oldflags & (VM_ACCOUNT|VM_WRITE|VM_HUGETLB|
169169
VM_SHARED|VM_NORESERVE))) {
170170
charged = nrpages;
171-
if (security_vm_enough_memory(charged))
171+
if (security_vm_enough_memory_mm(mm, charged))
172172
return -ENOMEM;
173173
newflags |= VM_ACCOUNT;
174174
}

‎mm/mremap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
329329

330330
if (vma->vm_flags & VM_ACCOUNT) {
331331
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))
333333
goto Efault;
334334
*p = charged;
335335
}

‎mm/shmem.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb)
127127
static inline int shmem_acct_size(unsigned long flags, loff_t size)
128128
{
129129
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));
131131
}
132132

133133
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)
145145
static inline int shmem_acct_block(unsigned long flags)
146146
{
147147
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;
149149
}
150150

151151
static inline void shmem_unacct_blocks(unsigned long flags, long pages)

‎mm/swapfile.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
15631563
if (!capable(CAP_SYS_ADMIN))
15641564
return -EPERM;
15651565

1566+
BUG_ON(!current->mm);
1567+
15661568
pathname = getname(specialfile);
15671569
err = PTR_ERR(pathname);
15681570
if (IS_ERR(pathname))
@@ -1590,7 +1592,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
15901592
spin_unlock(&swap_lock);
15911593
goto out_dput;
15921594
}
1593-
if (!security_vm_enough_memory(p->pages))
1595+
if (!security_vm_enough_memory_mm(current->mm, p->pages))
15941596
vm_unacct_memory(p->pages);
15951597
else {
15961598
err = -ENOMEM;

‎security/security.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,25 +187,11 @@ int security_settime(const struct timespec *ts, const struct timezone *tz)
187187
return security_ops->settime(ts, tz);
188188
}
189189

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-
196190
int security_vm_enough_memory_mm(struct mm_struct *mm, long pages)
197191
{
198-
WARN_ON(mm == NULL);
199192
return security_ops->vm_enough_memory(mm, pages);
200193
}
201194

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-
209195
int security_bprm_set_creds(struct linux_binprm *bprm)
210196
{
211197
return security_ops->bprm_set_creds(bprm);

0 commit comments

Comments
 (0)