Skip to contentSkip to conversation

procfs: fix possible double mmput() in do_procmap_query()

PATCH Applied Andrii Nakryiko 5 participants 5 messages Feb 10 – Feb 13

Subsystems (5)
lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 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.

Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")
Reported-by [email protected]
---
 fs/proc/task_mmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/proc/task_mmu.c +2 -1
index 26188a4ad1ab..2f55efc36816 100644
@@ -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
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrii Nakryiko

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.

Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")
Reported-by [email protected]

I did not test this one, but the identical fix I did myself :)

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrii Nakryiko
Quoted 7 lines · Andrii Nakryiko

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.

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
#3 lore raw
Quoted 8 lines · Shakeel Butt
Quoted 6 lines · Andrii Nakryiko

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.

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
#4 lore raw
In reply to Andrii Nakryiko
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_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.

Quoted 7 lines
Fixes b5cbacd7f86f ("procfs: avoid fetching build ID while holding VMA lock")
Reported-by [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