mm-mempolicy-fix-memory-leaks-in-weighted_interleave_auto_store.patch removed from -mm tree
The quilt patch titled
Subject: mm/mempolicy: fix memory leaks in weighted_interleave_auto_store()
has been removed from the -mm tree. Its filename was
mm-mempolicy-fix-memory-leaks-in-weighted_interleave_auto_store.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Jackie Liu <[email protected]>
Subject: mm/mempolicy: fix memory leaks in weighted_interleave_auto_store()
Date: Wed, 1 Apr 2026 08:57:02 +0800
weighted_interleave_auto_store() fetches old_wi_state inside the if (!input) block only. This causes two memory leaks:
1. When a user writes "false" and the current mode is already manual, the function returns early without freeing the freshly allocated new_wi_state.
2. When a user writes "true", old_wi_state stays NULL because the fetch is skipped entirely. The old state is then overwritten by rcu_assign_pointer() but never freed, since the cleanup path is gated on old_wi_state being non-NULL. A user can trigger this repeatedly by writing "1" in a loop.
Fix both leaks by moving the old_wi_state fetch before the input check, making it unconditional. This also allows a unified early return for both "true" and "false" when the requested mode matches the current mode.
Reviewed by: Donet Tom <[email protected]>
---
mm/mempolicy.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-fix-memory-leaks-in-weighted_interleave_auto_store +12 -11
@@ -3700,18 +3700,19 @@ static ssize_t weighted_interleave_auto_ new_wi_state->iw_table[i] =1 ;mutex_lock (&wi_state_lock); -if (!input) { - old_wi_state =rcu_dereference_protected (wi_state, -lockdep_is_held (&wi_state_lock)); -if (!old_wi_state) - goto update_wi_state; -if (input == old_wi_state->mode_auto) { -mutex_unlock (&wi_state_lock); -return count; - } + old_wi_state =rcu_dereference_protected (wi_state, +lockdep_is_held (&wi_state_lock)); + +if (old_wi_state && input == old_wi_state->mode_auto) { +mutex_unlock (&wi_state_lock); +kfree (new_wi_state); +return count; + } -memcpy (new_wi_state->iw_table, old_wi_state->iw_table, - nr_node_ids *sizeof (u8)); +if (!input) { +if (old_wi_state) +memcpy (new_wi_state->iw_table, old_wi_state->iw_table, + nr_node_ids *sizeof (u8)); goto update_wi_state; }
_
Patches currently in -mm which might be from [email protected] are