From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753241AbdK1Vi2 (ORCPT ); Tue, 28 Nov 2017 16:38:28 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:39255 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752771AbdK1Vdd (ORCPT ); Tue, 28 Nov 2017 16:33:33 -0500 From: Matthew Wilcox Cc: Matthew Wilcox , Chris Mi , Jiri Pirko , "David S . Miller" , Cong Wang , Jamal Hadi Salim , Daniel Borkmann , Eric Biggers , Lai Jiangshan , Tejun Heo , Rehas Sachdeva , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/17] idr: Warn if old iterators see large IDs Date: Tue, 28 Nov 2017 13:33:12 -0800 Message-Id: <20171128213312.28983-18-willy@infradead.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171128213312.28983-1-willy@infradead.org> References: <20171128213312.28983-1-willy@infradead.org> To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox 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 --- lib/idr.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/idr.c b/lib/idr.c index 772a24513d1e..f56133a600bb 100644 --- a/lib/idr.c +++ b/lib/idr.c @@ -145,7 +145,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(iter.index > INT_MAX)) + break; + ret = fn(iter.index, rcu_dereference_raw(*slot), data); if (ret) return ret; } @@ -173,6 +177,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); } -- 2.15.0