From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2836 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.comp.lib.glibc.alpha,gmane.linux.lib.musl.general Subject: Re: O_EXEC and O_SEARCH Date: Fri, 22 Feb 2013 23:33:36 -0500 Message-ID: <20130223043336.GV20323@brightrain.aerifal.cx> References: <20130222004540.GA8836@brightrain.aerifal.cx> <20130223031708.GU20323@brightrain.aerifal.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1361594030 21630 80.91.229.3 (23 Feb 2013 04:33:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 23 Feb 2013 04:33:50 +0000 (UTC) Cc: libc-alpha , musl@lists.openwall.com To: KOSAKI Motohiro Original-X-From: libc-alpha-return-37217-glibc-alpha=m.gmane.org@sourceware.org Sat Feb 23 05:34:11 2013 Return-path: Envelope-to: glibc-alpha@plane.gmane.org Original-Received: from server1.sourceware.org ([209.132.180.131] helo=sourceware.org) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U96oM-0008Qa-Ne for glibc-alpha@plane.gmane.org; Sat, 23 Feb 2013 05:34:11 +0100 Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sourceware.org; s=default; x=1362198830; h=Comment: DomainKey-Signature:Received:Received:Date:To:Cc:Subject: Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:User-Agent:From:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Subscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=+79HgNNaVSmYQBy5FYnV kuUKghI=; b=kRnyeN6UizQ3PlkOcN9TA5eYv8eKdJSWrMkURo5LplPOM7Ri3F0T +3y8YCQOL4AXiztN79F3wrQPomudtYhlUNhe2SHRr5TWaSgG2nvq3XBwK7T0IyS8 mWuOi1K7vAD+KakLjZBl/1eP3/RJrkzhVKimIpohjlbtiAUwtVGEcB4= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=sourceware.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Date:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:From:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=oBkv2YLEuX03rDw+vEqqPkbNY71d/sD6x8OeBH5nxGo1RZIIVM+EXaZCuFaLNJ lNaXLCQmO43Qrw3fknh33uxt9JynR1ZOJT3ATuAtE5UT9V8FnJTFmtwQpVjL2xAc BIz2puJlugTkARMlsGiFHMGhEknT6+oGGJKb0s4Zgtvx4=; Original-Received: (qmail 16573 invoked by alias); 23 Feb 2013 04:33:46 -0000 Original-Received: (qmail 16559 invoked by uid 22791); 23 Feb 2013 04:33:44 -0000 X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL,BAYES_00,KHOP_DYNAMIC2,RDNS_DYNAMIC,TVD_RCVD_IP X-Spam-Check-By: sourceware.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Original-Sender: libc-alpha-owner@sourceware.org Xref: news.gmane.org gmane.comp.lib.glibc.alpha:29553 gmane.linux.lib.musl.general:2836 Archived-At: On Fri, Feb 22, 2013 at 10:58:18PM -0500, KOSAKI Motohiro wrote: > On Fri, Feb 22, 2013 at 10:17 PM, Rich Felker wrote: > > On Fri, Feb 22, 2013 at 10:05:03PM -0500, KOSAKI Motohiro wrote: > >> > I'd like to have a conversation with the glibc team about O_EXEC and > >> > O_SEARCH in the interest of hopefully developing a unified plan for > >> > supporting them on Linux. Presumably the reason glibc still does not > >> > have them is that Linux O_PATH does not exactly match their semantics > >> > in some cases, and O_PATH is sufficiently broken on many kernel > >> > versions to make offering it problematic. In particular, current > >> > coreutils break badly on most kernel versions around 2.6.39-3.6 or so > >> > if O_SEARCH and O_EXEC are defined as O_PATH. > >> > >> I'm curious why don't you implement them in kernel directly? > > > > See this thread for Linus's opinion on why O_SEARCH was not added: > > > > http://comments.gmane.org/gmane.linux.file-systems/33611 > > > > O_NODE seems to have been renamed to O_PATH, or perhaps O_PATH was a > > later independent implementation of the same idea; it's not clear to > > me which happened. But the idea is that the kernel folks did not want > > to do O_SEARCH and O_EXEC properly in kernelspace but instead wanted > > to provide a more general flag that could be used to implement both > > O_SEARCH and O_EXEC. > > Do you mean following response? > > >I suspect that what we _could_ possibly do is to have something like > >O_NODE, and after that - if the semantics (for directories) match what > >O_SEARCH/O_EXEC wants, we could just do > > > >#define O_SEARCH O_NODE > > > >but my point is that we should _not_ start from O_SEARCH and make that the > >"core" part, since its semantics are badly defined (undefined) to begin > >with. > > I so, I don't think "start" mean refusing at all. However, I agree > kernel folks dislike > to hear "because it's posix". As far as no concrete good use case, any proposal > may be going to be get negative response. Yes, this is what I was referring to. > However, if O_SEARCH is really useful, I think in kernel Regardless of whether it's useful, it's mandatory, and you can't claim conformance if it's omitted. With that said, I think it is useful with the *at functions. Otherwise, the *at functions have reduced functionality in some sense because you can't use them with directories you don't have read access to. > implementation is better > because all other flags are implemented in kernel and it may prevent to create > ugly corner case. I agree, I really wish the kernel had just defined access mode 3 to be O_SEARCH and O_EXEC. However, getting them to do this seems unlikely. Even if they did do it, glibc and musl both intend to support kernels older than 3.9, so we'd have to have some fallback mechanism for avoiding serious breakage in apps when the kernel does not support them right. Note that this breakage is happening ALREADY in coreutils if O_SEARCH and O_EXEC are defined; the only reason coreutils is working on glibc is that glibc does not define them. Anyway, at this point (3.8 kernel, maybe some older ones too), I believe O_PATH is sufficient to implement O_SEARCH and O_EXEC with one caveat: If O_NOFOLLOW is also specified, fstat must be used after the open to determine if the file descriptor obtained refers to a symbolic link, and if so, it should be closed and failure simulated. I'm not aware of any other cases where O_PATH would give the wrong behavior. If we want to offer O_SEARCH and O_EXEC but avoid breakage on broken kernels (2.6.39 through 3.5 or so), then perhaps fstat should always be checked whenever O_SEARCH or O_EXEC is used. If it fails (which means the kernel is broken), the file descriptor could be closed and open reattempted in O_RDONLY mode. Alternatively, we could define O_SEARCH and O_EXEC to the value 3, and always do the following remapping in userspace: 1. Try to open with O_RDONLY. If it succeeds, we're done. This is REALLY nice because it means O_SEARCH and O_EXEC "just work" even on ancient or broken kernels as long as the target file is readable. 2. Else, add O_PATH and try again. If it still fails, we have a pre-2.6.39 kernel and there's nothing we can do, so just report failure. 3. If open succeeds with O_PATH, then if O_NOFOLLOW is also specified, check fstat, and close the file and report error if fstat succeeded and the obtained fd was a symbolic link. 4. If fstat failed, we have a buggy kernel, so either close and report an error, or just ignore the failure (possibly ignoring the requirements of O_NOFOLLOW), as there seems to be no way to handle it correctly on such kernels. If the kernel developers ever add O_SEARCH/O_EXEC at the kernel level with our proposed value of 3, a step 0, just passing the value to the kernel directly and seeing if it works, could also be added. Rich