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 1oDYjd-0000OQ-SS for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:57:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oDYjc-0000DF-Ni for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Jul 2022 21:57:00 +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 1oDYjc-0000D3-Cf for pgsql-hackers@lists.postgresql.org; Mon, 18 Jul 2022 21:57:00 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oDYjV-0001PD-DD for pgsql-hackers@postgresql.org; Mon, 18 Jul 2022 21:57:00 +0000 Received: by mail-pl1-x630.google.com with SMTP id g17so10264759plh.2 for ; Mon, 18 Jul 2022 14:56:53 -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=iMOCANC/OvtbYXwPPjMDMt9EEEnwRX2qoNf8WzXO630=; b=Uldgh5/XU3zUfumymCQmEP+fXnmS6vr+BObywLi9zm5xTDG4RJDVHqOuEYUKCjJ5Lx ahViBhELvtDsLmmqtvTjh2BSuR9UuLw24smCJhmvUbH1xS/6eaqXa47e1pIA9SmBHde4 YV6iZ2RRV7BrH4vHgQCf+i1kIxDYGIWkmZmjDl/jmInSii1SISIq3DHRi+7q4T7tDt7A p+x3iuRd6e6Kwornj2SU2kYQNfyVie6mJK4eyg0TZ+FR0QVs1Q78bX1KPkcMjQGZSQW5 S1J4Aw048vUU2YKo6G9sEiM4qtAH94nrBqJxPih8huMOh9L4OZUgTWwwn6pXIXuDKwHL TxiA== 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=iMOCANC/OvtbYXwPPjMDMt9EEEnwRX2qoNf8WzXO630=; b=vjNcF3m3JZEDbwcwu294beDOVLhV4u/QxGRN7LIBd8WDI4xb/kASZiB7uqujwrRM5+ GLSpjut7pYCMT40oD3gEq8WkGdK4SVvTrNGbzR2sk9LxCXdxL97x++R80L+4S4Mdb61i SLO5NnzEIInq8BUJwwGjlqKoJDCrYEhK6E2f7IHeZGTHCtiTq8BiRRN/cm+zwi5ZjZgL yfeBg2ao3BAx2aUwPZfrqcYtuaOx6Tx5Qfq1fsvue4uD8u+dPQLAGcVs/cZ++kk3CEKl zgJiXTm4dqJhmVGLXHLw/sBCgPXz6rXkkfGWdsG+X/d5cDlj1wxPFWKrFkinHU27mpJG 8RXg== X-Gm-Message-State: AJIora//TflueXXvE0Vykoz7guEd+HC3+iHwzFQuNopadXb8K7GCNZm9 AITSakUVQB5CGwL7r81v3Z8= X-Google-Smtp-Source: AGRyM1uHD1Zs5Hnl35GgUlJfHrv3J7XJxCyoWAWudcHdF6fqZ4uCqv5/lXS5pl3wUmNKidpZR/tdKw== X-Received: by 2002:a17:90b:3b90:b0:1ef:eb4a:fbd with SMTP id pc16-20020a17090b3b9000b001efeb4a0fbdmr35299475pjb.2.1658181411427; Mon, 18 Jul 2022 14:56:51 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id o2-20020a62cd02000000b0052942bde65bsm9733729pfg.30.2022.07.18.14.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 14:56:50 -0700 (PDT) Date: Mon, 18 Jul 2022 14:56:49 -0700 From: Nathan Bossart To: Tom Lane Cc: Michael Paquier , pgsql-hackers@postgresql.org Subject: Re: pg_parameter_aclcheck() and trusted extensions Message-ID: <20220718215649.GA3699123@nathanxps13> References: <20220706224727.GA2158260@nathanxps13> <2995921.1657212060@sss.pgh.pa.us> <3126292.1657828950@sss.pgh.pa.us> <20220714215225.GA3173833@nathanxps13> <3159281.1657836225@sss.pgh.pa.us> <20220714225735.GB3173833@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg" Content-Disposition: inline In-Reply-To: <20220714225735.GB3173833@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jul 14, 2022 at 03:57:35PM -0700, Nathan Bossart wrote: > However, ALTER ROLE RESET ALL will be blocked, while resetting only the > individual GUC will go through. > > postgres=> ALTER ROLE other RESET ALL; > ALTER ROLE > postgres=> SELECT * FROM pg_db_role_setting; > setdatabase | setrole | setconfig > -------------+---------+------------------------- > 0 | 16385 | {zero_damaged_pages=on} > (1 row) > > postgres=> ALTER ROLE other RESET zero_damaged_pages; > ALTER ROLE > postgres=> SELECT * FROM pg_db_role_setting; > setdatabase | setrole | setconfig > -------------+---------+----------- > (0 rows) > > I think this is because GUCArrayReset() is the only caller of > validate_option_array_item() that sets skipIfNoPermissions to true. The > others fall through to set_config_option(), which does a > pg_parameter_aclcheck(). So, you are right. Here's a small patch that seems to fix this case. However, I wonder if a better way to fix this is to provide a way to stop set_config_option() from throwing errors (e.g., setting elevel to -1). That way, we could remove the manual permissions checks in favor of always using the real ones, which might help prevent similar bugs in the future. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --gKMricLos+KVdGMg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="fix_reset_all_for_gucs.patch" diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 0328029d43..fbc1014824 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -11689,7 +11689,8 @@ validate_option_array_item(const char *name, const char *value, * We cannot do any meaningful check on the value, so only permissions * are useful to check. */ - if (superuser()) + if (superuser() || + pg_parameter_aclcheck(gconf->name, GetUserId(), ACL_SET) == ACLCHECK_OK) return true; if (skipIfNoPermissions) return false; @@ -11703,6 +11704,8 @@ validate_option_array_item(const char *name, const char *value, /* ok */ ; else if (gconf->context == PGC_SUSET && superuser()) /* ok */ ; + else if (pg_parameter_aclcheck(gconf->name, GetUserId(), ACL_SET) == ACLCHECK_OK) + /* ok */ ; else if (skipIfNoPermissions) return false; /* if a permissions error should be thrown, let set_config_option do it */ --gKMricLos+KVdGMg--