Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1ySq-0005u8-Lq for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2021 21:23:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l1ySp-0003eM-EG for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Jan 2021 21:22:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1ySp-0003eF-7j for pgsql-hackers@lists.postgresql.org; Tue, 19 Jan 2021 21:22:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1ySn-0001Yp-8M for pgsql-hackers@lists.postgresql.org; Tue, 19 Jan 2021 21:22:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10JLMp2W523590; Tue, 19 Jan 2021 16:22:51 -0500 From: Tom Lane To: Robert Haas cc: vignesh C , Andres Freund , Peter Eisentraut , PostgreSQL Hackers Subject: Re: Printing backtrace of postgres processes In-reply-to: References: <1778088.1606026308@sss.pgh.pa.us> <20201201032649.aekv5b5dicvmovf4@alap3.anarazel.de> <1361750.1606795285@sss.pgh.pa.us> <55526d79-247d-83a1-0961-7d42e0db1870@enterprisedb.com> <20210115201011.noomcygirzge43ir@alap3.anarazel.de> <3537.1610828491@sss.pgh.pa.us> <492025.1611078655@sss.pgh.pa.us> Comments: In-reply-to Robert Haas message dated "Tue, 19 Jan 2021 15:58:36 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <523588.1611091371.1@sss.pgh.pa.us> Date: Tue, 19 Jan 2021 16:22:51 -0500 Message-ID: <523589.1611091371@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas writes: > On Tue, Jan 19, 2021 at 12:50 PM Tom Lane wrote: >> I think it's got security hazards as well. If we restricted the >> feature to cause a trace of only one process at a time, and required >> that process to be logged in as the same database user as the >> requestor (or at least someone with the privs of that user, such >> as a superuser), that'd be less of an issue. > I am not sure I see a security hazard here. I think the checks for > this should have the same structure as pg_terminate_backend() and > pg_cancel_backend(); whatever is required there should be required > here, too, but not more, unless we have a real clear reason for such > an inconsistency. Yeah, agreed. The "broadcast" option seems inconsistent with doing things that way, but I don't have a problem with being able to send a trace signal to the same processes you could terminate. >> I share your estimate that there'll be small-fraction-of-a-percent >> hazards that could still add up to dangerous instability if people >> go wild with this. > Right. I was more concerned about whether we could, for example, crash > while inside the function that generates the backtrace, on some > platforms or in some scenarios. That would be super-sad. I assume that > the people who wrote the code tried to make sure that didn't happen > but I don't really know what's reasonable to expect. Recursion is scary, but it should (I think) not be possible if this is driven off CHECK_FOR_INTERRUPTS. There will certainly be none of those in libbacktrace. One point here is that it might be a good idea to suppress elog.c's calls to functions in the error context stack. As we saw in another connection recently, allowing that to happen makes for a *very* large increase in the footprint of code that you are expecting to work at any random CHECK_FOR_INTERRUPTS call site. BTW, it also looks like the patch is doing nothing to prevent the backtrace from being sent to the connected client. I'm not sure what I think about whether it'd be okay from a security standpoint to do that on the connection that requested the trace, but I sure as heck don't want it to happen on connections that didn't. Also, whatever you think about security concerns, it seems like there'd be pretty substantial reentrancy hazards if the interrupt occurs anywhere in code dealing with normal client communication. Maybe, given all of these things, we should forget using elog at all and just emit the trace with fprintf(stderr). That seems like it would decrease the odds of trouble by about an order of magnitude. It would make it more painful to collect the trace in some logging setups, of course. regards, tom lane