From nobody Mon Feb 12 16:25:53 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TYVFF2LmPz5B5l7; Mon, 12 Feb 2024 16:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TYVFF1ggrz47lb; Mon, 12 Feb 2024 16:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707755153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hnjpIpewbARPr92LvsYNgDOdcDXSRFod7AonqalXfMY=; b=tkjuu2KIf6NBQowT1xrKZ/vzi9QgHBjqTAlKDujNzr5Xh14H0xl/HIAh7b0RicOiasy0aH ayLm8q30GgUK1BSt1eCDQPqijImyVqOWbwwRcemMuJvpCceS+FY9Bujd0KZCJuVaEFgf53 +37c+gjqMX/jp7DE3xtEULLhF02cY/qQCThq8RBlvdmtc4EznNVyjhd3hl0LkLFeJsN4TC Z3Xl5mSWH4RpxATbjKLOXJciq/rqdaeY+y11HMmjKeMmNSLjiWiCrZkm994QSnv+TwEaDw PW/DwG2AhPfnw1r1k6DmIaUMSKLZM4F0AwEI4XgeRtONtRJyML6lERdBSsmllg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1707755153; a=rsa-sha256; cv=none; b=aU0H6YzsOZOTOh+MwCEnC+y6aKD5X15B6/0sX9uQYyK00VwvFp0S0cVU4ahpOSWlbuqybJ pvUpgbmd/6/FKM2DKrUs4ijLzVPZllkn5MP2ZWrDCnrpJZcT5B58lsXCLUCsa8veNzkRCo GVEvLkjn+x+ZpM/QSneBNzN/jfxJ5zRHjkkw6MWvAMkUPGHSited6yu5H9m0icyfOhrjrB XSg/fYsQegTXAV6NWVAPl1YNnbDR1ga3joAtFMrT1MD+fDvXDg0QMTm/h8PXL7pKL6YsNO NjhGlp89fNgyDndjHfnOurLN/zRLIqp38h31NMWyFaR5aWi1R63bPb7Oi5eeHA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1707755153; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hnjpIpewbARPr92LvsYNgDOdcDXSRFod7AonqalXfMY=; b=NAYd++aq633nupH3Aw4vfXeVUc0JFhd8pi6pzAy7b6t1p9L6WUCHr8NItNf9VaTtYKEAcq y+E9tSfcHKXGjHMFfFCj9nsp1RckFQSlcuchk1xBE7VFv5lvsJP5X5YdKEcN+c5hMFRmyO Q23hS9lCql+XdZs41ER+R/zC2xV+ZSZOk5NhHHaGslj/kVVhSYUaSCcDJSoZ4l1LcUChUx e1osAM6F5mUjfeaWppRSETPYOCHJVRA06Mv4gm7EktuFk3FQ9+R+GVh4lJMV6RbbCVUY8z HLN6aLKoZu3mpYwDIV8gbuea2Xr5Idm5BVBHIsW7LCsZ4kQ3+PDYzm6RSer1Tw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TYVFF0jztzZ5s; Mon, 12 Feb 2024 16:25:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41CGPrDE077340; Mon, 12 Feb 2024 16:25:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41CGPrHK077337; Mon, 12 Feb 2024 16:25:53 GMT (envelope-from git) Date: Mon, 12 Feb 2024 16:25:53 GMT Message-Id: <202402121625.41CGPrHK077337@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 93c87d96e114 - stable/14 - jail: Fix information leak. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 93c87d96e11421e425e257354b8fbf2d3ad878eb Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=93c87d96e11421e425e257354b8fbf2d3ad878eb commit 93c87d96e11421e425e257354b8fbf2d3ad878eb Author: Pawel Jakub Dawidek AuthorDate: 2024-01-17 17:43:55 +0000 Commit: Mark Johnston CommitDate: 2024-02-12 16:24:21 +0000 jail: Fix information leak. There is a lack of proper visibility checking in kern.ttys sysctl handler which leads to information leak about processes outside the current jail. This can be demonstrated with pstat -t: when called from within a jail, it will output all terminal devices including process groups and session leader process IDs: jail# pstat -t | grep pts/ | head LINE INQ CAN LIN LOW OUTQ USE LOW COL SESS PGID STATE pts/2 1920 0 0 192 1984 0 199 0 4132 27245 Oi pts/3 1920 0 0 192 1984 0 199 16 24890 33627 Oi pts/5 0 0 0 0 0 0 0 25 17758 0 G pts/16 0 0 0 0 0 0 0 0 52495 0 G pts/15 0 0 0 0 0 0 0 25 53446 0 G pts/17 0 0 0 0 0 0 0 6702 33230 0 G pts/19 0 0 0 0 0 0 0 14 1116 0 G pts/0 0 0 0 0 0 0 0 0 2241 0 G pts/23 0 0 0 0 0 0 0 20 15639 0 G pts/6 0 0 0 0 0 0 0 0 44062 93792 G jail# pstat -t | grep pts/ | wc -l 85 Devfs does the filtering correctly and we get only one entry: jail# ls /dev/pts/ 2 Approved by: mzaborski, secteam MFC after: 1 week Sponsored by: Fudo Security (cherry picked from commit f1d0a0cbecf2c688061f35adea85bfb29c9ec893) --- sys/kern/tty.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 353a3b58846c..6d060d61695c 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1308,9 +1308,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 +1325,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); }