Files
linux/include/linux
Nico Pache e4a38402c3 oom_kill.c: futex: delay the OOM reaper to allow time for proper futex cleanup
The pthread struct is allocated on PRIVATE|ANONYMOUS memory [1] which
can be targeted by the oom reaper.  This mapping is used to store the
futex robust list head; the kernel does not keep a copy of the robust
list and instead references a userspace address to maintain the
robustness during a process death.

A race can occur between exit_mm and the oom reaper that allows the oom
reaper to free the memory of the futex robust list before the exit path
has handled the futex death:

    CPU1                               CPU2
    --------------------------------------------------------------------
    page_fault
    do_exit "signal"
    wake_oom_reaper
                                        oom_reaper
                                        oom_reap_task_mm (invalidates mm)
    exit_mm
    exit_mm_release
    futex_exit_release
    futex_cleanup
    exit_robust_list
    get_user (EFAULT- can't access memory)

If the get_user EFAULT's, the kernel will be unable to recover the
waiters on the robust_list, leaving userspace mutexes hung indefinitely.

Delay the OOM reaper, allowing more time for the exit path to perform
the futex cleanup.

Reproducer: https://gitlab.com/jsavitz/oom_futex_reproducer

Based on a patch by Michal Hocko.

Link: https://elixir.bootlin.com/glibc/glibc-2.35/source/nptl/allocatestack.c#L370 [1]
Link: https://lkml.kernel.org/r/20220414144042.677008-1-npache@redhat.com
Fixes: 2129258024 ("mm: oom: let oom_reap_task and exit_mmap run concurrently")
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
Signed-off-by: Nico Pache <npache@redhat.com>
Co-developed-by: Joel Savitz <jsavitz@redhat.com>
Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Michal Hocko <mhocko@suse.com>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Herton R. Krzesinski <herton@redhat.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Daniel Bristot de Oliveira <bristot@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Joel Savitz <jsavitz@redhat.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2022-04-21 20:01:10 -07:00
..
2022-02-27 13:38:10 +00:00
2022-03-23 19:58:38 +01:00
2022-02-01 14:25:50 +02:00
2022-01-22 08:33:34 +02:00
2022-01-15 08:47:31 -08:00
2022-03-08 19:39:38 -07:00
2022-03-17 20:17:18 -07:00
2022-03-11 19:15:03 -08:00
2021-09-08 15:32:35 -07:00
2022-03-15 10:32:44 +01:00
2021-12-10 17:10:55 -08:00
2022-02-07 16:35:35 -08:00
2022-02-07 16:35:35 -08:00
2021-12-10 12:51:28 +01:00
2021-08-26 15:32:28 -04:00
2021-07-27 11:00:36 +02:00
2021-09-06 07:20:56 -04:00
2022-03-16 15:13:36 -07:00
2022-01-15 08:47:31 -08:00
2022-02-13 16:50:07 -08:00
2022-04-01 14:40:44 -04:00
2022-04-07 09:43:41 -04:00
2021-07-26 15:09:44 +02:00
2022-01-20 08:52:54 +02:00
2021-07-27 20:11:45 +01:00
2021-07-27 20:11:44 +01:00
2022-03-02 22:44:49 -08:00
2021-08-05 11:46:42 +01:00
2022-02-28 23:26:27 -08:00
2022-03-15 08:23:29 -04:00
2022-02-28 13:25:49 +01:00
2022-02-19 19:23:53 -08:00
2022-02-14 15:43:15 +01:00
2021-10-05 06:54:16 -05:00
2022-02-05 15:20:34 +00:00
2021-07-27 17:05:06 +01:00
2022-04-11 19:18:27 -06:00
2022-03-18 09:47:04 +01:00
2022-01-27 13:53:26 +00:00
2021-09-30 12:46:44 -06:00
2022-03-21 12:57:38 -04:00
2021-07-01 11:06:05 -07:00
2021-12-16 22:22:20 +01:00
2021-08-23 13:19:12 +02:00
2022-04-01 14:40:44 -04:00
2022-02-09 09:24:40 -05:00
2022-02-28 13:45:04 +02:00
2022-01-12 10:14:09 -06:00
2021-11-16 19:07:53 -08:00
2021-09-17 13:52:17 +01:00
2021-09-27 09:27:29 -04:00
2022-03-24 19:06:45 -07:00
2022-04-01 13:45:08 -04:00
2022-02-02 07:49:59 -07:00
2021-09-27 17:00:21 +02:00
2021-07-06 10:37:46 -05:00
2022-02-09 08:04:44 +01:00
2022-02-09 08:04:44 +01:00
2021-10-14 13:29:18 +02:00
2022-04-19 10:19:02 -07:00
2021-08-18 22:08:24 +02:00
2022-01-22 08:33:37 +02:00
2022-01-08 12:43:57 -06:00
2021-11-18 09:36:39 +01:00
2022-01-24 14:45:02 +01:00
2022-03-08 14:33:36 -06:00
2022-03-17 20:16:29 -07:00
2022-03-23 19:58:41 +01:00
2022-02-24 15:04:51 +00:00
2021-08-06 13:41:48 -07:00
2021-08-19 09:02:55 +09:00
2021-11-03 11:41:25 -07:00
2022-02-25 09:36:06 +01:00
2022-04-11 19:18:27 -06:00
2022-02-16 07:49:41 +01:00
2022-03-22 15:57:11 -07:00
2021-11-25 18:35:23 +01:00
2022-01-26 14:54:48 +01:00
2022-01-27 13:53:27 +00:00
2021-10-12 11:41:39 -03:00
2021-12-30 12:13:04 +01:00
2022-03-28 16:53:00 -04:00
2021-08-11 06:44:24 -04:00
2021-12-09 10:49:56 -08:00
2021-10-19 23:44:30 +08:00