Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932566AbcDSTWf (ORCPT ); Tue, 19 Apr 2016 15:22:35 -0400 Received: from terminus.zytor.com ([198.137.202.10]:42480 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932318AbcDSTWe (ORCPT ); Tue, 19 Apr 2016 15:22:34 -0400 User-Agent: K-9 Mail for Android In-Reply-To: <87inzdmo9z.fsf_-_@x220.int.ebiederm.org> References: <878u0s3orx.fsf_-_@x220.int.ebiederm.org> <87twjcorwg.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> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Subject: Re: Does anyone care about a race free ptsname? From: "H. Peter Anvin" Date: Tue, 19 Apr 2016 12:16:13 -0700 To: ebiederm@xmission.com, Linus Torvalds 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 Message-ID: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1772 Lines: 46 On April 19, 2016 11:44:40 AM PDT, ebiederm@xmission.com wrote: >Linus Torvalds writes: > >> What this does is get rid of the horrible notion of having that >> >> struct inode *ptmx_inode >> >> be the interface between the pty code and devpts. By de-emphasizing >the >> ptmx inode, a lot of things actually get cleaner, and we will have a >much >> saner way forward. > >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. > >The only way we have today to query which instance of devpts the pty is >on is through fstat and look st_dev to see if the file is on the >correct >filesystem. This works when /dev/pts/ptmx is used and fails when >/dev/ptmx is used. > >Does anyone else care? > >If no one cares I will stop worrying about it and just get on with >fixing the rest of this mess which there definitely seems to be the >will >to do. > >Eric We could add another ioctl for that purpose of we need to. Perhaps an ioctl which returns a file descriptor to the slave device? However, since we are now defining ptmx to explicitly look up pts/ by name it seems like /dev/ptmx -> /dev/pts/# is true by definition. If what you worry about is namespace reshuffling then ptsname() is the wrong interface in the first place since it returns a pathname. Fwiw, in klibc ptsname() is basically just an sprintf(). -- Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.