git: 16e5fecccd0e - main - kern/kern_descrip.c: avoid leaking pwd hold when vnode export fails

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 23 Nov 2026 00:16:03 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=16e5fecccd0e79fe9439ab526745f23b31051c34

commit 16e5fecccd0e79fe9439ab526745f23b31051c34
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-21 03:19:50 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-23 00:10:23 +0000

    kern/kern_descrip.c: avoid leaking pwd hold when vnode export fails
    
    kern_proc_filedesc_out() gotos around the pwd_drop() call on errors from
    export_vnode_to_sb(), leaking the hold.
    
    Reported by:    llm-postcr
    Reviewed by:    markj
    Fixes:  36bd49ac4db8 ("fd: Avoid truncating output buffers for KERN_PROC_{CWD,FILEDESC}")
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D61859
---
 sys/kern/kern_descrip.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index ae32f9cffc97..8968ffa7dea9 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -5095,10 +5095,10 @@ kern_proc_filedesc_out(struct proc *p,  struct sbuf *sb, ssize_t maxlen,
 		}
 	}
 	PWDDESC_XUNLOCK(pdp);
-	if (error != 0)
-		goto fail;
 	if (pwd != NULL)
 		pwd_drop(pwd);
+	if (error != 0)
+		goto fail;
 	FILEDESC_SLOCK(fdp);
 	if (refcount_load(&fdp->fd_refcnt) == 0)
 		goto skip;