git: 8788c3d3fa9d - stable/14 - sysctl vm.objects/vm.swap_objects: do not fill vnode info if jailed

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 24 Jan 2024 13:04:25 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=8788c3d3fa9d217e0b4f2bb87a84fbd6e6aceac9

commit 8788c3d3fa9d217e0b4f2bb87a84fbd6e6aceac9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-01-13 01:46:04 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-01-24 13:04:07 +0000

    sysctl vm.objects/vm.swap_objects: do not fill vnode info if jailed
    
    (cherry picked from commit 38f5f2a4af5daeec7f13d39cad1ff4dc90da52d8)
---
 sys/vm/vm_object.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c
index d3337c038113..76ae6118a756 100644
--- a/sys/vm/vm_object.c
+++ b/sys/vm/vm_object.c
@@ -69,6 +69,7 @@
 #include <sys/systm.h>
 #include <sys/blockcount.h>
 #include <sys/cpuset.h>
+#include <sys/jail.h>
 #include <sys/limits.h>
 #include <sys/lock.h>
 #include <sys/mman.h>
@@ -2516,6 +2517,7 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 	vm_page_t m;
 	u_long sp;
 	int count, error;
+	bool want_path;
 
 	if (req->oldptr == NULL) {
 		/*
@@ -2534,6 +2536,7 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 		    count * 11 / 10));
 	}
 
+	want_path = !(swap_only || jailed(curthread->td_ucred));
 	kvo = malloc(sizeof(*kvo), M_TEMP, M_WAITOK | M_ZERO);
 	error = 0;
 
@@ -2585,7 +2588,8 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only)
 		freepath = NULL;
 		fullpath = "";
 		vp = NULL;
-		kvo->kvo_type = vm_object_kvme_type(obj, swap_only ? NULL : &vp);
+		kvo->kvo_type = vm_object_kvme_type(obj, want_path ? &vp :
+		    NULL);
 		if (vp != NULL) {
 			vref(vp);
 		} else if ((obj->flags & OBJ_ANON) != 0) {