linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: optionally disable brk()
@ 2020-10-02 17:19 Topi Miettinen
  2020-10-02 17:52 ` David Hildenbrand
  0 siblings, 1 reply; 19+ messages in thread
From: Topi Miettinen @ 2020-10-02 17:19 UTC (permalink / raw)
  To: akpm, linux-mm, linux-kernel; +Cc: Topi Miettinen

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



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-11-01 11:41 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-02 17:19 [PATCH] mm: optionally disable brk() Topi Miettinen
2020-10-02 17:52 ` David Hildenbrand
2020-10-02 21:19   ` David Laight
2020-10-02 21:44   ` Topi Miettinen
2020-10-05  6:12     ` Michal Hocko
2020-10-05  8:11       ` Topi Miettinen
2020-10-05  8:22         ` Michal Hocko
2020-10-05  9:03           ` Topi Miettinen
2020-10-05 14:12         ` Jonathan Corbet
2020-10-05 16:14           ` Topi Miettinen
2020-10-05  9:13       ` David Hildenbrand
2020-10-05  9:20         ` Michal Hocko
2020-10-05  9:47         ` Topi Miettinen
2020-10-05  9:55           ` David Hildenbrand
2020-10-05 11:21             ` David Laight
2020-10-05 12:18               ` David Hildenbrand
2020-10-05 12:25                 ` David Laight
2020-10-07  9:43                   ` Topi Miettinen
2020-11-01 11:41                 ` Topi Miettinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).