lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  2 Oct 2020 20:19:21 +0300
From:   Topi Miettinen <toiwoton@...il.com>
To:     akpm@...ux-foundation.org, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Cc:     Topi Miettinen <toiwoton@...il.com>
Subject: [PATCH] mm: optionally disable brk()

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ