From 0b93b90ef77cfce1d153fdd82c7019cbdc4263c4 Mon Sep 17 00:00:00 2001 From: Srinivasarao Pathipati Date: Mon, 8 May 2023 20:08:25 +0530 Subject: [PATCH] msm-sysstats: protect task->files in get_task_unreclaimable_info() Race is observed between task exiting and accessing task's files from get_task_unreclaimable_info(), fix it by locking it. Change-Id: Ie43426696aa09222fdc4bbb2533c8a8fd18a0f7c Signed-off-by: Srinivasarao Pathipati --- kernel/msm_sysstats.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/msm_sysstats.c b/kernel/msm_sysstats.c index c45b9b84325c..b96785d8af7d 100644 --- a/kernel/msm_sysstats.c +++ b/kernel/msm_sysstats.c @@ -188,12 +188,17 @@ static unsigned long get_task_unreclaimable_info(struct task_struct *task) int ret = 0; for_each_thread(task, thread) { + /* task is already locked don't lock/unlock again. */ + if (task != thread) + task_lock(thread); if (unlikely(!group_leader_files)) group_leader_files = task->group_leader->files; files = thread->files; if (files && (group_leader_files != files || thread == task->group_leader)) ret = iterate_fd(files, 0, get_dma_info, &size); + if (task != thread) + task_unlock(thread); if (ret) break; }