From nobody Sat Sep 05 00:35:43 2026 X-Original-To: dev-commits-src-branches@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 4hcDrw0HcVz6qZn5 for ; Sat, 05 Sep 2026 00:35:44 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hcDrv3PRFz44ZX for ; Sat, 05 Sep 2026 00:35:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788568543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SMhpy7uU6VkzFHx3PMZMithGl//dp+JXKA+TOR6+cUQ=; b=M7Y26bDhciRfHWcDC1bZVRwP4qdRXbMw7GQObIkq8f4xomwdhbvJ8d09UJLK5i75qWhpWU r15hmTy+xP7owV3Qw3nbL88OzP86dIM6hHHKVwU5MR80bmluAe3WF5zKHZWYFC9L+uvGsi mCP2eoUlyvtrWqUyXNzzmDwGn2aRRJxFpMZ1XVZuLbhCi1h8ji0NzN3BOy4f45cNgQ2Gk3 +cgaCFWj4SLjNg090Fq+9cWTz9m5egriYj07XhR5reQtzUa917HpY1kVWK0+iCfkrZRkCh c1NIw3MwGtwknwAqhyUlLZDVgY+Y3UpsArXoJXqKRuhCyB46IMuBDXzfxyFvhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1788568543; a=rsa-sha256; cv=none; b=OMw7tg0bh85HUZAPPq8RxkC0TmjLoXoU6Apk88vnJH3ryKq5PVSYDIIj7KAzTvJqvUgTgs i4UC3NcV6w58qeS44ivtdA38rO/U3salcRhPZlp/Cu2VRppx64m1XxjXmWY2741/lYNnSL ENVEV75AjtvDsv00jFIoIhtHo6phSxWDeZZQM8ezAHUe+S0yU1zV9GZEuXZ3nJWA4muxHq tQztIVsVX1M97bWlHQHrdhpLHhmoGoUjAJ0Z0fXc/ou9wWDVjlqsEetwGa94b9vxAa860z V6cR4rSbJD9W6TLVqpjmYlrSK0pIy+ZpuqVy4HTknRHzncK5elB46rb0S4B6Dg== 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=1788568543; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=SMhpy7uU6VkzFHx3PMZMithGl//dp+JXKA+TOR6+cUQ=; b=dhytEF196uR7xG3c9JtthVQOAyc3wC3F2Wi4F/op/8Bs/E84Qg9cKf67/iyx6qK3GMfxhA 7FnzO4MJeY8aD7kwx8JRbEAuwHYkh8aEw8N3o2NHE1wbIKwVWZl5F6zC6oO4YHiQKOBga7 iKVizRtydZoezFwp+oDfPF2KjyoU/xYzOR60jtemkUjLkdx4GQTNlP/M8S7QoB9oV6CXin OBahIESMFZoPvfnuTNFkHOncWgG4TN/2UKO2tyss7QQ5YGTXZIraRXMIhcQ44pEa9k1psj cDl5qwyvjiLbLqEO/VLi1pbnGxUc+7jstvD3x1EBzTgNkyQpHGwtYDKCWQFV9Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hcDrv2Spkz7y8 for ; Sat, 05 Sep 2026 00:35:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1fd70 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Sat, 05 Sep 2026 00:35:43 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Gleb Popov From: Konstantin Belousov Subject: git: 2469f84bec79 - stable/15 - kern/tty.c: Exterrorize returns List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 2469f84bec79b090b261a6b075c76304541e2070 Auto-Submitted: auto-generated Date: Sat, 05 Sep 2026 00:35:43 +0000 Message-Id: <6a9b63df.1fd70.56cabebd@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=2469f84bec79b090b261a6b075c76304541e2070 commit 2469f84bec79b090b261a6b075c76304541e2070 Author: Gleb Popov AuthorDate: 2026-08-03 19:23:11 +0000 Commit: Konstantin Belousov CommitDate: 2026-09-05 00:33:46 +0000 kern/tty.c: Exterrorize returns (cherry picked from commit 62ccaec3dba6272590d97cc0aa0df28fd3d08d1c) --- lib/libc/gen/exterr_cat_filenames.h | 1 + sys/kern/tty.c | 49 ++++++++++++++++++++----------------- sys/sys/exterr_cat.h | 1 + 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/libc/gen/exterr_cat_filenames.h b/lib/libc/gen/exterr_cat_filenames.h index d55396a1b286..b28dbdb499a4 100644 --- a/lib/libc/gen/exterr_cat_filenames.h +++ b/lib/libc/gen/exterr_cat_filenames.h @@ -11,6 +11,7 @@ [EXTERR_CAT_PROCEXIT] = "kern/kern_exit.c", [EXTERR_CAT_FORK] = "kern/kern_fork.c", [EXTERR_CAT_GENIO] = "kern/sys_generic.c", + [EXTERR_CAT_TTY] = "kern/tty.c", [EXTERR_CAT_VFSBIO] = "kern/vfs_bio.c", [EXTERR_CAT_INOTIFY] = "kern/vfs_inotify.c", [EXTERR_CAT_VFSSYSCALL] = "kern/vfs_syscalls.c", diff --git a/sys/kern/tty.c b/sys/kern/tty.c index 7a401695be97..b7ead9ecf417 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -66,6 +66,8 @@ #undef TTYDEFCHARS #include #include +#define EXTERR_CATEGORY EXTERR_CAT_TTY +#include #include @@ -224,7 +226,7 @@ ttydev_enter(struct tty *tp) if (tty_gone(tp) || !tty_opened(tp)) { /* Device is already gone. */ tty_unlock(tp); - return (ENXIO); + return (EXTERROR(ENXIO, "ttydev_enter: device is gone")); } return (0); @@ -285,7 +287,7 @@ ttydev_open(struct cdev *dev, int oflags, int devtype __unused, if (tty_gone(tp)) { /* Device is already gone. */ tty_unlock(tp); - return (ENXIO); + return (EXTERROR(ENXIO, "ttydev_open: device is gone")); } /* @@ -491,7 +493,7 @@ tty_wait_background(struct tty *tp, struct thread *td, int sig, /* Don't allow the action to happen. */ PROC_UNLOCK(p); PGRP_UNLOCK(pg); - return (EIO); + return (EXTERROR(EIO, "cannot wait in background")); } PROC_UNLOCK(p); @@ -874,7 +876,7 @@ ttyil_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, tty_lock(tp); if (tty_gone(tp)) { - error = ENODEV; + error = (EXTERROR(ENODEV, "ttyil_ioctl: device is gone")); goto done; } @@ -1260,23 +1262,23 @@ tty_drop_ctty(struct tty *tp, struct proc *p) tty_lock(tp); if (tty_gone(tp)) { sx_xunlock(&proctree_lock); - return (ENODEV); + return (EXTERROR(ENODEV, "tty_drop_ctty: device is gone")); } /* * If the session doesn't have a controlling TTY, or if we weren't - * invoked on the controlling TTY, we'll return ENOIOCTL as we've + * invoked on the controlling TTY, we'll return ENOTTY as we've * historically done. */ session = p->p_session; if (session->s_ttyp == NULL || session->s_ttyp != tp) { sx_xunlock(&proctree_lock); - return (ENOTTY); + return (EXTERROR(ENOTTY, "no controlling tty")); } if (!SESS_LEADER(p)) { sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "not a session leader")); } PROC_LOCK(p); @@ -1607,7 +1609,7 @@ tty_wait(struct tty *tp, struct cv *cv) /* Bail out when the device slipped away. */ if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_wait: device is gone")); /* Restart the system call when we may have been revoked. */ if (tp->t_revokecnt != revokecnt) @@ -1666,7 +1668,7 @@ tty_timedwait(struct tty *tp, struct cv *cv, int hz) /* Bail out when the device slipped away. */ if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_timedwait: device is gone")); /* Restart the system call when we may have been revoked. */ if (tp->t_revokecnt != revokecnt) @@ -1714,7 +1716,7 @@ tty_sti_check(struct tty *tp, int fflag, struct thread *td) { /* Check for global disable. */ if (!tty_tiocsti) - return (EPERM); + return (EXTERROR(EPERM, "security.bsd.allow_tiocsti")); /* Root can bypass all of our constraints. */ if (priv_check(td, PRIV_TTY_STI) == 0) @@ -1722,11 +1724,11 @@ tty_sti_check(struct tty *tp, int fflag, struct thread *td) /* Unprivileged users must have it opened for read. */ if ((fflag & FREAD) == 0) - return (EPERM); + return (EXTERROR(EPERM, "opened read-only")); /* It must also be their controlling tty. */ if (!tty_is_ctty(tp, td->td_proc)) - return (EACCES); + return (EXTERROR(EACCES, "not a controlling tty")); return (0); } @@ -1913,7 +1915,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, return (0); case TIOCGPGRP: if (!tty_is_ctty(tp, td->td_proc)) - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); if (tp->t_pgrp != NULL) *(int *)data = tp->t_pgrp->pg_id; @@ -1922,7 +1924,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, return (0); case TIOCGSID: if (!tty_is_ctty(tp, td->td_proc)) - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); MPASS(tp->t_session); *(int *)data = tp->t_session->s_sid; @@ -1945,7 +1947,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, if (!SESS_LEADER(p)) { /* Only the session leader may do this. */ sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "not a session leader")); } if (tp->t_session != NULL && tp->t_session == p->p_session) { @@ -1969,7 +1971,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, * killed or the TTY revoked. */ sx_xunlock(&proctree_lock); - return (EPERM); + return (EXTERROR(EPERM, "session already has CTTY")); } /* Connect the session to the TTY. */ @@ -2002,7 +2004,10 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, if (pg == NULL || pg->pg_session != td->td_proc->p_session) { sx_sunlock(&proctree_lock); tty_lock(tp); - return (EPERM); + return (EXTERROR(EPERM, + "pgrp %jd belongs to other session %jd", + pg != NULL ? pg->pg_id : -1, + td->td_proc->p_session->s_sid)); } error = ttydev_enter(tp); if (error != 0) { @@ -2017,7 +2022,7 @@ tty_generic_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, */ if (!tty_is_ctty(tp, td->td_proc)) { sx_sunlock(&proctree_lock); - return (ENOTTY); + return (EXTERROR(ENOTTY, "not a controlling tty")); } tp->t_pgrp = pg; sx_sunlock(&proctree_lock); @@ -2109,7 +2114,7 @@ tty_ioctl(struct tty *tp, u_long cmd, void *data, int fflag, struct thread *td) tty_assert_locked(tp); if (tty_gone(tp)) - return (ENXIO); + return (EXTERROR(ENXIO, "tty_ioctl: device is gone")); error = ttydevsw_ioctl(tp, cmd, data, td); if (error == ENOIOCTL) @@ -2307,7 +2312,7 @@ ttyconsdev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) /* System has no console device. */ if (dev_console_filename == NULL) - return (ENXIO); + return (EXTERROR(ENXIO, "system has no console device")); /* Look up corresponding TTY by device name. */ sx_slock(&tty_list_sx); @@ -2321,7 +2326,7 @@ ttyconsdev_open(struct cdev *dev, int oflags, int devtype, struct thread *td) /* System console has no TTY associated. */ if (dev_console->si_drv1 == NULL) - return (ENXIO); + return (EXTERROR(ENXIO, "system console has no TTY attached")); return (ttydev_open(dev, oflags, devtype, td)); } diff --git a/sys/sys/exterr_cat.h b/sys/sys/exterr_cat.h index 015eb6a1ae76..78d52bfa6ced 100644 --- a/sys/sys/exterr_cat.h +++ b/sys/sys/exterr_cat.h @@ -39,6 +39,7 @@ #define EXTERR_CAT_FUSE_DEVICE 14 #define EXTERR_CAT_FORK 15 #define EXTERR_CAT_PROCEXIT 16 +#define EXTERR_CAT_TTY 22 #endif