Thread View: muc.lists.freebsd.bugs
2 messages
2 total messages
Started by bugzilla-noreply
Thu, 19 Nov 2026 08:29
[Bug 300893] tty_pts: TIOCSCTTY, TIOCNOTTY and TIOCSPGRP are accepted on the pty master
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 08:29
Date: Thu, 19 Nov 2026 08:29
113 lines
5292 bytes
5292 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300893
Bug ID: 300893
Summary: tty_pts: TIOCSCTTY, TIOCNOTTY and TIOCSPGRP are
accepted on the pty master
Product: Base System
Version: 16.0-CURRENT
Hardware: Any
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: rbranco@suse.com
OpenBSD fixed the same bug in errata 021
(https://ftp.openbsd.org/pub/OpenBSD/patches/8.0/common/021_pty.patch.sig).
> TIOCSCTTY, TIOCNOTTY and TIOCSPGRP ioctl(2) calls were incorrectly allowed on a pty(4) master.
FreeBSD has the same behaviour. ptsdev_ioctl() in sys/kern/tty_pts.c hands
these three ioctls to ttydev_ioctl_proctree(), which is the same path the slave
uses:
if (cmd == TIOCNOTTY || cmd == TIOCSCTTY || cmd == TIOCSPGRP)
return (ttydev_ioctl_proctree(tp, cmd, data, td));
The path never checks that the fd is the master. A session leader can
therefore make the pty its controlling terminal through the master fd, change
the foreground process group, and release the controlling terminal again. None
of this goes through the slave device.
With no slave open, the same calls fail with ENXIO. That comes from
ttydev_enter(), not from a deliberate check. After the slave is opened, all
three calls succeed.
Steps to reproduce:
#include <sys/ioctl.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
static void
try(int fd, u_long cmd, void *arg, const char *name)
{
printf("%s on master: ", name);
if (ioctl(fd, cmd, arg) == 0)
printf("SUCCEEDED\n");
else
warn(NULL);
}
int
main(void)
{
int m, s, arg = 0, pg;
if (setsid() < 0) /* needs to be a session leader */
err(1, "setsid");
if ((m = posix_openpt(O_RDWR | O_NOCTTY)) < 0)
err(1, "posix_openpt");
if (grantpt(m) < 0 || unlockpt(m) < 0)
err(1, "grantpt/unlockpt");
if ((s = open(ptsname(m), O_RDWR | O_NOCTTY)) < 0)
err(1, "open slave");
try(m, TIOCSCTTY, &arg, "TIOCSCTTY");
pg = getpgrp();
try(m, TIOCSPGRP, &pg, "TIOCSPGRP");
try(m, TIOCNOTTY, &arg, "TIOCNOTTY");
return (0);
}
Build and run it. It must not already be a process group leader. Running it
from a fresh shell works, and so does setsid ./a.out
TIOCSCTTY on master: SUCCEEDED
TIOCSPGRP on master: SUCCEEDED
TIOCNOTTY on master: SUCCEEDED
Expected results:
All three calls fail with ENOTTY, as on OpenBSD after errata 021.
Proposed fix:
In ptsdev_ioctl(), return ENOTTY for these three commands instead of calling
ttydev_ioctl_proctree():
if (cmd == TIOCNOTTY || cmd == TIOCSCTTY || cmd == TIOCSPGRP)
return (ENOTTY);
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300893] tty_pts: TIOCSCTTY, TIOCNOTTY and TIOCSPGRP are accepted on the pty master
Author: bugzilla-noreply
Date: Thu, 19 Nov 2026 08:32
Date: Thu, 19 Nov 2026 08:32
13 lines
2418 bytes
2418 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300893 --- Comment #1 from Ricardo Branco <rbranco@suse.com> --- Fix: https://github.com/freebsd/freebsd-src/pull/2571 -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads