Article View: muc.lists.freebsd.bugs
Article #538[Bug 300893] tty_pts: TIOCSCTTY, TIOCNOTTY and TIOCSPGRP are accepted on the pty master
From: 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
Technical Details
Message-ID:
<bug-300893-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 300893] tty_pts: TIOCSCTTY, TIOCNOTTY and TIOCSPGRP are accepted on the pty master Date: Thu, 19 Nov 2026 08:29:58 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-300893-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="25800"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795076998; 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=BGWif2B/trLW43lxN7eu0/3KcbjeKYHj/YGpYSMrLrc=; b=QMZ1i6PzzRpKzt5bKG2l4PPQ9FiwFprCWkMJhQs3gMn1wnPzTLi4FiPdcxAdBHgdUDQAJz KH1flhbEV4ZNQ3LiamibqnjetGIZc7vAibeg/RdC7LsR2pST4gT06xNXle6Ed/HjQceuJ+ rfBgnGZB0p6Xu9lvEokpdB38OvgORkbN7PkJkbpWYhp/O/EBabt8if1bqzbjc6Lf7+ty1Y ziTNxqwooZzSscgMBAVoMpFBzDZ6C7mRRWZV98F9RMumbgVI7CDGrsmUMXQmzTiEEElti2 BzSasR9+/wTd7m1OdahsX9rT9Blkg1M2LZYjwLtb6M15wgw3kyfmf29iiXJuNw== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes