Linux Trace Kernel
 help / color / mirror / Atom feed
From: Ye Liu <ye.liu@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v3 04/15] mm/memory-failure: convert process iterator to for_each_process_rculock
Date: Fri, 11 Sep 2026 17:51:59 +0800	[thread overview]
Message-ID: <7ae944a6-df67-4a8a-8ece-c34701715c8a@linux.dev> (raw)
In-Reply-To: <20260911081351.A8FE81F00893@smtp.kernel.org>



在 2026/9/11 16:13, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] Potential NULL pointer dereference or Use-After-Free of `folio->mapping` in `collect_procs_file()` due to concurrent truncation.
> --
> 
Unrelated to this patch. I will fix it later.

> commit 788d1f422c3f19026d9e0d86b550c238607720ed
> Author: Ye Liu <liuye@kylinos.cn>
> 
> mm/memory-failure: convert process iterator to for_each_process_rculock
> 
> This commit replaces the manual rcu_read_lock()/rcu_read_unlock() pairs
> combined with for_each_process() loop in mm/memory-failure.c with
> for_each_process_rculock(), which scopes the RCU read lock to the loop body
> via scoped_guard(rcu).
> 
>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
>> index a8b03e2920ba8..7d93deb1f7b3d 100644
>> --- a/mm/memory-failure.c
>> +++ b/mm/memory-failure.c
> [ ... ]
>> @@ -589,9 +587,8 @@ static void collect_procs_file(const struct folio *folio,
>>  	pgoff_t pgoff;
>>  
>>  	i_mmap_lock_read(mapping);
> 
> [Severity: High]
> This is a pre-existing issue, but could this lead to a NULL pointer
> dereference or a use-after-free of mapping due to a race with truncation?
> 
> In memory_failure(), the folio lock is dropped in hwpoison_user_mappings()
> before calling collect_procs(). collect_procs() performs an unlocked check of
> !folio->mapping:
> 
> static void collect_procs(...)
> {
> 	if (!folio->mapping)
> 		return;
> 	...
> 	else
> 		collect_procs_file(folio, page, tokill, force_early);
> }
> 
> If a concurrent truncation removes the folio from the page cache immediately
> after this check, folio->mapping becomes NULL. collect_procs_file() then
> initializes mapping = folio->mapping and calls i_mmap_lock_read(mapping).
> 
> If the compiler performs a second read of folio->mapping, mapping will be
> NULL, crashing the kernel on the semaphore acquisition. If the compiler
> caches the first read, mapping will point to an address_space whose host
> inode may have been concurrently freed, leading to a use-after-free since
> the elevated page refcount does not pin the inode and no RCU read lock is
> held during the blocking i_mmap_lock_read() call.
> 
>> -	rcu_read_lock();
>>  	pgoff = page_pgoff(folio, page);
>> -	for_each_process(tsk) {
>> +	for_each_process_rculock(tsk) {
>>  		struct task_struct *t = task_early_kill(tsk, force_early);
>>  		unsigned long addr;
> 

-- 
Thanks,
Ye Liu


  reply	other threads:[~2026-09-11  9:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11  7:57 [PATCH v3 00/15] sched: introduce for_each_process_rculock and for_each_thread_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 01/15] " Ye Liu
2026-09-11  7:57 ` [PATCH v3 02/15] mm/oom_kill: convert process/thread iterators to for_each_*_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 03/15] mm/ksm: convert process iterator to for_each_process_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 04/15] mm/memory-failure: " Ye Liu
2026-09-11  8:13   ` sashiko-bot
2026-09-11  9:51     ` Ye Liu [this message]
2026-09-11  7:57 ` [PATCH v3 05/15] cpu/hotplug: convert thread iterator to for_each_thread_rculock Ye Liu
2026-09-11  8:11   ` sashiko-bot
2026-09-11  9:55     ` Ye Liu
2026-09-11  7:57 ` [PATCH v3 06/15] freezer: " Ye Liu
2026-09-11  7:57 ` [PATCH v3 07/15] hung_task: convert process/thread iterators to for_each_*_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 08/15] locking/lockdep: " Ye Liu
2026-09-11  7:57 ` [PATCH v3 09/15] rcu: convert process/thread iterator to for_each_process_thread_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 10/15] sched: convert process/thread iterators to for_each_*_rculock Ye Liu
2026-09-11  7:57 ` [PATCH v3 11/15] tracing/fgraph: convert process/thread iterator to for_each_process_thread_rculock Ye Liu
2026-09-11  8:10   ` sashiko-bot
2026-09-11 12:59   ` Steven Rostedt
2026-09-11  7:57 ` [PATCH v3 12/15] unwind: " Ye Liu
2026-09-11 12:57   ` Steven Rostedt
2026-09-11  7:57 ` [PATCH v3 13/15] fs: convert process/thread iterators to for_each_*_rculock Ye Liu
2026-09-11  8:15   ` sashiko-bot
2026-09-11  7:57 ` [PATCH v3 14/15] lib: convert process iterator to for_each_process_rculock Ye Liu
2026-09-11  7:58 ` [PATCH v3 15/15] security/landlock: convert thread iterator to for_each_thread_rculock Ye Liu

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=7ae944a6-df67-4a8a-8ece-c34701715c8a@linux.dev \
    --to=ye.liu@linux.dev \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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