From: Amit Kapila <amit.kapila@huawei.com>
To: 'Alvaro Herrera' <alvherre@commandprompt.com>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: 'Edmund Horner' <ejrh00@gmail.com>
Cc: 'Pg Bugs' <pgsql-bugs@postgresql.org>
Cc: 'Bruce Momjian' <bruce@momjian.us>
Subject: Re: 9.2 beta2 - pg_ctl crashes on Win32 when neither PGDATA nor -D specified
Date: Thu, 14 Jun 2012 10:54:18 +0530
Message-ID: <003a01cd49ed$f32ea690$d98bf3b0$@kapila@huawei.com> (raw)
In-Reply-To: <1339601668-sup-4658@alvh.no-ip.org>
References: <CAMyN-kAsMj18rV9eshn4JX4Dn-JXbLMzC+eZ6wrnQ76FavaFfA@mail.gmail.com>
<9940.1339467780@sss.pgh.pa.us>
<4fd73c8b.25d3440a.7d9b.7fd2SMTPIN_ADDED@mx.google.com>
<CAMyN-kCJ0RVmrhsT3ipqOmRh=E-E=RuHNWob-iO2HChLUjFeYQ@mail.gmail.com>
<002501cd4920$85617430$90245c90$@kapila@huawei.com>
<1339601668-sup-4658@alvh.no-ip.org>
Please Find the patch based on idea I have suggested attached with this mail.
Let me know your comments regarding the same.
-----Original Message-----
From: pgsql-bugs-owner@postgresql.org [mailto:pgsql-bugs-owner@postgresql.org] On Behalf Of Alvaro Herrera
Sent: Wednesday, June 13, 2012 9:23 PM
To: Amit Kapila
Cc: 'Edmund Horner'; Tom Lane; Pg Bugs; Bruce Momjian
Subject: Re: [BUGS] 9.2 beta2 - pg_ctl crashes on Win32 when neither PGDATA nor -D specified
Excerpts from Amit Kapila's message of mié jun 13 00:53:47 -0400 2012:
> > Unfortunately in src/backend/main/main.c it only does a cursory check
> > for --help and --version. So it would need to become a little more
> > complicated to scan for -C options at that stage. It's not too much
> > if you can assume -C always appears first like the other special
> > options detected in that file.
>
> I am doubtful whether we should make such an exception for -C option, as
> this will
> be a change in behavior as compare to previous versions.
> How to do in code is next step.
> According to me the solution I have proposed is safer and already initdb
> handles in same way.
>
> I am waiting for other people opinion on this issue.
I agree with you. The fact that we drop privileges is not only a
security measure; it's a robustness one as well. With the current
setup, we can confidently say "it's not Postgres' fault" when the system
crashes with some weird kernel error. A process running with
administrative privs is capable of doing privileged stuff that may
override safe interfaces provided by the operating system; a process
without admin privs is more constrained and should not be able to cause
the system to crash. Any kernel crash, then, is not our responsibility.
If we allow -C to run with admin privs, we lose that.
--
Álvaro Herrera <alvherre@commandprompt.com>
The PostgreSQL Company - Command Prompt, Inc.
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugsAttachments:pgctldefectfix.patch (application/octet-stream, 1.6K) downloaddiff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.cindex 329cc24..4462749 100644--- a/src/bin/pg_ctl/pg_ctl.c+++ b/src/bin/pg_ctl/pg_ctl.c@@ -1961,10 +1961,16 @@ main(int argc, char **argv)
int c;
pgpid_t killproc = 0;
+#ifdef WIN32+ char *restrict_env;+#endif+
#if defined(WIN32) || defined(__CYGWIN__)
setvbuf(stderr, NULL, _IONBF, 0);
#endif
++
progname = get_progname(argv[0]);
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_ctl"));
start_time = time(NULL);
@@ -2182,6 +2188,49 @@ main(int argc, char **argv)
canonicalize_path(pg_config);
pg_data = xstrdup(pg_config);
}
+#ifdef WIN32++ /*+ * Before we execute another program, make sure that we are running with a+ * restricted token. If not, re-execute ourselves with one.+ */++ if ((restrict_env = getenv("PG_RESTRICT_EXEC")) == NULL+ || strcmp(restrict_env, "1") != 0)+ {+ PROCESS_INFORMATION pi;+ char *cmdline;++ ZeroMemory(&pi, sizeof(pi));++ cmdline = xstrdup(GetCommandLine());++ putenv("PG_RESTRICT_EXEC=1");++ if (!CreateRestrictedProcess(cmdline, &pi, false))+ {+ write_stderr(_("%s: could not re-exec with restricted token: error code %lu\n"), progname, GetLastError());+ }+ else+ {+ /*+ * Successfully re-execed. Now wait for child process to capture+ * exitcode.+ */+ DWORD x;++ CloseHandle(pi.hThread);+ WaitForSingleObject(pi.hProcess, INFINITE);++ if (!GetExitCodeProcess(pi.hProcess, &x))+ {+ write_stderr(_("%s: could not get exit code from subprocess: error code %lu\n"), progname, GetLastError());+ exit(1);+ }+ exit(x);+ }+ }+#endif
adjust_data_dir();
=
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: amit.kapila@huawei.com, alvherre@commandprompt.com, tgl@sss.pgh.pa.us, ejrh00@gmail.com, bruce@momjian.us
Subject: Re: 9.2 beta2 - pg_ctl crashes on Win32 when neither PGDATA nor -D specified
In-Reply-To: <003a01cd49ed$f32ea690$d98bf3b0$@kapila@huawei.com>
References: <CAMyN-kAsMj18rV9eshn4JX4Dn-JXbLMzC+eZ6wrnQ76FavaFfA@mail.gmail.com> <9940.1339467780@sss.pgh.pa.us> <4fd73c8b.25d3440a.7d9b.7fd2SMTPIN_ADDED@mx.google.com> <CAMyN-kCJ0RVmrhsT3ipqOmRh=E-E=RuHNWob-iO2HChLUjFeYQ@mail.gmail.com> <002501cd4920$85617430$90245c90$@kapila@huawei.com> <1339601668-sup-4658@alvh.no-ip.org> <003a01cd49ed$f32ea690$d98bf3b0$@kapila@huawei.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox