git: 6392bf679e0b - main - proc: Fix an execve race in proc_getauxv()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Fri, 27 Nov 2026 14:53:30 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=6392bf679e0b815b0e78a9b4285e9906a8dd4d1f

commit 6392bf679e0b815b0e78a9b4285e9906a8dd4d1f
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-11-27 14:52:13 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-11-27 14:52:13 +0000

    proc: Fix an execve race in proc_getauxv()
    
    The SV_PROC_FLAG(p, SV_ILP32) test in proc_getauxv() is racy once we
    unblock execve, resulting in a potential OOB read of heap memory.
    Postpone the proc_vmspace_unref() call until after we've calculated the
    auxv size.
    
    Reviewed by:    kib
    Reported by:    Albert E. of Metnir
    Fixes:          a22c044cce41 ("kern_proc.c: ensure stability of the vmspace we read the strings from")
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D62107
---
 sys/kern/kern_proc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index c0a6f9767db2..d85e6d78179e 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2114,7 +2114,6 @@ proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
 	if (error != 0)
 		return (error);
 	error = get_proc_vector(td, p, vm, &auxv, &vsize, PROC_AUX);
-	proc_vmspace_unref(td, p, PRVM_BLOCK_EXEC | PRVM_CHECK_DEBUG, vm);
 	if (error == 0) {
 #ifdef COMPAT_FREEBSD32
 		if (SV_PROC_FLAG(p, SV_ILP32) != 0)
@@ -2126,6 +2125,7 @@ proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
 			error = ENOMEM;
 		free(auxv, M_TEMP);
 	}
+	proc_vmspace_unref(td, p, PRVM_BLOCK_EXEC | PRVM_CHECK_DEBUG, vm);
 	return (error);
 }