From nobody Wed Jan 17 17:50:07 2024 X-Original-To: dev-commits-src-main@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 4TFYLS1NcJz58HPP; Wed, 17 Jan 2024 17:50:08 +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 4TFYLS0lSdz4W6N; Wed, 17 Jan 2024 17:50:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705513808; 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=KPMMZ9NCxgXR+SW1pcrtYJ75bn9cjjo4wOyDvzRmm90=; b=FFwsvTD62qKel/R5H9MWUX1LNT5gv+Cc7NOrn4vUMps9md/3xZF+7FnHKii0IXCFWQXrqO Qh1GNvt+HGHY1pcq1llfOpOTJTrdpk6gdTrqPSCd1FnSw4zxfNmnXn7TiW3x5KQdpFCznQ BQqECkqrrqUQB+qHbu0ls8jeHTXDyMVJ6bf+jhhbNygUYry9vQ9GCBsVXWDstAfaZbsPNN n0IDEFAnqvxOrQ6Ol0vPhDFMLfwTmd780bledCOdQ/Wbt/QmXyvs9t6HHpGLAyvV2Kb2P3 7R99gv/uqR/N2GqZdnW05JN5BkFsgDFy4D45hpqlOCNJj1g8kKuhIcJeUm1lYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705513808; 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=KPMMZ9NCxgXR+SW1pcrtYJ75bn9cjjo4wOyDvzRmm90=; b=V1prpi361D2R1KPPaYHqxnaZmK6axBT+ARp2BHm46tdGejPpt0q9VVanZG0E2qTh211P6g n7c3Wm0Hu+YjouFaYl3XJFtVlTnWQx1IgL8bkXU1LGS74/4qtFARFqlgTay20g7d8yMcMC wR0Fi1IgoshTdSo648dzUJRwoBB2vaqliMNACXBSvdH/dz0xbpGRUEFQhVjyKk44+f3TPx NFKExctCHdvULvLSA0wOy4VpycLUFbcdXIlz9ziA1WKaNyeui2kBXMCyhi/SkN4WWkHCDv 9jcvirxNyqCqdQZIPjg1ZE0QkzvLNGq9gfmir0pB5ZVfcd3yLr1DxOmvdo1SNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705513808; a=rsa-sha256; cv=none; b=EAXnNdQL6Mi+AZKJv36zekVEg6K6qgBbf01uK9pfrT1//IU3BAaKzYNjc0xPC8gOJpSwlZ whHSNUbZtPvZ+jjIwBD5hjsOFug/No4CdTo7FTgO+5HhoNeRL3S90Y+WIgDkL9e4X0dVBp VxbeDoTSZE7Y/TBgNyGF8jqb8mOFYqBrQWrqvPuydGQkxyhXNVQeAg05xzlbioYyEMfJxZ Ka2JLfshMnH+uxWRf5aytHvxhGOzqU5agUVWsAPCYxOdSA34aSmFtf9XQDbeGv+ucbRd+D JxD9k6Ood1i13oN5QN7mA0nOo2zPwTLcM8YuMPSvUs7i82QlEBt8OC60Bj+RGw== 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 4TFYLR6w06zYrq; Wed, 17 Jan 2024 17:50:07 +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 40HHo7F1098801; Wed, 17 Jan 2024 17:50:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40HHo7rD098796; Wed, 17 Jan 2024 17:50:07 GMT (envelope-from git) Date: Wed, 17 Jan 2024 17:50:07 GMT Message-Id: <202401171750.40HHo7rD098796@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Pawel Jakub Dawidek Subject: git: f1d0a0cbecf2 - main - jail: Fix information leak. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: pjd X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f1d0a0cbecf2c688061f35adea85bfb29c9ec893 Auto-Submitted: auto-generated The branch main has been updated by pjd: URL: https://cgit.FreeBSD.org/src/commit/?id=f1d0a0cbecf2c688061f35adea85bfb29c9ec893 commit f1d0a0cbecf2c688061f35adea85bfb29c9ec893 Author: Pawel Jakub Dawidek AuthorDate: 2024-01-17 17:43:55 +0000 Commit: Pawel Jakub Dawidek CommitDate: 2024-01-17 17:43:55 +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 --- 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 29bb092a50b0..ce72b250c526 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1310,9 +1310,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); @@ -1325,13 +1327,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); }