pgsql: Fix possible crashes due to using elog/ereport too early in star

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix possible crashes due to using elog/ereport too early in star
Дата
Msg-id E1W26EC-0007bf-Ft@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix possible crashes due to using elog/ereport too early in startup.

Per reports from Andres Freund and Luke Campbell, a server failure during
set_pglocale_pgservice results in a segfault rather than a useful error
message, because the infrastructure needed to use ereport hasn't been
initialized; specifically, MemoryContextInit hasn't been called.
One known cause of this is starting the server in a directory it
doesn't have permission to read.

We could try to prevent set_pglocale_pgservice from using anything that
depends on palloc or elog, but that would be messy, and the odds of future
breakage seem high.  Moreover there are other things being called in main.c
that look likely to use palloc or elog too --- perhaps those things
shouldn't be there, but they are there today.  The best solution seems to
be to move the call of MemoryContextInit to very early in the backend's
real main() function.  I've verified that an elog or ereport occurring
immediately after that is now capable of sending something useful to
stderr.

I also added code to elog.c to print something intelligible rather than
just crashing if MemoryContextInit hasn't created the ErrorContext.
This could happen if MemoryContextInit itself fails (due to malloc
failure), and provides some future-proofing against someone trying to
sneak in new code even earlier in server startup.

Back-patch to all supported branches.  Since we've only heard reports of
this type of failure recently, it may be that some recent change has made
it more likely to see a crash of this kind; but it sure looks like it's
broken all the way back.

Branch
------
REL8_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/d0070ac81b46e8c77b158268a5a772fd1a993f05

Modified Files
--------------
src/backend/bootstrap/bootstrap.c   |    8 --------
src/backend/main/main.c             |   10 ++++++++++
src/backend/postmaster/postmaster.c |    6 ------
src/backend/tcop/postgres.c         |    8 --------
src/backend/utils/error/elog.c      |   21 +++++++++++++++++++++
src/backend/utils/mmgr/mcxt.c       |    6 +++++-
6 files changed, 36 insertions(+), 23 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix possible crashes due to using elog/ereport too early in star
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix possible crashes due to using elog/ereport too early in star