Revert "mm: oom_kill: reap memory of a task that receives SIGKILL"

This reverts commit 97bf2fb571.

Reason to revert: The changes introduced in this commit are
causing an undesirable SELinux denial as a side-effect and
we do not enable the functionality that this commit adds.
Reverting the commit fixes the SELinux denial bug.

Bug: 152624411
Test: boot
Signed-off-by: Martin Liu <liumartin@google.com>
Change-Id: I149b66e6fa0e90e691436e1a83261ff1de233669
Signed-off-by: UtsavBalar1231 <utsavbalar1231@gmail.com>
This commit is contained in:
Martin Liu 2020-06-02 21:22:02 +08:00 committed by spakkkk
parent 739033fd6b
commit b007a800d0
5 changed files with 9 additions and 76 deletions

View File

@ -51,7 +51,6 @@ Currently, these files are in /proc/sys/vm:
- nr_trim_pages (only if CONFIG_MMU=n) - nr_trim_pages (only if CONFIG_MMU=n)
- numa_zonelist_order - numa_zonelist_order
- oom_dump_tasks - oom_dump_tasks
- reap_mem_on_sigkill
- oom_kill_allocating_task - oom_kill_allocating_task
- overcommit_kbytes - overcommit_kbytes
- overcommit_memory - overcommit_memory
@ -656,24 +655,6 @@ The default value is 1 (enabled).
============================================================== ==============================================================
reap_mem_on_sigkill
This enables or disables the memory reaping for a SIGKILL received
process and that the sending process must have the CAP_KILL capabilities.
If this is set to 1, when a process receives SIGKILL from a process
that has the capability, CAP_KILL, the process is added into the oom_reaper
queue which can be picked up by the oom_reaper thread to reap the memory of
that process. This reaps for the process which received SIGKILL through
either sys_kill from user or kill_pid from kernel.
If this is set to 0, we are not reaping memory of a SIGKILL, sent through
either sys_kill from user or kill_pid from kernel, received process.
The default value is 0 (disabled).
==============================================================
oom_kill_allocating_task oom_kill_allocating_task
This enables or disables killing the OOM-triggering task in This enables or disables killing the OOM-triggering task in

View File

@ -120,8 +120,4 @@ extern void dump_tasks(struct mem_cgroup *memcg,
extern int sysctl_oom_dump_tasks; extern int sysctl_oom_dump_tasks;
extern int sysctl_oom_kill_allocating_task; extern int sysctl_oom_kill_allocating_task;
extern int sysctl_panic_on_oom; extern int sysctl_panic_on_oom;
extern int sysctl_reap_mem_on_sigkill;
/* calls for LMK reaper */
extern void add_to_oom_reaper(struct task_struct *p);
#endif /* _INCLUDE_LINUX_OOM_H */ #endif /* _INCLUDE_LINUX_OOM_H */

View File

@ -43,8 +43,6 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/posix-timers.h> #include <linux/posix-timers.h>
#include <linux/livepatch.h> #include <linux/livepatch.h>
#include <linux/oom.h>
#include <linux/capability.h>
#include <linux/cgroup.h> #include <linux/cgroup.h>
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
@ -1387,11 +1385,8 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p,
ret = check_kill_permission(sig, info, p); ret = check_kill_permission(sig, info, p);
rcu_read_unlock(); rcu_read_unlock();
if (!ret && sig) { if (!ret && sig)
ret = do_send_sig_info(sig, info, p, type); ret = do_send_sig_info(sig, info, p, type);
if (capable(CAP_KILL) && sig == SIGKILL)
add_to_oom_reaper(p);
}
return ret; return ret;
} }

View File

@ -1663,13 +1663,6 @@ static struct ctl_table vm_table[] = {
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec, .proc_handler = proc_dointvec,
}, },
{
.procname = "reap_mem_on_sigkill",
.data = &sysctl_reap_mem_on_sigkill,
.maxlen = sizeof(sysctl_reap_mem_on_sigkill),
.mode = 0644,
.proc_handler = proc_dointvec,
},
{ {
.procname = "overcommit_ratio", .procname = "overcommit_ratio",
.data = &sysctl_overcommit_ratio, .data = &sysctl_overcommit_ratio,

View File

@ -54,7 +54,6 @@
int sysctl_panic_on_oom; int sysctl_panic_on_oom;
int sysctl_oom_kill_allocating_task; int sysctl_oom_kill_allocating_task;
int sysctl_oom_dump_tasks = 1; int sysctl_oom_dump_tasks = 1;
int sysctl_reap_mem_on_sigkill;
/* /*
* Serializes oom killer invocations (out_of_memory()) from all contexts to * Serializes oom killer invocations (out_of_memory()) from all contexts to
@ -642,21 +641,13 @@ static int oom_reaper(void *unused)
static void wake_oom_reaper(struct task_struct *tsk) static void wake_oom_reaper(struct task_struct *tsk)
{ {
/*
* Move the lock here to avoid scenario of queuing
* the same task by both OOM killer and any other SIGKILL
* path.
*/
spin_lock(&oom_reaper_lock);
/* mm is already queued? */ /* mm is already queued? */
if (test_and_set_bit(MMF_OOM_REAP_QUEUED, &tsk->signal->oom_mm->flags)) { if (test_and_set_bit(MMF_OOM_REAP_QUEUED, &tsk->signal->oom_mm->flags))
spin_unlock(&oom_reaper_lock);
return; return;
}
get_task_struct(tsk); get_task_struct(tsk);
spin_lock(&oom_reaper_lock);
tsk->oom_reaper_list = oom_reaper_list; tsk->oom_reaper_list = oom_reaper_list;
oom_reaper_list = tsk; oom_reaper_list = tsk;
spin_unlock(&oom_reaper_lock); spin_unlock(&oom_reaper_lock);
@ -676,16 +667,6 @@ static inline void wake_oom_reaper(struct task_struct *tsk)
} }
#endif /* CONFIG_MMU */ #endif /* CONFIG_MMU */
static void __mark_oom_victim(struct task_struct *tsk)
{
struct mm_struct *mm = tsk->mm;
if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) {
mmgrab(tsk->signal->oom_mm);
set_bit(MMF_OOM_VICTIM, &mm->flags);
}
}
/** /**
* mark_oom_victim - mark the given task as OOM victim * mark_oom_victim - mark the given task as OOM victim
* @tsk: task to mark * @tsk: task to mark
@ -698,13 +679,18 @@ static void __mark_oom_victim(struct task_struct *tsk)
*/ */
static void mark_oom_victim(struct task_struct *tsk) static void mark_oom_victim(struct task_struct *tsk)
{ {
struct mm_struct *mm = tsk->mm;
WARN_ON(oom_killer_disabled); WARN_ON(oom_killer_disabled);
/* OOM killer might race with memcg OOM */ /* OOM killer might race with memcg OOM */
if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE)) if (test_and_set_tsk_thread_flag(tsk, TIF_MEMDIE))
return; return;
/* oom_mm is bound to the signal struct life time. */ /* oom_mm is bound to the signal struct life time. */
__mark_oom_victim(tsk); if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) {
mmgrab(tsk->signal->oom_mm);
set_bit(MMF_OOM_VICTIM, &mm->flags);
}
/* /*
* Make sure that the task is woken up from uninterruptible sleep * Make sure that the task is woken up from uninterruptible sleep
@ -1179,21 +1165,3 @@ void pagefault_out_of_memory(void)
if (__ratelimit(&pfoom_rs)) if (__ratelimit(&pfoom_rs))
pr_warn("Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF\n"); pr_warn("Huh VM_FAULT_OOM leaked out to the #PF handler. Retrying PF\n");
} }
void add_to_oom_reaper(struct task_struct *p)
{
if (!sysctl_reap_mem_on_sigkill)
return;
p = find_lock_task_mm(p);
if (!p)
return;
get_task_struct(p);
if (task_will_free_mem(p)) {
__mark_oom_victim(p);
wake_oom_reaper(p);
}
task_unlock(p);
put_task_struct(p);
}