Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753765AbcDSXoI (ORCPT ); Tue, 19 Apr 2016 19:44:08 -0400 Received: from terminus.zytor.com ([198.137.202.10]:47518 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753678AbcDSXoG (ORCPT ); Tue, 19 Apr 2016 19:44:06 -0400 Subject: Re: Does anyone care about a race free ptsname? To: Linus Torvalds , "Eric W. Biederman" References: <878u0s3orx.fsf_-_@x220.int.ebiederm.org> <20160409140909.42315e6d@lxorguk.ukuu.org.uk> <83FE8CD2-C0A2-4ADB-AEBD-8DD89AD4F88A@zytor.com> <87bn5ij0x1.fsf@x220.int.ebiederm.org> <78205895-E11D-417F-91DC-4BCA0B61A122@zytor.com> <570D4781.3070600@zytor.com> <877ffyzy1j.fsf_-_@x220.int.ebiederm.org> <87inzdmo9z.fsf_-_@x220.int.ebiederm.org> Cc: Andy Lutomirski , security@debian.org, "security@kernel.org" , Al Viro , "security@ubuntu.com >> security" , Peter Hurley , Serge Hallyn , Willy Tarreau , Aurelien Jarno , One Thousand Gnomes , Jann Horn , Greg KH , Linux Kernel Mailing List , Jiri Slaby , Florian Weimer From: "H. Peter Anvin" Message-ID: <5716C19B.1030500@zytor.com> Date: Tue, 19 Apr 2016 16:39:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1255 Lines: 33 On 04/19/2016 04:23 PM, Linus Torvalds wrote: > On Tue, Apr 19, 2016 at 11:44 AM, Eric W. Biederman > wrote: >> >> I will take a look in a minute. Before I do that I want to mention >> why I care about /dev/pts/ptmx. >> >> There is a posix function that is widely used called ptsname. It's >> function is to take a master file descriptor and returns the path to the >> slave. >> >> All we have in the kernel to support ptsname is an ioctl TIOCGPTN that >> returns the pty number in the appropriate instance of devpts. > > Don't bother with that completely mis-designed interface.It's crap. > > So we'll keep it working for legacy models, but the whole "return an > integer index" is just pure shit. It's not worth worrying about. > > We can (and probably should) just introduce a new ioctl or even a > system call that just does the sane thing and returns the pathname > from the kernel. > What do you think of the idea of TIOCPTSOPEN (or whatever) to get a file descriptor for the slave device given the master device? Then we can use realpath() or a readlink on /proc/self/fd/# to get the pathname if needed. (Incidentally, we added getcwd() as a system call. Should we add [f]realpath() as a system call too?) -hpa