[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <43e8466f-762e-4359-975f-f16cf74c2f7b@lucifer.local>
Date: Fri, 20 Jun 2025 16:50:37 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: "Liam R. Howlett" <Liam.Howlett@...cle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, maple-tree@...ts.infradead.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org, stable@...nel.org,
Suren Baghdasaryan <surenb@...gle.com>,
Hailong Liu <hailong.liu@...o.com>, zhangpeng.00@...edance.com,
Steve Kang <Steve.Kang@...soc.com>,
Matthew Wilcox <willy@...radead.org>,
Sidhartha Kumar <sidhartha.kumar@...cle.com>,
Zhaoyang Huang <zhaoyang.huang@...soc.com>
Subject: Re: [PATCH 2/3] maple_tree: Fix MA_STATE_PREALLOC flag in
mas_preallocate()
On Mon, Jun 16, 2025 at 02:45:20PM -0400, Liam R. Howlett wrote:
> Temporarily clear the preallocation flag when explicitly requesting
> allocations. Pre-existing allocations are already counted against the
> request through mas_node_count_gfp(), but the allocations will not
> happen if the MA_STATE_PREALLOC flag is set. This flag is meant to
> avoid re-allocating in bulk allocation mode, and to detect issues with
> preallocation calculations.
>
> The MA_STATE_PREALLOC flag should also always be set on zero allocations
> so that detection of underflow allocations will print a WARN_ON() during
> consumption.
>
> User visible effect of this flaw is a WARN_ON() followed by a null
> pointer dereference when subsequent requests for larger number of nodes
> is ignored, such as the vma merge retry in mmap_region() caused by
> drivers altering the vma flags (which happens in v6.6, at least)
Oh interesting, this was a deep one (Lovecraftian pun fully intended)!
>
> Reported-by: Zhaoyang Huang <zhaoyang.huang@...soc.com>
> Reported-by: Hailong Liu <hailong.liu@...o.com>
> Fixes: 54a611b605901 ("Maple Tree: add new data structure")
> Link: https://lore.kernel.org/all/1652f7eb-a51b-4fee-8058-c73af63bacd1@oppo.com/
> Link: https://lore.kernel.org/all/20250428184058.1416274-1-Liam.Howlett@oracle.com/
> Link: https://lore.kernel.org/all/20250429014754.1479118-1-Liam.Howlett@oracle.com/
> Cc: stable@...nel.org
> Cc: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
> Cc: Suren Baghdasaryan <surenb@...gle.com>
> Cc: Hailong Liu <hailong.liu@...o.com>
> Cc: zhangpeng.00@...edance.com <zhangpeng.00@...edance.com>
> Cc: Steve Kang <Steve.Kang@...soc.com>
> Cc: Matthew Wilcox <willy@...radead.org>
> Cc: Sidhartha Kumar <sidhartha.kumar@...cle.com>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@...cle.com>
This looks reasonable, but because I am not quite au fait with all the details
on a deeper level:
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
> ---
> lib/maple_tree.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 7144dbbc34813..54a09c26edf96 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -5528,8 +5528,9 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
> mas->store_type = mas_wr_store_type(&wr_mas);
> request = mas_prealloc_calc(&wr_mas, entry);
> if (!request)
> - return ret;
> + goto set_flag;
>
> + mas->mas_flags &= ~MA_STATE_PREALLOC;
> mas_node_count_gfp(mas, request, gfp);
> if (mas_is_err(mas)) {
> mas_set_alloc_req(mas, 0);
> @@ -5539,6 +5540,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp)
> return ret;
> }
>
> +set_flag:
> mas->mas_flags |= MA_STATE_PREALLOC;
> return ret;
> }
> --
> 2.47.2
>
Powered by blists - more mailing lists