]> www.infradead.org Git - users/dwmw2/linux.git/commit
maple_tree: reset mas->index and mas->last on write retries
authorSidhartha Kumar <sidhartha.kumar@oracle.com>
Mon, 12 Aug 2024 19:05:42 +0000 (15:05 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 2 Sep 2024 03:26:11 +0000 (20:26 -0700)
commite1b8b883bb838339eec728de5d02e2f252a7d3d9
tree7bd24fe4e83d6de301736d69e3df2df420fdb028
parentc0f398c3b2cf67976bca216f80668b9c93368385
maple_tree: reset mas->index and mas->last on write retries

The following scenario can result in a race condition:

Consider a node with the following indices and values

a<------->b<----------->c<--------->d
    0xA        NULL          0xB

CPU 1   CPU 2
      ---------         ---------
mas_set_range(a,b)
mas_erase()
-> range is expanded (a,c) because of null expansion

mas_nomem()
mas_unlock()
mas_store_range(b,c,0xC)

The node now looks like:

a<------->b<----------->c<--------->d
    0xA        0xC          0xB

mas_lock()
mas_erase() <------ range of erase is still (a,c)

The node is now NULL from (a,c) but the write from CPU 2 should have been
retained and range (b,c) should still have 0xC as its value.  We can fix
this by re-intializing to the original index and last.  This does not need
a cc: Stable as there are no users of the maple tree which use internal
locking and this condition is only possible with internal locking.

Link: https://lkml.kernel.org/r/20240812190543.71967-1-sidhartha.kumar@oracle.com
Signed-off-by: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/maple_tree.c