summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-02-12 20:11:25 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-11-28 17:14:40 +0000
commitec298b958cb0c40d70c68079da933c8f31c5134c (patch)
tree887f1a2e7f4af12623f33c43489eb95f4744bb85 /include
parent96612b6f99d5783bdbe96443fca455290bac17b3 (diff)
downloadlinux-stable-ec298b958cb0c40d70c68079da933c8f31c5134c.tar.gz
linux-stable-ec298b958cb0c40d70c68079da933c8f31c5134c.tar.bz2
linux-stable-ec298b958cb0c40d70c68079da933c8f31c5134c.zip
lib/generic-radix-tree.c: Don't overflow in peek()
[ Upstream commit 9492261ff2460252cf2d8de89cdf854c7e2b28a0 ] When we started spreading new inode numbers throughout most of the 64 bit inode space, that triggered some corner case bugs, in particular some integer overflows related to the radix tree code. Oops. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/generic-radix-tree.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/linux/generic-radix-tree.h b/include/linux/generic-radix-tree.h
index 107613f7d792..f6cd0f909d9f 100644
--- a/include/linux/generic-radix-tree.h
+++ b/include/linux/generic-radix-tree.h
@@ -38,6 +38,7 @@
#include <asm/page.h>
#include <linux/bug.h>
+#include <linux/limits.h>
#include <linux/log2.h>
#include <linux/math.h>
#include <linux/types.h>
@@ -184,6 +185,12 @@ void *__genradix_iter_peek(struct genradix_iter *, struct __genradix *, size_t);
static inline void __genradix_iter_advance(struct genradix_iter *iter,
size_t obj_size)
{
+ if (iter->offset + obj_size < iter->offset) {
+ iter->offset = SIZE_MAX;
+ iter->pos = SIZE_MAX;
+ return;
+ }
+
iter->offset += obj_size;
if (!is_power_of_2(obj_size) &&