In the Linux kernel, the following vulnerability has been resolved:
schhtb: make htbdeactivate() idempotent
Alan reported a NULL pointer dereference in htbnextrbnode() after we made htbqlen_notify() idempotent.
It turns out in the following case it introduced some regression:
htbdequeuetree(): |-> fqcodeldequeue() |-> qdisctreereducebacklog() |-> htbqlennotify() |-> htbdeactivate() |-> htbnextrbnode() |-> htbdeactivate()
For htbnextrbnode(), after calling the 1st htbdeactivate(), the clprio[prio]->ptr could be already set to NULL, which means htbnextrb_node() is vulnerable here.
For htbdeactivate(), although we checked qlen before calling it, in case of qlen==0 after qdisctreereducebacklog(), we may call it again which triggers the warning inside.
To fix the issues here, we need to:
1) Make htbdeactivate() idempotent, that is, simply return if we already call it before. 2) Make htbnextrbnode() safe against ptr==NULL.
Many thanks to Alan for testing and for the reproducer.