lkml.org 
[lkml]   [2022]   [Apr]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2] mm/mmu_notifier.c: Fix race in mmu_interval_notifier_remove()
Date
Andrew Morton <akpm@linux-foundation.org> writes:

> On Wed, 20 Apr 2022 14:37:34 +1000 Alistair Popple <apopple@nvidia.com> wrote:
>
>> In some cases it is possible for mmu_interval_notifier_remove() to race
>> with mn_tree_inv_end() allowing it to return while the notifier data
>> structure is still in use. Consider the following sequence:
>>
>> CPU0 - mn_tree_inv_end() CPU1 - mmu_interval_notifier_remove()
>> ----------------------------------- ------------------------------------
>> spin_lock(subscriptions->lock);
>> seq = subscriptions->invalidate_seq;
>> spin_lock(subscriptions->lock); spin_unlock(subscriptions->lock);
>> subscriptions->invalidate_seq++;
>> wait_event(invalidate_seq != seq);
>> return;
>> interval_tree_remove(interval_sub); kfree(interval_sub);
>> spin_unlock(subscriptions->lock);
>> wake_up_all();
>>
>> As the wait_event() condition is true it will return immediately. This
>> can lead to use-after-free type errors if the caller frees the data
>> structure containing the interval notifier subscription while it is
>> still on a deferred list. Fix this by taking the appropriate lock when
>> reading invalidate_seq to ensure proper synchronisation.
>>
>> ...
>>
>> Fixes: 99cb252f5e68 ("mm/mmu_notifier: add an interval tree notifier")
>
> Do you think fix this should be backported into older kernels?

Yes, I forgot to cc stable sorry. Do you want me to resend with
'Cc: stable@vger.kernel.org'?

- Alistair
\
 
 \ /
  Last update: 2022-04-21 01:29    [W:0.090 / U:1.536 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site