kern: fix panic with disabled ttys

PR: 277240, 277329
Reviewed by: kib (earlier version)
Fixes: f1d0a0cbec ("jail: Fix information leak.")
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D44086

(cherry picked from commit 975d773082)
This commit is contained in:
Ed Maste 2024-02-26 10:38:45 -05:00
parent 38595c9d73
commit 8d22744f5b

View file

@ -1313,7 +1313,8 @@ sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
struct xtty *xtlist, *xt;
struct tty *tp;
struct proc *p;
int cansee, error;
int error;
bool cansee;
sx_slock(&tty_list_sx);
lsize = tty_list_count * sizeof(struct xtty);
@ -1326,8 +1327,8 @@ sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
TAILQ_FOREACH(tp, &tty_list, t_list) {
tty_lock(tp);
if (tp->t_session != NULL) {
p = tp->t_session->s_leader;
if (tp->t_session != NULL &&
(p = atomic_load_ptr(&tp->t_session->s_leader)) != NULL) {
PROC_LOCK(p);
cansee = (p_cansee(td, p) == 0);
PROC_UNLOCK(p);