Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177944806
D61985.1795616401.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D61985.1795616401.diff
View Options
diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c
--- a/sys/compat/linuxkpi/common/src/linux_idr.c
+++ b/sys/compat/linuxkpi/common/src/linux_idr.c
@@ -162,6 +162,14 @@
static inline int
idr_max(struct idr *idr)
{
+ /*
+ * With IDR_BITS == 5 a 7-layer tree spans 35 bits, more than an
+ * int holds; 1 << 35 is undefined (x86 masks it to 1 << 3, giving
+ * idr_max() == 7) and makes every lookup of a large id fail.
+ * amdkfd allocates event ids starting at (INT_MAX >> 1) + 1.
+ */
+ if (idr->layers * IDR_BITS >= MAX_IDR_SHIFT)
+ return (INT_MAX);
return (1 << (idr->layers * IDR_BITS)) - 1;
}
@@ -587,7 +595,23 @@
* to be rare.
*/
if (idx == IDR_SIZE) {
- starting_id = id + (1 << ((layer + 1) * IDR_BITS));
+ int64_t next;
+
+ /*
+ * Same 1 << 35 overflow as idr_max() at the top
+ * layer.
+ */
+ if ((layer + 1) * IDR_BITS >= MAX_IDR_SHIFT) {
+ error = -ENOSPC;
+ goto out;
+ }
+ next = (int64_t)id +
+ ((int64_t)1 << ((layer + 1) * IDR_BITS));
+ if (next > INT_MAX) {
+ error = -ENOSPC;
+ goto out;
+ }
+ starting_id = (int)next;
goto restart;
}
if (idx > sidx)
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 25, 2:20 PM (21 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41992513
Default Alt Text
D61985.1795616401.diff (1 KB)
Attached To
Mode
D61985: LinuxKPI: Fix idr_max() and idr_get_new_above() overflow for 7-layer trees
Attached
Detach File
Event Timeline