History

genirq/matrix: Prevent allocation counter corruption

When irq_matrix_free() is called for an unallocated vector the managed_allocated and total_allocated counters get out of sync with the real state of the matrix. Later, when the last interrupt is freed, these counters will underflow resulting in UINTMAX because the counters are unsigned. While this is certainly a problem of the calling code, this can be catched in the allocator by checking the allocation bit for the to be freed vector which simplifies debugging. An example of the problem described above: https://lore.kernel.org/lkml/20210318192819.636943062@linutronix.de/ Add the missing sanity check and emit a warning when it triggers.

Vitaly Kuznetsov committed 5 years ago

Commit c93a5e21 parent 2c6b0211 file · +3 −1Browse files

Unified · Split

kernel/irq/matrix.c+3−1
@@ -422,7 +422,9 @@ void irq_matrix_free(struct irq_matrix *m, unsigned int cpu, · 421 unmodified lines
422422 if (WARN_ON_ONCE(bit < m->alloc_start || bit >= m->alloc_end))
423423 return;
424424
425− clear_bit(bit, cm->alloc_map);
425+ if (WARN_ON_ONCE(!test_and_clear_bit(bit, cm->alloc_map)))
426+ return;
427+
426428 cm->allocated--;
427429 if(managed)
428430 cm->managed_allocated--;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t