Re: [PATCH V3] mm: fix use-after free of page_ext after race with memory-offline
From: Michal Hocko
Date: Tue Aug 16 2022 - 12:15:40 EST
On Tue 16-08-22 15:04:01, Charan Teja Kalla wrote:
[...]
> >> @@ -183,19 +184,26 @@ static inline void __set_page_owner_handle(struct page_ext *page_ext,
> >> noinline void __set_page_owner(struct page *page, unsigned short order,
> >> gfp_t gfp_mask)
> >> {
> >> - struct page_ext *page_ext = lookup_page_ext(page);
> >> + struct page_ext *page_ext = page_ext_get(page);
> >> depot_stack_handle_t handle;
> >>
> >> if (unlikely(!page_ext))
> >> return;
> > Either add a comment like this
> > /* save_stack can sleep in general so we have to page_ext_put */
>
>
> Vlastimil suggested to go for save stack first since !page_ext is mostly
> unlikely. Snip from his comments:
> Why not simply do the save_stack() first and then page_ext_get() just
> once? It should be really rare that it's NULL, so I don't think we save
> much by avoiding an unnecessary save_stack(), while the overhead of
> doing two get/put instead of one will affect every call.
right see below
>
> https://lore.kernel.org/all/f5fd4942-b03e-1d1c-213b-9cd5283ced91@xxxxxxx/
> >> + page_ext_put();
> >>
> >> handle = save_stack(gfp_mask);
> > or just drop the initial page_ext_get altogether. This function is
> > called only when page_ext is supposed to be initialized and !page_ext
> > case above should be very unlikely. Or is there any reason to keep this?
^^^^^
--
Michal Hocko
SUSE Labs