lkml.org 
[lkml]   [2020]   [Oct]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] mm: optionally disable brk()
Date
The brk() system call allows to change data segment size (heap). This
is mainly used by glibc for memory allocation, but it can use mmap()
and that results in more randomized memory mappings since the heap is
always located at fixed offset to program while mmap()ed memory is
randomized.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
---
init/Kconfig | 15 +++++++++++++++
kernel/sys_ni.c | 2 ++
mm/mmap.c | 2 ++
3 files changed, 19 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index c5ea2e694f6a..53735ac305d8 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1851,6 +1851,20 @@ config SLUB_MEMCG_SYSFS_ON
controlled by slub_memcg_sysfs boot parameter and this
config option determines the parameter's default value.

+config BRK_SYSCALL
+ bool "Enable brk() system call" if EXPERT
+ default y
+ help
+ Enable the brk() system call that allows to change data
+ segment size (heap). This is mainly used by glibc for memory
+ allocation, but it can use mmap() and that results in more
+ randomized memory mappings since the heap is always located
+ at fixed offset to program while mmap()ed memory is
+ randomized.
+
+ If unsure, say Y for maximum compatibility.
+
+if BRK_SYSCALL
config COMPAT_BRK
bool "Disable heap randomization"
default y
@@ -1862,6 +1876,7 @@ config COMPAT_BRK
/proc/sys/kernel/randomize_va_space to 2 or 3.

On non-ancient distros (post-2000 ones) N is usually a safe choice.
+endif # BRK_SYSCALL

choice
prompt "Choose SLAB allocator"
diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c
index 4d59775ea79c..3ffa5c4002e1 100644
--- a/kernel/sys_ni.c
+++ b/kernel/sys_ni.c
@@ -299,6 +299,8 @@ COND_SYSCALL(recvmmsg_time32);
COND_SYSCALL_COMPAT(recvmmsg_time32);
COND_SYSCALL_COMPAT(recvmmsg_time64);

+COND_SYSCALL(brk);
+
/*
* Architecture specific syscalls: see further below
*/
diff --git a/mm/mmap.c b/mm/mmap.c
index 489368f43af1..653be2c8982a 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -188,6 +188,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)

static int do_brk_flags(unsigned long addr, unsigned long request, unsigned long flags,
struct list_head *uf);
+#ifdef CONFIG_BRK_SYSCALL
SYSCALL_DEFINE1(brk, unsigned long, brk)
{
unsigned long retval;
@@ -286,6 +287,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
mmap_write_unlock(mm);
return retval;
}
+#endif

static inline unsigned long vma_compute_gap(struct vm_area_struct *vma)
{
--
2.28.0
\
 
 \ /
  Last update: 2020-10-02 19:20    [W:0.069 / U:3.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site