summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2019-11-03 06:36:43 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-05 09:19:39 +0100
commit88358c7610cc29234f795bb9deca4ece95fd2c1b (patch)
treee822af15042abb9fb7280ae2a10ccebc05dbc31a /include/linux
parenta6359d5e2d98771b33f3dcd9ff26009ba8244eed (diff)
downloadlinux-stable-88358c7610cc29234f795bb9deca4ece95fd2c1b.tar.gz
linux-stable-88358c7610cc29234f795bb9deca4ece95fd2c1b.tar.bz2
linux-stable-88358c7610cc29234f795bb9deca4ece95fd2c1b.zip
idr: Fix integer overflow in idr_for_each_entry
[ Upstream commit f6341c5af4e6e15041be39976d16deca789555fa ] If there is an entry at INT_MAX then idr_for_each_entry() will increment id after handling it. This is undefined behaviour, and is caught by UBSAN. Adding 1U to id forces the operation to be carried out as an unsigned addition which (when assigned to id) will result in INT_MIN. Since there is never an entry stored at INT_MIN, idr_get_next() will return NULL, ending the loop as expected. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/idr.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 3ec8628ce17f..b6c6151c7446 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -185,7 +185,7 @@ static inline void idr_preload_end(void)
* is convenient for a "not found" value.
*/
#define idr_for_each_entry(idr, entry, id) \
- for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; ++id)
+ for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; id += 1U)
/**
* idr_for_each_entry_ul() - Iterate over an IDR's elements of a given type.