Jason A. Donenfeld
f5ad508340
mm: do not BUG_ON missing brk mapping, because userspace can unmap it
...
The following program will trigger the BUG_ON that this patch removes,
because the user can munmap() mm->brk:
#include <sys/syscall.h>
#include <sys/mman.h>
#include <assert.h>
#include <unistd.h>
static void *brk_now(void)
{
return (void *)syscall(SYS_brk, 0);
}
static void brk_set(void *b)
{
assert(syscall(SYS_brk, b) != -1);
}
int main(int argc, char *argv[])
{
void *b = brk_now();
brk_set(b + 4096);
assert(munmap(b - 4096, 4096 * 2) == 0);
brk_set(b);
return 0;
}
Compile that with musl, since glibc actually uses brk(), and then
execute it, and it'll hit this splat:
kernel BUG at mm/mmap.c:229!
invalid opcode: 0000 [#1 ] PREEMPT SMP
CPU: 12 PID: 1379 Comm: a.out Tainted: G S U 6.1.0-rc7+ #419
RIP: 0010:__do_sys_brk+0x2fc/0x340
Code: 00 00 4c 89 ef e8 04 d3 fe ff eb 9a be 01 00 00 00 4c 89 ff e8 35 e0 fe ff e9 6e ff ff ff 4d 89 a7 20>
RSP: 0018:ffff888140bc7eb0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 00000000007e7000 RCX: ffff8881020fe000
RDX: ffff8881020fe001 RSI: ffff8881955c9b00 RDI: ffff8881955c9b08
RBP: 0000000000000000 R08: ffff8881955c9b00 R09: 00007ffc77844000
R10: 0000000000000000 R11: 0000000000000001 R12: 00000000007e8000
R13: 00000000007e8000 R14: 00000000007e7000 R15: ffff8881020fe000
FS: 0000000000604298(0000) GS:ffff88901f700000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000603fe0 CR3: 000000015ba9a005 CR4: 0000000000770ee0
PKRU: 55555554
Call Trace:
<TASK>
do_syscall_64+0x2b/0x50
entry_SYSCALL_64_after_hwframe+0x46/0xb0
RIP: 0033:0x400678
Code: 10 4c 8d 41 08 4c 89 44 24 10 4c 8b 01 8b 4c 24 08 83 f9 2f 77 0a 4c 8d 4c 24 20 4c 01 c9 eb 05 48 8b>
RSP: 002b:00007ffc77863890 EFLAGS: 00000212 ORIG_RAX: 000000000000000c
RAX: ffffffffffffffda RBX: 000000000040031b RCX: 0000000000400678
RDX: 00000000004006a1 RSI: 00000000007e6000 RDI: 00000000007e7000
RBP: 00007ffc77863900 R08: 0000000000000000 R09: 00000000007e6000
R10: 00007ffc77863930 R11: 0000000000000212 R12: 00007ffc77863978
R13: 00007ffc77863988 R14: 0000000000000000 R15: 0000000000000000
</TASK>
Instead, just return the old brk value if the original mapping has been
removed.
[akpm@linux-foundation.org: fix changelog, per Liam]
Link: https://lkml.kernel.org/r/20221202162724.2009-1-Jason@zx2c4.com
Fixes: 2e7ce7d354f2 ("mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Jann Horn <jannh@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-12-09 18:41:16 -08:00
..
2022-11-30 14:49:41 -08:00
2022-10-16 15:27:07 -07:00
2022-11-22 18:50:44 -08:00
2022-11-08 15:57:24 -08:00
2022-09-11 20:26:02 -07:00
2022-08-02 12:34:03 -04:00
2022-08-28 14:02:45 -07:00
2022-09-11 20:25:50 -07:00
2022-05-13 15:11:26 -07:00
2022-03-22 15:57:09 -07:00
2022-11-30 14:49:41 -08:00
2022-06-27 12:52:53 -07:00
2022-09-26 19:46:26 -07:00
2022-01-15 16:30:28 +02:00
2022-03-22 15:57:11 -07:00
2022-04-26 13:36:25 -07:00
2022-11-22 18:50:44 -08:00
2022-10-10 17:53:04 -07:00
2022-10-03 14:02:53 -07:00
2022-09-26 12:14:34 -07:00
2022-07-17 17:14:27 -07:00
2022-10-12 11:16:58 -07:00
2022-10-12 18:51:51 -07:00
2022-09-26 19:46:05 -07:00
2022-11-08 15:57:23 -08:00
2022-09-11 20:25:53 -07:00
2022-11-08 15:57:23 -08:00
2022-08-08 18:06:43 -07:00
2022-11-30 14:49:40 -08:00
2022-10-03 14:03:05 -07:00
2022-09-26 19:46:16 -07:00
2022-10-03 14:03:30 -07:00
2022-06-27 12:22:31 +01:00
2022-10-10 17:53:04 -07:00
2022-05-27 11:40:49 -07:00
2022-11-30 14:49:42 -08:00
2022-10-28 13:37:22 -07:00
2022-10-03 14:02:53 -07:00
2022-06-16 19:48:31 -07:00
2022-03-23 18:03:08 -07:00
2022-11-30 14:49:40 -08:00
2022-10-03 14:03:36 -07:00
2022-01-15 16:30:27 +02:00
2022-10-03 14:03:04 -07:00
2022-11-22 18:50:42 -08:00
2022-03-05 11:08:32 -08:00
2022-10-03 14:03:04 -07:00
2022-11-08 15:57:22 -08:00
2022-10-28 13:37:22 -07:00
2022-11-30 14:49:40 -08:00
2022-10-20 21:27:21 -07:00
2022-06-16 19:48:30 -07:00
2022-11-08 15:57:23 -08:00
2022-11-22 18:50:43 -08:00
2022-10-28 13:37:22 -07:00
2022-05-13 07:20:09 -07:00
2022-09-26 19:46:27 -07:00
2022-09-26 19:46:09 -07:00
2022-10-03 14:02:43 -07:00
2022-12-09 18:41:16 -08:00
2022-11-30 14:49:42 -08:00
2022-04-21 20:01:10 -07:00
2022-09-26 19:46:09 -07:00
2022-10-12 15:56:46 -07:00
2022-09-26 19:46:28 -07:00
2022-09-26 19:46:25 -07:00
2022-09-26 19:46:26 -07:00
2022-09-26 19:46:29 -07:00
2022-11-22 18:50:44 -08:00
2022-09-11 20:26:01 -07:00
2022-11-22 18:50:41 -08:00
2022-05-19 14:08:54 -07:00
2022-10-03 14:02:52 -07:00
2022-10-28 13:37:22 -07:00
2022-10-03 14:03:03 -07:00
2022-10-03 14:03:27 -07:00
2022-09-26 19:46:05 -07:00
2022-09-26 12:28:07 +02:00
2022-10-10 17:53:04 -07:00
2022-05-13 07:20:18 -07:00
2022-03-08 09:30:46 -05:00
2022-07-17 17:14:47 -07:00
2022-05-13 07:20:05 -07:00
2022-09-03 10:13:13 -07:00
2022-09-20 08:24:38 -06:00
2022-10-10 17:53:04 -07:00
2022-10-03 14:03:05 -07:00
2022-10-03 14:03:36 -07:00
2022-10-28 13:37:23 -07:00
2022-07-29 18:07:13 -07:00
2022-10-03 14:03:07 -07:00
2022-10-10 17:53:04 -07:00
2022-10-16 15:27:07 -07:00
2022-10-10 17:53:04 -07:00
2022-09-29 11:30:55 +02:00
2022-10-11 17:42:55 -06:00
2022-08-08 18:06:42 -07:00
2022-07-03 18:08:49 -07:00
2022-10-03 14:03:36 -07:00
2022-10-03 14:02:46 -07:00
2022-10-03 14:02:51 -07:00
2022-10-03 14:02:45 -07:00
2022-10-03 14:02:51 -07:00
2022-11-22 18:50:44 -08:00
2022-10-03 14:02:45 -07:00
2022-07-01 17:03:38 -07:00
2022-11-08 15:57:23 -08:00
2022-10-10 17:53:04 -07:00
2022-10-03 14:03:20 -07:00
2021-11-06 13:30:40 -07:00
2022-11-30 14:49:41 -08:00
2022-10-10 17:53:04 -07:00
2022-09-26 19:46:09 -07:00
2022-08-02 12:34:03 -04:00
2022-01-15 16:30:31 +02:00
2022-10-20 21:27:21 -07:00
2022-09-11 20:25:50 -07:00