summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wilcox <mawilcox@microsoft.com>2017-11-28 15:50:12 -0500
committerMatthew Wilcox <mawilcox@microsoft.com>2018-02-06 16:41:28 -0500
commit72fd6c7be701d80eef34da305a6294c61520fe13 (patch)
tree43cedfc096c74d6240c51b77d6ed2b5a1042621c
parent7a4575778f4db109b8b78e6dba03271096793f88 (diff)
downloadlinux-0-day-72fd6c7be701d80eef34da305a6294c61520fe13.tar.gz
linux-0-day-72fd6c7be701d80eef34da305a6294c61520fe13.tar.xz
idr: Warn if old iterators see large IDs
Now that the IDR can be used to store large IDs, it is possible somebody might only partially convert their old code and use the iterators which can only handle IDs up to INT_MAX. It's probably unwise to show them a truncated ID, so settle for spewing warnings to dmesg, and terminating the iteration. Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
-rw-r--r--lib/idr.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 3df44d528b687..b47055efceb0a 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -159,7 +159,11 @@ int idr_for_each(const struct idr *idr,
void __rcu **slot;
radix_tree_for_each_slot(slot, &idr->idr_rt, &iter, 0) {
- int ret = fn(iter.index, rcu_dereference_raw(*slot), data);
+ int ret;
+
+ if (WARN_ON_ONCE(iter.index > INT_MAX))
+ break;
+ ret = fn(iter.index, rcu_dereference_raw(*slot), data);
if (ret)
return ret;
}
@@ -187,6 +191,9 @@ void *idr_get_next(struct idr *idr, int *nextid)
if (!slot)
return NULL;
+ if (WARN_ON_ONCE(iter.index > INT_MAX))
+ return NULL;
+
*nextid = iter.index;
return rcu_dereference_raw(*slot);
}