This is an automated email from the ASF dual-hosted git repository.

reshke pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 879fbfca96d91493deb16d6267c7baeda676e53c
Author: Nathan Bossart <[email protected]>
AuthorDate: Mon Aug 10 06:38:36 2026 -0700

    Check for USAGE privilege on the subtype in CREATE TYPE AS RANGE.
    
    This omission allowed roles without USAGE on a type to create range
    types that depend on it, which could prevent the owner from
    changing the type later.
    
    Reported-by: Jingzhou Fu <[email protected]>
    Author: Nathan Bossart <[email protected]>
    Reviewed-by: Noah Misch <[email protected]>
    Reviewed-by: Robert Haas <[email protected]>
    Security: CVE-2026-6470
    Backpatch-through: 14
---
 doc/src/sgml/ref/create_type.sgml        |  5 +++++
 src/backend/commands/typecmds.c          |  4 ++++
 src/test/regress/expected/rangetypes.out | 15 +++++++++++++++
 src/test/regress/sql/rangetypes.sql      | 14 ++++++++++++++
 4 files changed, 38 insertions(+)

diff --git a/doc/src/sgml/ref/create_type.sgml 
b/doc/src/sgml/ref/create_type.sgml
index 3ea3d661bf8..3327c8b8b01 100644
--- a/doc/src/sgml/ref/create_type.sgml
+++ b/doc/src/sgml/ref/create_type.sgml
@@ -189,6 +189,11 @@ CREATE TYPE <replaceable 
class="parameter">name</replaceable>
     type name.  Otherwise, the multirange type name is formed by appending a
     <literal>_multirange</literal> suffix to the range type name.
    </para>
+
+   <para>
+    To be able to create a range type, you must have <literal>USAGE</literal>
+    privilege on the subtype.
+   </para>
   </refsect2>
 
   <refsect2>
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index fb47f3275ce..612e5083bc4 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -1597,6 +1597,10 @@ DefineRange(CreateRangeStmt *stmt)
                                 errmsg("range subtype cannot be %s",
                                                format_type_be(rangeSubtype))));
 
+       aclresult = pg_type_aclcheck(rangeSubtype, GetUserId(), ACL_USAGE);
+       if (aclresult != ACLCHECK_OK)
+               aclcheck_error_type(aclresult, rangeSubtype);
+
        /* Identify subopclass */
        rangeSubOpclass = findRangeSubOpclass(rangeSubOpclassName, 
rangeSubtype);
 
diff --git a/src/test/regress/expected/rangetypes.out 
b/src/test/regress/expected/rangetypes.out
index 4e6f580efe6..bfeb57dd4a9 100644
--- a/src/test/regress/expected/rangetypes.out
+++ b/src/test/regress/expected/rangetypes.out
@@ -1495,6 +1495,21 @@ ERROR:  range lower bound must be less than or equal to 
range upper bound
 LINE 1: select '[2010-01-01 01:00:00 -08, 2010-01-01 02:00:00 -05)':...
                ^
 set timezone to default;
+-- CREATE TYPE AS RANGE checks for USAGE on subtype
+CREATE ROLE regress_subtype;
+CREATE TYPE mytype AS (a INT, b INT);
+REVOKE USAGE ON TYPE mytype FROM PUBLIC;
+SET ROLE regress_subtype;
+CREATE TYPE myrange AS RANGE (subtype = mytype);
+ERROR:  permission denied for type mytype
+RESET ROLE;
+GRANT USAGE ON TYPE mytype TO regress_subtype;
+SET ROLE regress_subtype;
+CREATE TYPE myrange AS RANGE (subtype = mytype);
+RESET ROLE;
+DROP TYPE mytype CASCADE;
+NOTICE:  drop cascades to type myrange
+DROP ROLE regress_subtype;
 --
 -- Test user-defined range of floats
 --
diff --git a/src/test/regress/sql/rangetypes.sql 
b/src/test/regress/sql/rangetypes.sql
index 50707f35529..f62eb8d0837 100644
--- a/src/test/regress/sql/rangetypes.sql
+++ b/src/test/regress/sql/rangetypes.sql
@@ -429,6 +429,20 @@ select '[2010-01-01 01:00:00 -05, 2010-01-01 02:00:00 
-08)'::tstzrange;
 select '[2010-01-01 01:00:00 -08, 2010-01-01 02:00:00 -05)'::tstzrange;
 set timezone to default;
 
+-- CREATE TYPE AS RANGE checks for USAGE on subtype
+CREATE ROLE regress_subtype;
+CREATE TYPE mytype AS (a INT, b INT);
+REVOKE USAGE ON TYPE mytype FROM PUBLIC;
+SET ROLE regress_subtype;
+CREATE TYPE myrange AS RANGE (subtype = mytype);
+RESET ROLE;
+GRANT USAGE ON TYPE mytype TO regress_subtype;
+SET ROLE regress_subtype;
+CREATE TYPE myrange AS RANGE (subtype = mytype);
+RESET ROLE;
+DROP TYPE mytype CASCADE;
+DROP ROLE regress_subtype;
+
 --
 -- Test user-defined range of floats
 --


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to