Skip to content
/ linux Public

Commit 8adaff8

Browse files
anakryikoSasha Levin
authored andcommitted
procfs: fix possible double mmput() in do_procmap_query()
[ Upstream commit 61dc9f7 ] 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. Link: https://lkml.kernel.org/r/20260210192738.3041609-1-andrii@kernel.org Fixes: b5cbacd ("procfs: avoid fetching build ID while holding VMA lock") Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reported-by: Ruikai Peng <ruikai@pwno.io> Reported-by: Thomas Gleixner <tglx@kernel.org> Tested-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev> Reported-by: syzbot+237b5b985b78c1da9600@syzkaller.appspotmail.com Cc: Ruikai Peng <ruikai@pwno.io> Closes: https://lkml.kernel.org/r/CAFD3drOJANTZPuyiqMdqpiRwOKnHwv5QgMNZghCDr-WxdiHvMg@mail.gmail.com Closes: https://lore.kernel.org/all/698aaf3c.050a0220.3b3015.0088.GAE@google.com/T/#u Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f644910 commit 8adaff8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fs/proc/task_mmu.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg)
780780
} else {
781781
if (karg.build_id_size < build_id_sz) {
782782
err = -ENAMETOOLONG;
783-
goto out;
783+
goto out_file;
784784
}
785785
karg.build_id_size = build_id_sz;
786786
}
@@ -808,6 +808,7 @@ static int do_procmap_query(struct mm_struct *mm, void __user *uarg)
808808
out:
809809
query_vma_teardown(&lock_ctx);
810810
mmput(mm);
811+
out_file:
811812
if (vm_file)
812813
fput(vm_file);
813814
kfree(name_buf);

0 commit comments

Comments
 (0)