Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exEhc-0005Hw-9g for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 16:29:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1exEha-0002wL-LK for pgsql-bugs@arkaria.postgresql.org; Sat, 17 Mar 2018 16:29:02 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exEha-0002wC-BF for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 16:29:02 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1exEhT-0005Oo-Jm for pgsql-bugs@lists.postgresql.org; Sat, 17 Mar 2018 16:29:01 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w2HGSrp2018477; Sat, 17 Mar 2018 12:28:54 -0400 From: Tom Lane To: petar@smokva.net cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15120: use of getcwd(3)/chdir(2) during path resolution (exec.c) In-reply-to: <152130268473.1317.3689189784729884454@wrigleys.postgresql.org> References: <152130268473.1317.3689189784729884454@wrigleys.postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Sat, 17 Mar 2018 16:04:44 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18475.1521304133.1@sss.pgh.pa.us> Date: Sat, 17 Mar 2018 12:28:53 -0400 Message-ID: <18476.1521304133@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?q?PG_Bug_reporting_form?= writes: > In both cases, the utility/daemon will fail (and exit) if the current > directory is either not readable or not searchable, even though said > utility/daemon has permission to access each component of its absolute > path in argv0. TBH, I don't have a whole lot of sympathy for the premise that we need to support such cases. If we can do it without giving anything else up, then OK, but ... > In the patch below, path resolution is skipped if getcwd returns EACCES. ... I find that quite an unacceptable answer. We need to resolve the symlink correctly, or we risk malfunctioning later, for the reasons recited in the comment for find_my_exec(). The idea of pre-checking to see if the initial path is already absolute seems safe enough, but I'm not sure how much of the use-case it'd cover. I think your example of "sudo /usr/bin/pg_ctl" is pretty artificial; who'd bother spelling that out? While I've not thought about it very hard, it might be possible to rewrite find_my_exec() and resolve_symlinks() "from the ground up" so that they don't do getcwd() except in cases where there's really no alternative, such as the executable having been invoked using a relative path. Also, I realize that this patch is just a POC, but we don't much like patches that make significant logic changes without appropriate comment updates. regards, tom lane