]> jfr.im git - irc/atheme/atheme.git/commit
module_unload: avoid potential use-after-free
authorNicole Kleinhoff <redacted>
Thu, 3 Jun 2021 05:58:04 +0000 (05:58 +0000)
committerNicole Kleinhoff <redacted>
Sun, 13 Jun 2021 02:59:46 +0000 (02:59 +0000)
commiteb8e4a1cd4e59456bca11d109fc76d933491c4d6
treeea1789f22f320d2eb6aa42c4bad799325682e469
parentc5696933e10b8b25f6fc8e5a02ffe1a3a7431ae7
module_unload: avoid potential use-after-free

Given three modules (A, B, C), where:

B depends on A
C depends on B
C depends on A

Module A can end up with this reverse dependency graph (as represented
in the modules' required_by lists):

A -> B -> C
A -> C

Given B is listed first in required_by, it will be unloaded;
recursively, C will be unloaded. However, unloading a module also
removes it from its dependencies' required_by lists, thus removing C
from A's required_by list. While the _SAFE variant of the list iteration
macro is designed to handle the current element being removed, it is not
able to handle an arbitrary number of following elements being removed
as well.

As unloading a module will always remove it from the required_by list,
we can instead keep unloading the first element of the list until the
list is empty.
libathemecore/module.c