diff --git a/kernel/static_call.c b/kernel/static_call.c index a5df28b2bc1b6588d5131834ae3a55d8ebb6c071..63e7c2efc5cdd49197de922921c905561ea8bfc5 100644 --- a/kernel/static_call.c +++ b/kernel/static_call.c @@ -406,6 +406,17 @@ static void static_call_del_module(struct module *mod) for (site = start; site < stop; site++) { key = static_call_key(site); + + /* + * If the key was not updated due to a memory allocation + * failure in __static_call_init() then treating key::sites + * as key::mods in the code below would cause random memory + * access and #GP. In that case all subsequent sites have + * not been touched either, so stop iterating. + */ + if (!static_call_key_has_mods(key)) + break; + if (key == prev_key) continue;