From 06269f5295e1ab4d6f6cb681824fad9b714f52f7 Mon Sep 17 00:00:00 2001 From: Carlos Galo Date: Mon, 23 Oct 2023 17:20:45 +0000 Subject: [PATCH] ANDROID: mm: Prevent memhealth from crashing in low memory Adding check when allocating memory for new OOM victim node. This is necessary to prevent crashing in low-memory situations, where the allocation is likely to fail. Bug: 244232958 Change-Id: I8ed17501a9a1bec705766b7e3f3bec3e793a4ad5 Signed-off-by: Carlos Galo --- drivers/android/memhealth.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/android/memhealth.c b/drivers/android/memhealth.c index d26b41b13602..e2b9c3e1a5a2 100644 --- a/drivers/android/memhealth.c +++ b/drivers/android/memhealth.c @@ -98,6 +98,11 @@ static int add_oom_victim_to_list(pid_t pid, ktime_t timestamp) * prevent blocking while allocating for the new node */ new_node = kmalloc(sizeof(*new_node), GFP_ATOMIC); + if (!new_node) { + pr_err("memhealth failed to create new oom node for pid %d\n", pid); + ret = -ENOMEM; + goto err_create_oom_node; + } pid_struct = find_get_pid(pid); if (!pid_struct) { @@ -159,6 +164,7 @@ err_get_cred: err_get_task: err_get_pid: kfree(new_node); +err_create_oom_node: return ret; }