Re: [PATCH] mm: fix use-after free of page_ext after race with memory-offline

From: Charan Teja Kalla
Date: Fri Jul 15 2022 - 08:32:50 EST


Thanks Andrew for the review!!

On 7/15/2022 6:34 AM, Andrew Morton wrote:
> On Thu, 14 Jul 2022 20:17:43 +0530 Charan Teja Kalla <quic_charante@xxxxxxxxxxx> wrote:
>
>> The below is one path where race between page_ext and offline of the
>> respective memory blocks will cause use-after-free on the access of
>> page_ext structure.
>>
>> ...
>>
>> --- a/include/linux/page_ext.h
>> +++ b/include/linux/page_ext.h
>> @@ -64,6 +64,25 @@ static inline struct page_ext *page_ext_next(struct page_ext *curr)
>> return next;
>> }
>>
>> +static inline struct page_ext *get_page_ext(struct page *page)
>> +{
>> + struct page_ext *page_ext;
>> +
>> + rcu_read_lock();
> If page_ext.h is to call rcu functions then it will need to include
> appropriate header files.
>

Will add them!!

>> + page_ext = lookup_page_ext(page);
>> + if (!page_ext) {
>> + rcu_read_unlock();
>> + return NULL;
>> + }
>> +
>> + return page_ext;
>> +}
>> +
>> +static inline void put_page_ext(void)
>> +{
>> + rcu_read_unlock();
>> +}
> Better names would be page_ext_get() and page_ext_put(). The rest of
> the page_ext API appears to have got this right, so let's not mess that
> up.

I see naming convention is not consistent in page_ext.c. For couple of
them I see page_ext_xxx() and for the rest it is xxx_page_ext(). Sure I
will follow the page_ext_xxx() convention in V2.

>
> Also, these aren't really get and put functions - page_ext doesn't have
> a refcount. But I can't immediately think of a name that better
> communicates what we're doing here so I guess get and put will do.
>> And are we able to add some comments here explaining why these
> functions exist and what they do?

Sure will add then in V2.
>
>> #else /* !CONFIG_PAGE_EXTENSION */
>> struct page_ext;
> Are you sure we didn't need CONFIG_PAGE_EXTENSION=n stubs for these two
> functions?

I think it does need. Will add them in v2.

>
>