]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Require execute permission on the trigger function for CREATE TRIGGER.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Feb 2012 20:39:20 +0000 (15:39 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 23 Feb 2012 20:39:20 +0000 (15:39 -0500)
This check was overlooked when we added function execute permissions to the
system years ago.  For an ordinary trigger function it's not a big deal,
since trigger functions execute with the permissions of the table owner,
so they couldn't do anything the user issuing the CREATE TRIGGER couldn't
have done anyway.  However, if a trigger function is SECURITY DEFINER,
that is not the case.  The lack of checking would allow another user to
install it on his own table and then invoke it with, essentially, forged
input data; which the trigger function is unlikely to realize, so it might
do something undesirable, for instance insert false entries in an audit log
table.

Reported by Dinesh Kumar, patch by Robert Haas

Security: CVE-2012-0866

doc/src/sgml/ref/create_trigger.sgml
src/backend/commands/trigger.c

index 9cbdcf91651503a2044b7ce5f4726ace10aed3f6..d799e466129e041270d8b8520aaf9adca3d523af 100644 (file)
@@ -176,7 +176,8 @@ CREATE TRIGGER <replaceable class="PARAMETER">name</replaceable> { BEFORE | AFTE
 
   <para>
    To create a trigger on a table, the user must have the
-   <literal>TRIGGER</literal> privilege on the table.
+   <literal>TRIGGER</literal> privilege on the table.  The user must
+   also have <literal>EXECUTE</literal> privilege on the trigger function.
   </para>
 
   <para>
index 2fc35eed29bbf3ccbaf3eb676af5617719620dc0..ebc1cce09e9fd619ee71d4723a8ac10dbdd29c33 100644 (file)
@@ -188,6 +188,10 @@ CreateTrigger(CreateTrigStmt *stmt, Oid constraintOid)
         * Find and validate the trigger function.
         */
        funcoid = LookupFuncName(stmt->funcname, 0, fargtypes, false);
+       aclresult = pg_proc_aclcheck(funcoid, GetUserId(), ACL_EXECUTE);
+       if (aclresult != ACLCHECK_OK)
+               aclcheck_error(aclresult, ACL_KIND_PROC,
+                                          NameListToString(stmt->funcname));
        funcrettype = get_func_rettype(funcoid);
        if (funcrettype != TRIGGEROID)
        {