Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Feb 2021 08:36:49 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 86316d8265b7 - stable/12 - Lock proctree in around fill_kinfo_proc().
Message-ID:  <202102090836.1198anUm013843@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=86316d8265b7640f24b42df83738730c9a8222b9

commit 86316d8265b7640f24b42df83738730c9a8222b9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2020-12-31 22:29:40 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-02-09 08:35:39 +0000

    Lock proctree in around fill_kinfo_proc().
    
    Tested by:      pho
    
    (cherry picked from commit 4daea938130b4a219e01d678e9499f0bdb715f82)
---
 sys/kern/imgact_elf.c | 2 ++
 sys/kern/kern_proc.c  | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index e436c34d1d1b..18b83d6b499a 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -2326,8 +2326,10 @@ __elfN(note_procstat_proc)(void *arg, struct sbuf *sb, size_t *sizep)
 		KASSERT(*sizep == size, ("invalid size"));
 		structsize = sizeof(elf_kinfo_proc_t);
 		sbuf_bcat(sb, &structsize, sizeof(structsize));
+		sx_slock(&proctree_lock);
 		PROC_LOCK(p);
 		kern_proc_out(p, sb, ELF_KERN_PROC_MASK);
+		sx_sunlock(&proctree_lock);
 	}
 	*sizep = size;
 }
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index 4a202f0a7411..739046cca413 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1603,9 +1603,11 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
 		error = sysctl_wire_old_buffer(req, 0);
 		if (error)
 			return (error);
+		sx_slock(&proctree_lock);
 		error = pget((pid_t)name[0], PGET_CANSEE, &p);
 		if (error == 0)
 			error = sysctl_out_proc(p, req, flags);
+		sx_sunlock(&proctree_lock);
 		return (error);
 	}
 
@@ -1634,6 +1636,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
 		if (error != 0)
 			return (error);
 	}
+	sx_slock(&proctree_lock);
 	sx_slock(&allproc_lock);
 	for (doingzomb=0 ; doingzomb < 2 ; doingzomb++) {
 		if (!doingzomb)
@@ -1740,6 +1743,7 @@ sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
 	}
 out:
 	sx_sunlock(&allproc_lock);
+	sx_sunlock(&proctree_lock);
 	return (error);
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202102090836.1198anUm013843>