idr: Warn if old iterators see large IDs

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/72fd6c7be701d80eef34da305a6294c61520fe13
Commit:     72fd6c7be701d80eef34da305a6294c61520fe13
Parent:     7a4575778f4db109b8b78e6dba03271096793f88
Refname:    refs/heads/master
Author:     Matthew Wilcox <[email protected]>
AuthorDate: Tue Nov 28 15:50:12 2017 -0500
Committer:  Matthew Wilcox <[email protected]>
CommitDate: Tue Feb 6 16:41:28 2018 -0500

    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 <[email protected]>
---
 lib/idr.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/idr.c b/lib/idr.c
index 3df44d528b68..b47055efceb0 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);
 }
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.