Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e4PcS-0003xD-3U for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Oct 2017 11:01:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e4PcR-0006QR-MT for pgsql-hackers@arkaria.postgresql.org; Tue, 17 Oct 2017 11:01:07 +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.84_2) (envelope-from ) id 1e4Pap-0001h7-83 for pgsql-hackers@postgresql.org; Tue, 17 Oct 2017 10:59:27 +0000 Received: from smtprelay0050.b.hostedemail.com ([64.98.42.50] helo=smtprelay.b.hostedemail.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e4Pah-00078t-Pu for pgsql-hackers@postgresql.org; Tue, 17 Oct 2017 10:59:25 +0000 Received: from filter.hostedemail.com (10.5.19.248.rfc1918.com [10.5.19.248]) by smtprelay05.b.hostedemail.com (Postfix) with ESMTP id 8890832AECF; Tue, 17 Oct 2017 10:59:18 +0000 (UTC) X-Session-Marker: 616C76686572726540616C76682E6E6F2D69702E6F7267 X-Spam-Summary: 50,0,0,,d41d8cd98f00b204,alvherre@alvh.no-ip.org,:::,RULES_HIT:41:355:379:599:871:967:973:988:989:1260:1311:1312:1313:1314:1345:1359:1437:1515:1516:1518:1519:1534:1541:1575:1594:1595:1596:1711:1730:1747:1764:1777:1792:2393:2525:2560:2563:2682:2685:2689:2692:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3352:3865:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:5007:6261:6748:7281:9025:9121:10004:10400:10848:11026:11473:11604:11658:11914:12043:12438:12555:12663:12986:13439:13894:13895:14658:14721:21080:21451:21627:30025:30054:30070:30075:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:3,LUA_SUMMARY:none X-HE-Tag: twig58_8b68c70285e25 X-Filterd-Recvd-Size: 4283 Received: from alvin.alvh.no-ip.org (241.red-88-12-57.staticip.rima-tde.net [88.12.57.241]) (Authenticated sender: alvherre@alvh.no-ip.org) by omf06.b.hostedemail.com (Postfix) with ESMTPA; Tue, 17 Oct 2017 10:59:17 +0000 (UTC) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 38F709F8; Tue, 17 Oct 2017 12:59:16 +0200 (CEST) Date: Tue, 17 Oct 2017 12:59:16 +0200 From: Alvaro Herrera To: Justin Pryzby Cc: pgsql-hackers@postgresql.org Subject: Re: SIGSEGV in BRIN autosummarize Message-ID: <20171017105916.3rvmznxnuphn3uph@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="bbhsuy37ykwidops" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20171014224220.GB22678@telsasoft.com> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --bbhsuy37ykwidops Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Justin Pryzby wrote: > #1 0x00000000006a52e9 in perform_work_item (workitem=0x7f8ad1f94824) at autovacuum.c:2676 > cur_datname = 0x298c740 "no 1 :vartype 1184 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 146} {CONST :consttype 1184 :consttypmod -1 :constcollid 0 :constlen 8 :constbyval true :constisnull fal"... > cur_nspname = 0x298c728 "s ({VAR :varno 1 :varattno 1 :vartype 1184 :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 1 :location 146} {CONST :consttype 1184 :consttypmod -1 :constcollid 0 :constlen 8 :constbyv"... > cur_relname = 0x298cd68 "cdrs_eric_msc_sms_2017_10_14_startofcharge_idx" > __func__ = "perform_work_item" cur_datname here seems corrupted -- it points halfway into cur_nspname, which is also a corrupt value. And I think that's because we're not checking that the namespace OID is a valid value before calling get_namespace_name on it. And I'm betting that these values are all not what we expect, because we're not checking that we're in the correct database before trying to execute the work item. I don't quite understand how this results in an invalid string rather than just a NULL, as I would have expected. Anyway, can give this patch a try? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --bbhsuy37ykwidops Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-autovacuum-workitems.patch" From 0a53aaf589dfdbd2f25ae2ee36323d77c2910a60 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 17 Oct 2017 12:58:38 +0200 Subject: [PATCH] Fix autovacuum workitems --- src/backend/postmaster/autovacuum.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 776b1c0a9d..83366b862c 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -2525,6 +2525,8 @@ deleted: continue; if (workitem->avw_active) continue; + if (workitem->avw_database != MyDatabaseId) + continue; /* claim this one, and release lock while performing it */ workitem->avw_active = true; @@ -2592,6 +2594,7 @@ perform_work_item(AutoVacuumWorkItem *workitem) char *cur_datname = NULL; char *cur_nspname = NULL; char *cur_relname = NULL; + Oid cur_nspoid; /* * Note we do not store table info in MyWorkerInfo, since this is not @@ -2607,9 +2610,12 @@ perform_work_item(AutoVacuumWorkItem *workitem) */ cur_relname = get_rel_name(workitem->avw_relation); - cur_nspname = get_namespace_name(get_rel_namespace(workitem->avw_relation)); + cur_nspoid = get_rel_namespace(workitem->avw_relation); + if (!cur_relname || !OidIsValid(cur_nspoid)) + goto deleted2; + cur_nspname = get_namespace_name(cur_nspoid); cur_datname = get_database_name(MyDatabaseId); - if (!cur_relname || !cur_nspname || !cur_datname) + if (!cur_nspname || !cur_datname) goto deleted2; autovac_report_workitem(workitem, cur_nspname, cur_datname); -- 2.11.0 --bbhsuy37ykwidops Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --bbhsuy37ykwidops--