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 1oEefN-00065e-43 for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 22:29:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oEefL-00081i-Op for pgsql-hackers@arkaria.postgresql.org; Thu, 21 Jul 2022 22:29:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oEefL-00081V-Fk for pgsql-hackers@lists.postgresql.org; Thu, 21 Jul 2022 22:29:07 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oEefJ-0005Bm-1u for pgsql-hackers@postgresql.org; Thu, 21 Jul 2022 22:29:06 +0000 Received: by mail-pl1-x630.google.com with SMTP id q5so3081474plr.11 for ; Thu, 21 Jul 2022 15:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=q5FLOrpXDKq5fYa2C5NpzLQQnsn47kKnyDrg/DN0jUI=; b=a58u8r8XSD1z2zcrfz4GcKQm4PgfDJqu8AcUQ4ai1vyrt1cAWIq1+Kniu5ZiigfKiM gYSn7jMJ2ouMTLXKnO8YKaIAgThsOROygYBVAe3EaQBP/Goai+VGee02BXiAjqo0JC4L /TkIbwUXZkbUz84MhTIqUXjRXlAq/1LvbC3n8aBUym4j/iBNJ6WWHrP9xDEpfQAQIhga fZwpO9H+ghmWbTrR3eT/60X7vmqUpPzwjJdMma/rWfLq6ZZoW6KuP0DKxdXAst0DPYU6 +qtuiNoQ6xwrj4DrAtjYbcg1HNQTU2rmK6BevwmDCkdTRJIsp64bzFxBUwdx82JXBDQk qeOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=q5FLOrpXDKq5fYa2C5NpzLQQnsn47kKnyDrg/DN0jUI=; b=oLO3qs/H93YgI59PkezJh83Etk5YWIVLk2BxZMUiHJmnvJYqJWd6f9vx6K5/vBI24c Q9Dee5WrH1To003tokN4RIa9v1kbruDxEc/JH9B77ChiOY8Pwyp7cDtxXiQhJeyMR0lx BDr2jYa4EqByX2O+yGoxpt4wSSVpybD67C8Q0aNeXd231Gs3o8L2IMY9jvlQsWkG9A01 kVvebJ3H0AgnBGVxoJayhiYpGEOzZ+86NmuHRjXBI6R7GrfFL9qvekNSX6H5f0TxqKiQ hJyN6vth3bV2mlsZ2oevbLaOpWkEAlC8MxBP4TDv/mVAvQf4rf/TVkieYhD3QofpQpwt WDEQ== X-Gm-Message-State: AJIora+cnHaALTXF26Aeq2PdbKWe+tbtoWmHYFo9AuzsYi2/Nxm77AJv FHRXdoIGuuGIh8XengJbbAw= X-Google-Smtp-Source: AGRyM1v7gAFi78TkOWaoVaXZB8lVm2J41MStePS9MLuy/FpvzgEf1FUgo7DfuwvT6ijHCGFrdvIpVQ== X-Received: by 2002:a17:902:ec8b:b0:16c:20d4:eb3 with SMTP id x11-20020a170902ec8b00b0016c20d40eb3mr643641plg.40.1658442543779; Thu, 21 Jul 2022 15:29:03 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id l6-20020a170903244600b00163de9e9342sm2257456pls.17.2022.07.21.15.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 15:29:02 -0700 (PDT) Date: Thu, 21 Jul 2022 15:29:00 -0700 From: Nathan Bossart To: Tom Lane Cc: Gurjeet Singh , Postgres Hackers Subject: Re: Fwd: Unprivileged user can induce crash by using an SUSET param in PGOPTIONS Message-ID: <20220721222900.GA3813377@nathanxps13> References: <20220705174938.GB2566600@rfd.leadboat.com> <335170.1658439851@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <335170.1658439851@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jul 21, 2022 at 05:44:11PM -0400, Tom Lane wrote: > Right. So there are basically two things we could do about this: > > 1. set_config_option could decline to call pg_parameter_aclcheck > if not IsTransactionState(), instead failing the assignment. > This isn't a great answer because it would result in disallowing > GUC assignments that users might expect to work. > > 2. We could move process_session_preload_libraries() to someplace > where a transaction is in progress -- probably, relocate it to > inside InitPostgres(). > > I'm inclined to think that #2 is a better long-term solution, > because it'd allow you to session-preload libraries that expect > to be able to do database access during _PG_init. (Right now > that'd fail with the same sort of symptoms seen here.) But > there's no denying that this might have surprising side-effects > for extensions that weren't expecting such a change. > > It could also be reasonable to do both #1 and #2, with the idea > that #1 might save us from crashing if there are any other > code paths where we can reach that pg_parameter_aclcheck call > outside a transaction. > > Thoughts? I wrote up a small patch along the same lines as #2 before seeing this message. It simply ensures that process_session_preload_libraries() is called within a transaction. I don't have a strong opinion about doing it this way versus moving this call somewhere else as you proposed, but I'd agree that #2 is a better long-term solution than #1. AFAICT shared_preload_libraries, even with EXEC_BACKEND, should not have the same problem. I'm not sure whether we should be worried about libraries that are already creating transactions in their _PG_init() functions. Off the top of my head, I don't recall seeing anything like that. Even if it does impact some extensions, it doesn't seem like it'd be too much trouble to fix. diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 8ba1c170f0..fd471d74a3 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -4115,8 +4115,15 @@ PostgresMain(const char *dbname, const char *username) /* * process any libraries that should be preloaded at backend start (this * likewise can't be done until GUC settings are complete) + * + * If the user provided a setting at session startup for a custom GUC + * defined by one of these libraries, we might need syscache access when + * evaluating whether she has permission to set it, so do this step within + * a transaction. */ + StartTransactionCommand(); process_session_preload_libraries(); + CommitTransactionCommand(); /* * Send this backend's cancellation info to the frontend. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com