mirror of
https://github.com/joel16/android_kernel_sony_msm8994_rework.git
synced 2024-11-27 05:40:41 +00:00
mm: use rlimit helpers
Make sure compiler won't do weird things with limits. E.g. fetching them
twice may return 2 different values after writable limits are implemented.
I.e. either use rlimit helpers added in
3e10e716ab
("resource: add helpers for
fetching rlimits") or ACCESS_ONCE if not applicable.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
06f9d8c2b5
commit
59e99e5b97
@ -1986,7 +1986,7 @@ EXPORT_SYMBOL(iov_iter_single_seg_count);
|
|||||||
inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk)
|
inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, int isblk)
|
||||||
{
|
{
|
||||||
struct inode *inode = file->f_mapping->host;
|
struct inode *inode = file->f_mapping->host;
|
||||||
unsigned long limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
|
unsigned long limit = rlimit(RLIMIT_FSIZE);
|
||||||
|
|
||||||
if (unlikely(*pos < 0))
|
if (unlikely(*pos < 0))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
12
mm/mlock.c
12
mm/mlock.c
@ -25,7 +25,7 @@ int can_do_mlock(void)
|
|||||||
{
|
{
|
||||||
if (capable(CAP_IPC_LOCK))
|
if (capable(CAP_IPC_LOCK))
|
||||||
return 1;
|
return 1;
|
||||||
if (current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur != 0)
|
if (rlimit(RLIMIT_MEMLOCK) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -487,7 +487,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
|
|||||||
locked = len >> PAGE_SHIFT;
|
locked = len >> PAGE_SHIFT;
|
||||||
locked += current->mm->locked_vm;
|
locked += current->mm->locked_vm;
|
||||||
|
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
lock_limit >>= PAGE_SHIFT;
|
lock_limit >>= PAGE_SHIFT;
|
||||||
|
|
||||||
/* check against resource limits */
|
/* check against resource limits */
|
||||||
@ -550,7 +550,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
|
|||||||
|
|
||||||
down_write(¤t->mm->mmap_sem);
|
down_write(¤t->mm->mmap_sem);
|
||||||
|
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
lock_limit >>= PAGE_SHIFT;
|
lock_limit >>= PAGE_SHIFT;
|
||||||
|
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
@ -584,7 +584,7 @@ int user_shm_lock(size_t size, struct user_struct *user)
|
|||||||
int allowed = 0;
|
int allowed = 0;
|
||||||
|
|
||||||
locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
locked = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
if (lock_limit == RLIM_INFINITY)
|
if (lock_limit == RLIM_INFINITY)
|
||||||
allowed = 1;
|
allowed = 1;
|
||||||
lock_limit >>= PAGE_SHIFT;
|
lock_limit >>= PAGE_SHIFT;
|
||||||
@ -618,12 +618,12 @@ int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim,
|
|||||||
|
|
||||||
down_write(&mm->mmap_sem);
|
down_write(&mm->mmap_sem);
|
||||||
|
|
||||||
lim = rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
|
lim = ACCESS_ONCE(rlim[RLIMIT_AS].rlim_cur) >> PAGE_SHIFT;
|
||||||
vm = mm->total_vm + pgsz;
|
vm = mm->total_vm + pgsz;
|
||||||
if (lim < vm)
|
if (lim < vm)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
lim = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
|
lim = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur) >> PAGE_SHIFT;
|
||||||
vm = mm->locked_vm + pgsz;
|
vm = mm->locked_vm + pgsz;
|
||||||
if (lim < vm)
|
if (lim < vm)
|
||||||
goto out;
|
goto out;
|
||||||
|
13
mm/mmap.c
13
mm/mmap.c
@ -265,7 +265,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
|
|||||||
* segment grow beyond its set limit the in case where the limit is
|
* segment grow beyond its set limit the in case where the limit is
|
||||||
* not page aligned -Ram Gupta
|
* not page aligned -Ram Gupta
|
||||||
*/
|
*/
|
||||||
rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
|
rlim = rlimit(RLIMIT_DATA);
|
||||||
if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
|
if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
|
||||||
(mm->end_data - mm->start_data) > rlim)
|
(mm->end_data - mm->start_data) > rlim)
|
||||||
goto out;
|
goto out;
|
||||||
@ -967,7 +967,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
|
|||||||
unsigned long locked, lock_limit;
|
unsigned long locked, lock_limit;
|
||||||
locked = len >> PAGE_SHIFT;
|
locked = len >> PAGE_SHIFT;
|
||||||
locked += mm->locked_vm;
|
locked += mm->locked_vm;
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
lock_limit >>= PAGE_SHIFT;
|
lock_limit >>= PAGE_SHIFT;
|
||||||
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
@ -1594,7 +1594,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* Stack limit test */
|
/* Stack limit test */
|
||||||
if (size > rlim[RLIMIT_STACK].rlim_cur)
|
if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* mlock limit tests */
|
/* mlock limit tests */
|
||||||
@ -1602,7 +1602,8 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
|
|||||||
unsigned long locked;
|
unsigned long locked;
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
locked = mm->locked_vm + grow;
|
locked = mm->locked_vm + grow;
|
||||||
limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
|
limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
|
||||||
|
limit >>= PAGE_SHIFT;
|
||||||
if (locked > limit && !capable(CAP_IPC_LOCK))
|
if (locked > limit && !capable(CAP_IPC_LOCK))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
@ -2067,7 +2068,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
|
|||||||
unsigned long locked, lock_limit;
|
unsigned long locked, lock_limit;
|
||||||
locked = len >> PAGE_SHIFT;
|
locked = len >> PAGE_SHIFT;
|
||||||
locked += mm->locked_vm;
|
locked += mm->locked_vm;
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
lock_limit >>= PAGE_SHIFT;
|
lock_limit >>= PAGE_SHIFT;
|
||||||
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
@ -2281,7 +2282,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
|
|||||||
unsigned long cur = mm->total_vm; /* pages */
|
unsigned long cur = mm->total_vm; /* pages */
|
||||||
unsigned long lim;
|
unsigned long lim;
|
||||||
|
|
||||||
lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
|
lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
|
||||||
|
|
||||||
if (cur + npages > lim)
|
if (cur + npages > lim)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -285,7 +285,7 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
|
|||||||
if (vma->vm_flags & VM_LOCKED) {
|
if (vma->vm_flags & VM_LOCKED) {
|
||||||
unsigned long locked, lock_limit;
|
unsigned long locked, lock_limit;
|
||||||
locked = mm->locked_vm << PAGE_SHIFT;
|
locked = mm->locked_vm << PAGE_SHIFT;
|
||||||
lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
|
lock_limit = rlimit(RLIMIT_MEMLOCK);
|
||||||
locked += new_len - old_len;
|
locked += new_len - old_len;
|
||||||
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
if (locked > lock_limit && !capable(CAP_IPC_LOCK))
|
||||||
goto Eagain;
|
goto Eagain;
|
||||||
|
Loading…
Reference in New Issue
Block a user