]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
arm_mpam: Check whether the config array is allocated before destroying it
authorJames Morse <james.morse@arm.com>
Fri, 8 May 2026 16:23:39 +0000 (17:23 +0100)
committerCatalin Marinas <catalin.marinas@arm.com>
Thu, 14 May 2026 08:52:05 +0000 (09:52 +0100)
__destroy_component_cfg() is called to free the configuration array.
It uses the embedded 'garbage' structure, which means the array has
to be allocated.

If __destroy_component_cfg() is called from mpam_disable() before the
configuration was ever allocated, then a NULL pointer is dereferenced.

Check for this case and return early if the configuration is not
allocated.

__destroy_component_cfg() also frees the mbwu_state as this is allocated
by __allocate_component_cfg(). As the mbwu_state is allocated after
comp->cfg is set, and is also under mpam_list_lock, only the first
pointer needs checking.

Fixes: 3bd04fe7d807 ("arm_mpam: Extend reset logic to allow devices to be reset any time")
Cc: <stable@vger.kernel.org>
Signed-off-by: James Morse <james.morse@arm.com>
Reviewed-by: Ben Horgan <ben.horgan@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
drivers/resctrl/mpam_devices.c

index 5c48812d8573b5fe8dabfef883d809b9380bf2cf..988fc291241d23a5c0f9ac8a801d9a3b55860ad2 100644 (file)
@@ -2581,6 +2581,9 @@ static void __destroy_component_cfg(struct mpam_component *comp)
 
        lockdep_assert_held(&mpam_list_lock);
 
+       if (!comp->cfg)
+               return;
+
        add_to_garbage(comp->cfg);
        list_for_each_entry(vmsc, &comp->vmsc, comp_list) {
                msc = vmsc->msc;