From: mawupeng <mawupeng1@huawei.com>
To: <guohanjun@huawei.com>, <rafael@kernel.org>,
<tony.luck@intel.com>, <bp@alien8.de>, <mchehab@kernel.org>,
<xueshuai@linux.alibaba.com>, <lenb@kernel.org>,
<jonathan.cameron@huawei.com>, <jane.chu@oracle.com>,
<jarkko@kernel.org>, <wangkefeng.wang@huawei.com>
Cc: <mawupeng1@huawei.com>, <linux-kernel@vger.kernel.org>,
<linux-acpi@vger.kernel.org>
Subject: Re: [PATCH] ACPI: APEI: check return value of task_work_add to prevent memory leaks
Date: Tue, 21 Apr 2026 17:18:28 +0800 [thread overview]
Message-ID: <bdf9828c-a6e2-46be-aa39-9d222094d565@huawei.com> (raw)
In-Reply-To: <bb2139ba-a7ff-440c-641f-57229a8389b3@huawei.com>
On 周二 2026-4-21 17:02, Hanjun Guo wrote:
> Hi Wupeng,
>
> On 2026/4/17 14:50, Wupeng Ma wrote:
>> task_work_add() can fail with -ESRCH if the target task is exiting.
>> When it fails, the caller must handle the error and free any allocated
>> resources.
>>
>> ghes_do_memory_failure() allocates a twcb structure from ghes_estatus_pool
>> before calling task_work_add(). If task_work_add() fails, twcb is leaked.
>>
>> This can happen due to a race during task exit:
>>
>> do_exit()
>> exit_mm() # current->mm cleared
>> exit_task_work() # task->task_works = &work_exited
>>
>> ghes_do_memory_failure() checks current->mm before allocating twcb,
>> but exit_task_work() may run before task_work_add() completes. At that
>> point task->task_works == &work_exited, causing task_work_add() to fail.
>
> There are multi places in the kernel to call task_work_add() without
> checking the return value, does this race only cause bug in
> ghes_do_memory_failure()?
Thanks for the review.
We have analyzed all the called functions, and apart from this location, only
binder_deferred_fd_close has a potential resource leak issue upon failure.
>
> Thanks
> Hanjun
next prev parent reply other threads:[~2026-04-21 9:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-17 6:50 [PATCH] ACPI: APEI: check return value of task_work_add to prevent memory leaks Wupeng Ma
2026-04-21 9:02 ` Hanjun Guo
2026-04-21 9:18 ` mawupeng [this message]
2026-04-29 8:16 ` Hanjun Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bdf9828c-a6e2-46be-aa39-9d222094d565@huawei.com \
--to=mawupeng1@huawei.com \
--cc=bp@alien8.de \
--cc=guohanjun@huawei.com \
--cc=jane.chu@oracle.com \
--cc=jarkko@kernel.org \
--cc=jonathan.cameron@huawei.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rafael@kernel.org \
--cc=tony.luck@intel.com \
--cc=wangkefeng.wang@huawei.com \
--cc=xueshuai@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox