summaryrefslogtreecommitdiff
path: root/lib/idr.c
diff options
context:
space:
mode:
authorMatthew Wilcox (Oracle) <willy@infradead.org>2023-12-21 16:53:57 +0000
committerTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-02-01 11:13:54 +0000
commit4e015450d1dfc777a05939647822084e78bcc981 (patch)
tree8585185faed9fdea372931abb494007c3965feb0 /lib/idr.c
parent75cfaf69975ddb465ec0ea5c85ac49c66825c499 (diff)
downloadcommon-4e015450d1dfc777a05939647822084e78bcc981.tar.gz
UPSTREAM: ida: Fix crash in ida_free when the bitmap is empty
[ Upstream commit af73483f4e8b6f5c68c9aa63257bdd929a9c194a ] The IDA usually detects double-frees, but that detection failed to consider the case when there are no nearby IDs allocated and so we have a NULL bitmap rather than simply having a clear bit. Add some tests to the test-suite to be sure we don't inadvertently reintroduce this problem. Unfortunately they're quite noisy so include a message to disregard the warnings. Bug: 321878978 Reported-by: Zhenghan Wang <wzhmmmmm@gmail.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> (cherry picked from commit 5dbcdaf4dbfe074e9142991c5c28eef789c1f6c6) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I4919e5c64af12f86fe1a91e1e9224a58eedbf345
Diffstat (limited to 'lib/idr.c')
-rw-r--r--lib/idr.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/idr.c b/lib/idr.c
index 13f2758c2377..da36054c3ca0 100644
--- a/lib/idr.c
+++ b/lib/idr.c
@@ -508,7 +508,7 @@ void ida_free(struct ida *ida, unsigned int id)
goto delete;
xas_store(&xas, xa_mk_value(v));
} else {
- if (!test_bit(bit, bitmap->bitmap))
+ if (!bitmap || !test_bit(bit, bitmap->bitmap))
goto err;
__clear_bit(bit, bitmap->bitmap);
xas_set_mark(&xas, XA_FREE_MARK);