git: 3484217cc47c - main - proc: free kstack buffers when debug permission changes

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 16 Sep 2026 15:35:10 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=3484217cc47c1f77d2be2ed0e012b870d1cd3dca

commit 3484217cc47c1f77d2be2ed0e012b870d1cd3dca
Author:     Andrew Griffiths <andrew@calif.io>
AuthorDate: 2026-09-14 07:55:01 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-09-16 15:34:31 +0000

    proc: free kstack buffers when debug permission changes
    
    The kern.proc.kstack handler allocates its output and stack buffers
    before deliberately checking p_candebug again under the process lock.
    If trace-control state changes between authorization checks, the failure
    path balances the process and exec state but leaks both buffers.
    
    Submitted by calif.io for the OpenAI Patch The Planet program
    
    Signed-off-by: Andrew Griffiths <andrew@calif.io>
    
    Fixes:          8b5abd9027b8 ("kern_proc.c: disallow execve around sysctl kern.proc.kstacks")
    Reviewed by:    markj
    MFC after:      1 week
---
 sys/kern/kern_proc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 6489feca99fc..398de3a182f5 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2890,6 +2890,8 @@ sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
 		execve_unblock(ctd, p);
 		_PRELE(p);
 		PROC_UNLOCK(p);
+		stack_destroy(st);
+		free(kkstp, M_TEMP);
 		return (error);
 	}
 	do {