aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/tty.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index d7f9a914166a..508c0f14b861 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -44,6 +44,7 @@
#ifdef COMPAT_43TTY
#include <sys/ioctl_compat.h>
#endif /* COMPAT_43TTY */
+#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/limits.h>
#include <sys/malloc.h>
@@ -1308,9 +1309,11 @@ static int
sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
{
unsigned long lsize;
+ struct thread *td = curthread;
struct xtty *xtlist, *xt;
struct tty *tp;
- int error;
+ struct proc *p;
+ int cansee, error;
sx_slock(&tty_list_sx);
lsize = tty_list_count * sizeof(struct xtty);
@@ -1323,13 +1326,28 @@ sysctl_kern_ttys(SYSCTL_HANDLER_ARGS)
TAILQ_FOREACH(tp, &tty_list, t_list) {
tty_lock(tp);
- tty_to_xtty(tp, xt);
+ if (tp->t_session != NULL) {
+ p = tp->t_session->s_leader;
+ PROC_LOCK(p);
+ cansee = (p_cansee(td, p) == 0);
+ PROC_UNLOCK(p);
+ } else {
+ cansee = !jailed(td->td_ucred);
+ }
+ if (cansee) {
+ tty_to_xtty(tp, xt);
+ xt++;
+ }
tty_unlock(tp);
- xt++;
}
sx_sunlock(&tty_list_sx);
- error = SYSCTL_OUT(req, xtlist, lsize);
+ lsize = (xt - xtlist) * sizeof(struct xtty);
+ if (lsize > 0) {
+ error = SYSCTL_OUT(req, xtlist, lsize);
+ } else {
+ error = 0;
+ }
free(xtlist, M_TTY);
return (error);
}