Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Muchun Song <muchun.song@linux.dev>
To: Xiangfeng Cai <caixiangfeng@bytedance.com>
Cc: akpm@linux-foundation.org, osalvador@suse.de, david@kernel.org,
	richard.weiyang@linux.alibaba.com, baoquan.he@linux.dev,
	shuah@kernel.org, linux-mm@kvack.org,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/2] mm/hugetlb: fix list corruption in allocate_file_region_entries()
Date: Tue, 14 Jul 2026 11:54:28 +0800	[thread overview]
Message-ID: <5FB61ABB-6299-4EBE-93DC-BFAE855EE5F1@linux.dev> (raw)
In-Reply-To: <20260713171456.300518-2-caixiangfeng@bytedance.com>



> On Jul 14, 2026, at 01:14, Xiangfeng Cai <caixiangfeng@bytedance.com> wrote:
> 
> allocate_file_region_entries() tops up resv->region_cache with freshly
> allocated file_region descriptors.  The allocation uses GFP_KERNEL, so
> resv->lock is dropped around it: the new entries are gathered on a
> stack-local list head, allocated_regions, and spliced into
> resv->region_cache once the lock is re-acquired.
> 
> The splice used list_splice(), which moves the entries but does not
> re-initialize the source head, so allocated_regions is left pointing at an
> entry that now lives on resv->region_cache.  The top-up runs in a while
> loop that re-checks the cache deficit after re-acquiring the lock.  For a
> shared mapping the resv_map is shared by every mapper of the hugetlbfs
> inode, so a concurrent region_chg()/region_add()/region_del() on the same
> resv_map can consume cache entries during the unlocked window and force a
> second iteration.  That iteration calls list_add() on the stale head and
> corrupts the list; with CONFIG_DEBUG_LIST the __list_add_valid() check
> trips:
> 
>  list_add corruption. next->prev should be prev (ffffc900011ff7f8),
>  but was ffff88814c281460. (next=ffff88814c545640).
>  kernel BUG at lib/list_debug.c:31!
>   allocate_file_region_entries+0x191/0x420
>   region_chg+0x267/0x300
>   hugetlb_reserve_pages+0x387/0xc80
>   hugetlbfs_file_mmap+0x2ce/0x3f0
>   mmap_region+0x1348/0x1a80
>   do_mmap+0x85e/0xb90
>   vm_mmap_pgoff+0x18c/0x330
>   ksys_mmap_pgoff+0x2a1/0x3e0
>   do_syscall_64+0xd7/0x420
> 
> Without CONFIG_DEBUG_LIST the bad list_add() silently links a kernel-stack
> address into resv->region_cache, leading to later use-after-free.
> 
> Use list_splice_init() so the source head is re-initialized empty after
> each splice, making the retry loop safe.
> 
> Fixes: d3ec7b6e09e5 ("mm/hugetlb: use list_splice to merge two list at once")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Xiangfeng Cai <caixiangfeng@bytedance.com>

Reviewed-by: Muchun Song <muchun.song@linux.dev>

Thanks.



  reply	other threads:[~2026-07-14  3:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-13 17:14 [PATCH 0/2] mm/hugetlb: fix list corruption in allocate_file_region_entries() Xiangfeng Cai
2026-07-13 17:14 ` [PATCH 1/2] " Xiangfeng Cai
2026-07-14  3:54   ` Muchun Song [this message]
2026-07-13 17:14 ` [PATCH 2/2] selftests/mm: add hugetlb_region_cache_race regression test Xiangfeng Cai
2026-07-14  4:03   ` Muchun Song
2026-07-14  5:38     ` 蔡翔峰

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=5FB61ABB-6299-4EBE-93DC-BFAE855EE5F1@linux.dev \
    --to=muchun.song@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=caixiangfeng@bytedance.com \
    --cc=david@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osalvador@suse.de \
    --cc=richard.weiyang@linux.alibaba.com \
    --cc=shuah@kernel.org \
    --cc=stable@vger.kernel.org \
    /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