Skip to content

Commit 9c59902

Browse files
Cyrill Gorcunovtorvalds
authored andcommitted
mm: introduce check_data_rlimit helper
To eliminate code duplication lets introduce check_data_rlimit helper which we will use in brk() and prctl() syscalls. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Cc: Kees Cook <keescook@chromium.org> Cc: Tejun Heo <tj@kernel.org> Cc: Andrew Vagin <avagin@openvz.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: H. Peter Anvin <hpa@zytor.com> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Cc: Pavel Emelyanov <xemul@parallels.com> Cc: Vasiliy Kulikov <segoon@openwall.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Michael Kerrisk <mtk.manpages@gmail.com> Cc: Julien Tinnes <jln@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6d7ce55 commit 9c59902

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/pfn.h>
1919
#include <linux/bit_spinlock.h>
2020
#include <linux/shrinker.h>
21+
#include <linux/resource.h>
2122

2223
struct mempolicy;
2324
struct anon_vma;
@@ -1780,6 +1781,20 @@ extern struct vm_area_struct *copy_vma(struct vm_area_struct **,
17801781
bool *need_rmap_locks);
17811782
extern void exit_mmap(struct mm_struct *);
17821783

1784+
static inline int check_data_rlimit(unsigned long rlim,
1785+
unsigned long new,
1786+
unsigned long start,
1787+
unsigned long end_data,
1788+
unsigned long start_data)
1789+
{
1790+
if (rlim < RLIM_INFINITY) {
1791+
if (((new - start) + (end_data - start_data)) > rlim)
1792+
return -ENOSPC;
1793+
}
1794+
1795+
return 0;
1796+
}
1797+
17831798
extern int mm_take_all_locks(struct mm_struct *mm);
17841799
extern void mm_drop_all_locks(struct mm_struct *mm);
17851800

0 commit comments

Comments
 (0)