[PATCH] mm/mempolicy: fix memory leak in weighted_interleave_auto_store()

Jackie Liu
2026-03-31T10:08:27Z

From: Jackie Liu <liuyun01@kylinos.cn>

Add the missing kfree(new_wi_state) when the auto mode is already set
to the requested value. When a user writes "false" to the auto sysfs
interface and the current mode is already manual (mode_auto == false),
the function returns early without freeing new_wi_state allocated at
the beginning of the function. This can be triggered repeatedly from
userspace, leaking memory on each write.

Fixes: e341f9c3c841 ("mm/mempolicy: Weighted Interleave Auto-tuning")
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
mm/mempolicy.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index cf92bd6a8226..9ac74178075b 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -3713,6 +3713,7 @@ static ssize_t weighted_interleave_auto_store(struct kobject *kobj,
goto update_wi_state;
if (input == old_wi_state->mode_auto) {
mutex_unlock(&wi_state_lock);
+ kfree(new_wi_state);
return count;
}

--
2.51.1