1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Avoid repeated name lookups during table and index DDL.

If the name lookups come to different conclusions due to concurrent
activity, we might perform some parts of the DDL on a different table
than other parts.  At least in the case of CREATE INDEX, this can be
used to cause the permissions checks to be performed against a
different table than the index creation, allowing for a privilege
escalation attack.

This changes the calling convention for DefineIndex, CreateTrigger,
transformIndexStmt, transformAlterTableStmt, CheckIndexCompatible
(in 9.2 and newer), and AlterTable (in 9.1 and older).  In addition,
CheckRelationOwnership is removed in 9.2 and newer and the calling
convention is changed in older branches.  A field has also been added
to the Constraint node (FkConstraint in 8.4).  Third-party code calling
these functions or using the Constraint node will require updating.

Report by Andres Freund.  Patch by Robert Haas and Andres Freund,
reviewed by Tom Lane.

Security: CVE-2014-0062
This commit is contained in:
Robert Haas
2014-02-17 09:33:31 -05:00
parent 338daafe01
commit b5c574399e
20 changed files with 233 additions and 130 deletions

View File

@@ -27,6 +27,7 @@
#include "bootstrap/bootstrap.h"
#include "catalog/catalog.h"
#include "catalog/heap.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "catalog/pg_attribute.h"
#include "catalog/pg_authid.h"
@@ -279,9 +280,14 @@ Boot_InsertStmt:
Boot_DeclareIndexStmt:
XDECLARE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{
Oid relationId;
do_start();
DefineIndex(makeRangeVar(NULL, $6, -1),
relationId = RangeVarGetRelid(makeRangeVar(NULL, $6, -1),
false);
DefineIndex(relationId,
$3,
$4,
$8,
@@ -297,9 +303,14 @@ Boot_DeclareIndexStmt:
Boot_DeclareUniqueIndexStmt:
XDECLARE UNIQUE INDEX boot_ident oidspec ON boot_ident USING boot_ident LPAREN boot_index_params RPAREN
{
Oid relationId;
do_start();
DefineIndex(makeRangeVar(NULL, $7, -1),
relationId = RangeVarGetRelid(makeRangeVar(NULL, $7, -1),
false);
DefineIndex(relationId,
$4,
$5,
$9,