diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2021-02-13 02:11:25 +0100 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-19 20:47:33 +0200 |
commit | 9492261ff2460252cf2d8de89cdf854c7e2b28a0 (patch) | |
tree | 3640d582a003ce846467aceb9a52a7ed3e90fe37 /lib/generic-radix-tree.c | |
parent | MAINTAINERS: Add entry for generic-radix-tree (diff) | |
download | linux-9492261ff2460252cf2d8de89cdf854c7e2b28a0.tar.xz linux-9492261ff2460252cf2d8de89cdf854c7e2b28a0.zip |
lib/generic-radix-tree.c: Don't overflow in peek()
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>
Diffstat (limited to 'lib/generic-radix-tree.c')
-rw-r--r-- | lib/generic-radix-tree.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/generic-radix-tree.c b/lib/generic-radix-tree.c index f25eb111c051..7dfa88282b00 100644 --- a/lib/generic-radix-tree.c +++ b/lib/generic-radix-tree.c @@ -166,6 +166,10 @@ void *__genradix_iter_peek(struct genradix_iter *iter, struct genradix_root *r; struct genradix_node *n; unsigned level, i; + + if (iter->offset == SIZE_MAX) + return NULL; + restart: r = READ_ONCE(radix->root); if (!r) @@ -184,10 +188,17 @@ restart: (GENRADIX_ARY - 1); while (!n->children[i]) { + size_t objs_per_ptr = genradix_depth_size(level); + + if (iter->offset + objs_per_ptr < iter->offset) { + iter->offset = SIZE_MAX; + iter->pos = SIZE_MAX; + return NULL; + } + i++; - iter->offset = round_down(iter->offset + - genradix_depth_size(level), - genradix_depth_size(level)); + iter->offset = round_down(iter->offset + objs_per_ptr, + objs_per_ptr); iter->pos = (iter->offset >> PAGE_SHIFT) * objs_per_page; if (i == GENRADIX_ARY) |