procfs: fix possible double mmput() in do_procmap_query()
Subsystems (5)
Andrii Nakryiko
maintainerPATCH 1/1 procfs: fix possible double mmput() in do_procmap_query()
When user provides incorrectly sized buffer for build ID for PROCMAP_QUERY we return with -ENAMETOOLONG error. After recent changes this condition happens later, after we unlocked mmap_lock/per-VMA lock and did mmput(), so original goto out is now wrong and will double-mmput() mm_struct. Fix by jumping further to clean up only vm_file and name_buf.
--- fs/proc/task_mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +2 -1
@@ -780,7 +780,7 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg) }else {if (karg.build_id_size < build_id_sz) { err = -ENAMETOOLONG ; - goto out; + goto out_file; } karg.build_id_size = build_id_sz; }
@@ -808,6 +808,7 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg) out:query_vma_teardown (&lock_ctx);mmput (mm); +out_file:if (vm_file)fput (vm_file);kfree (name_buf);
Signature · 1 line
2.47.3
Quoted 11 lines · Andrii Nakryiko
When user provides incorrectly sized buffer for build ID for
PROCMAP_QUERYwe return with-ENAMETOOLONGerror. After recent changes this condition happens later, after we unlocked mmap_lock/per-VMA lock and didmmput(), so original goto out is now wrong and will double-mmput()mm_struct. Fix by jumping further to clean up onlyvm_fileandname_buf.Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")Reported-by Ruikai Peng <[email protected]>Reported-by Thomas Gleixner <[email protected]>Reported-by [email protected]Signed-off-by Andrii Nakryiko <[email protected]>
I did not test this one, but the identical fix I did myself :)
Quoted 7 lines · Andrii Nakryiko
When user provides incorrectly sized buffer for build ID for
PROCMAP_QUERYwe return with-ENAMETOOLONGerror. After recent changes this condition happens later, after we unlocked mmap_lock/per-VMA lock and didmmput(), so original goto out is now wrong and will double-mmput()mm_struct. Fix by jumping further to clean up onlyvm_fileandname_buf.Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")
Why didn't the BPF AI review bot didn't trigger for b5cbacd7f86f?
Quoted 4 lines
Reported-by Ruikai Peng <[email protected]>Reported-by Thomas Gleixner <[email protected]>Reported-by [email protected]Signed-off-by Andrii Nakryiko <[email protected]>
Quoted 8 lines · Shakeel Butt
Quoted 6 lines · Andrii Nakryiko
When user provides incorrectly sized buffer for build ID for
PROCMAP_QUERYwe return with-ENAMETOOLONGerror. After recent changes this condition happens later, after we unlocked mmap_lock/per-VMA lock and didmmput(), so original goto out is now wrong and will double-mmput()mm_struct. Fix by jumping further to clean up onlyvm_fileandname_buf.
Quoted 4 lines
Quoted 1 line
Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")Why didn't the BPF AI review bot didn't trigger for
b5cbacd7f86f?
I was wondering the same, tbh. I think it's because I marked the patch for mm-stable tree with [PATCH mm-stable], and our BPF CI infrastructure just ignored this patch (even though bpf mailing list was cc'ed).
Quoted 6 lines
Quoted 4 lines
Reported-by Ruikai Peng <[email protected]>Reported-by Thomas Gleixner <[email protected]>Reported-by [email protected]Signed-off-by Andrii Nakryiko <[email protected]>Reviewed-by Shakeel Butt <[email protected]>
This patch was applied to bpf/bpf.git (master) by Andrew Morton <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Andrew Morton <[email protected]>:
Quoted 6 lines · On Tue, 10 Feb 2026 11:27:38 -0800 you wrote:
When user provides incorrectly sized buffer for build ID for
PROCMAP_QUERYwe return with-ENAMETOOLONGerror. After recent changes this condition happens later, after we unlocked mmap_lock/per-VMA lock and didmmput(), so original goto out is now wrong and will double-mmput()mm_struct. Fix by jumping further to clean up onlyvm_fileandname_buf.
Quoted 7 lines
Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")Reported-by Ruikai Peng <[email protected]>Reported-by Thomas Gleixner <[email protected]>Reported-by [email protected]Signed-off-by Andrii Nakryiko <[email protected]>[...]
Here is the summary with links:
- [mm-hotfixes-stable] procfs: fix possible double mmput() in do_procmap_query()
https://git.kernel.org/bpf/bpf/c/61dc9f776705
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html