XArray: Fix infinite loop with entry at ULONG_MAX
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 17 Jan 2020 22:45:12 +0000 (17:45 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 29 Jan 2020 15:45:26 +0000 (16:45 +0100)
commita5135ca1f92a7b201b7f8297f42b8579f92bc55d
tree186501e471fdb0e5e845e9bddb03e5144d1c3051
parentb8560e3d90afad8c5ee1ae4fea41949a76b5bb8b
XArray: Fix infinite loop with entry at ULONG_MAX

commit 430f24f94c8a174d411a550d7b5529301922e67a upstream.

If there is an entry at ULONG_MAX, xa_for_each() will overflow the
'index + 1' in xa_find_after() and wrap around to 0.  Catch this case
and terminate the loop by returning NULL.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/test_xarray.c
lib/xarray.c