git: 987c8e9afa1a - stable/14 - kinfo_{vmobject,vmentry}: move copy of pathes into the vnode handling scope

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 15 Oct 2024 15:05:31 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=987c8e9afa1a198d7cf9fc304e4855a0d9dcb738

commit 987c8e9afa1a198d7cf9fc304e4855a0d9dcb738
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-07 07:36:51 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-10-15 14:50:16 +0000

    kinfo_{vmobject,vmentry}: move copy of pathes into the vnode handling scope
    
    (cherry picked from commit 71a66883b58f796baf2bf79a43a91c16a71673b3)
---
 sys/kern/kern_proc.c | 7 +++----
 sys/vm/vm_object.c   | 5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 17d002a29c77..8f5ffeea71d3 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -2741,6 +2741,9 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
 					kve->kve_status = KF_ATTR_VALID;
 				}
 				vput(vp);
+				strlcpy(kve->kve_path, fullpath, sizeof(
+				    kve->kve_path));
+				free(freepath, M_TEMP);
 			}
 		} else {
 			kve->kve_type = guard ? KVME_TYPE_GUARD :
@@ -2749,10 +2752,6 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
 			kve->kve_shadow_count = 0;
 		}
 
-		strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
-		if (freepath != NULL)
-			free(freepath, M_TEMP);
-
 		/* Pack record size down */
 		if ((flags & KERN_VMMAP_PACK_KINFO) != 0)
 			kve->kve_structsize =
diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index a8821f0f2a8b..1dbebf139683 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -2622,11 +2622,10 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 								/* truncate */
 			}
 			vput(vp);
+			strlcpy(kvo->kvo_path, fullpath, sizeof(kvo->kvo_path));
+			free(freepath, M_TEMP);
 		}
 
-		strlcpy(kvo->kvo_path, fullpath, sizeof(kvo->kvo_path));
-		free(freepath, M_TEMP);
-
 		/* Pack record size down */
 		kvo->kvo_structsize = offsetof(struct kinfo_vmobject, kvo_path)
 		    + strlen(kvo->kvo_path) + 1;