From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11897 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 0/1] openpty: use TIOCGPTPEER to open slave side fd Date: Fri, 1 Sep 2017 12:00:49 -0400 Message-ID: <20170901160049.GK1627@brightrain.aerifal.cx> References: <20170901153558.29715-1-christian.brauner@ubuntu.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1504281669 15758 195.159.176.226 (1 Sep 2017 16:01:09 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 1 Sep 2017 16:01:09 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11910-gllmg-musl=m.gmane.org@lists.openwall.com Fri Sep 01 18:01:00 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dnoNN-0003cb-Sr for gllmg-musl@m.gmane.org; Fri, 01 Sep 2017 18:00:57 +0200 Original-Received: (qmail 17857 invoked by uid 550); 1 Sep 2017 16:01:03 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17827 invoked from network); 1 Sep 2017 16:01:02 -0000 Content-Disposition: inline In-Reply-To: <20170901153558.29715-1-christian.brauner@ubuntu.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11897 Archived-At: On Fri, Sep 01, 2017 at 05:35:57PM +0200, Christian Brauner wrote: > Hi, > > Newer kernels expose the ioctl TIOCGPTPEER [1] call to userspace which allows to > safely allocate a file descriptor for a pty slave based solely on the master > file descriptor. This allows us to avoid path-based operations and makes this > function a lot safer in the face of devpts mounts in different mount namespaces. > > [1]: https://patchwork.kernel.org/patch/9760743/ > > The way I wrote this patch it doesn't use the snprintf() and open() routine as a > fallback in case the ioctl() call fails. If this is a compatibility issue for > non-Linux systems I can rewrite. But the musl documentation gave me the > impression that this is not really a concern. It's a compatibility issue for everything but bleeding-edge Linux. musl supports all the way back to 2.6.0 and possibly farther, but especially needs to support actual modern versions people run; you can't just add dependencies on newly-added features. There's also no reason for the #ifdef TIOCGPTPEER, as musl decides if TIOCGPTPEER is defined or not (it has to provide the definition). Instead, you just need to try the ioctl and fall back if it fails. Is the TIOCGPTPEER thing upstream in the kernel yet? If not it's not a stable API and possibly subject to change (even reassignment of the ioctl number which could be dangerous) so this patch can't be merged until it's official/permanent on the kernel side. Otherwise this looks like a good change, but I do wonder a bit about how the cases where it would help are intended to work, since the POSIX interfaces for opening a pty require using a pathname (ptsname[_r]). It seems like only programs using the nonstandard openpty() function could benefit, and while this interface is nicer in many ways, it's fundamentally broken in that it lacks a way to atomically set the FD_CLOEXEC flag. The POSIX functions posix_openpt and ptsname+open both allow O_CLOEXEC which solves this problem. Rich