mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-11-27 07:21:09 +08:00
6b11a46878
Hostile objects located within the installation-time search_path could
capture references in an extension's installation or upgrade script.
If the extension is being installed with superuser privileges, this
opens the door to privilege escalation. While such hazards have existed
all along, their urgency increases with the v13 "trusted extensions"
feature, because that lets a non-superuser control the installation path
for a superuser-privileged script. Therefore, make a number of changes
to make such situations more secure:
* Tweak the construction of the installation-time search_path to ensure
that references to objects in pg_catalog can't be subverted; and
explicitly add pg_temp to the end of the path to prevent attacks using
temporary objects.
* Disable check_function_bodies within installation/upgrade scripts,
so that any security gaps in SQL-language or PL-language function bodies
cannot create a risk of unwanted installation-time code execution.
* Adjust lookup of type input/receive functions and join estimator
functions to complain if there are multiple candidate functions. This
prevents capture of references to functions whose signature is not the
first one checked; and it's arguably more user-friendly anyway.
* Modify various contrib upgrade scripts to ensure that catalog
modification queries are executed with secure search paths. (These
are in-place modifications with no extension version changes, since
it is the update process itself that is at issue, not the end result.)
Extensions that depend on other extensions cannot be made fully secure
by these methods alone; therefore, revert the "trusted" marking that
commit eb67623c9
applied to earthdistance and hstore_plperl, pending
some better solution to that set of issues.
Also add documentation around these issues, to help extension authors
write secure installation scripts.
Patch by me, following an observation by Andres Freund; thanks
to Noah Misch for review.
Security: CVE-2020-14350
159 lines
9.4 KiB
PL/PgSQL
159 lines
9.4 KiB
PL/PgSQL
/* contrib/tsearch2/tsearch2--unpackaged--1.0.sql */
|
|
|
|
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
|
|
\echo Use "CREATE EXTENSION tsearch2 FROM unpackaged" to load this file. \quit
|
|
|
|
ALTER EXTENSION tsearch2 ADD type @extschema@.tsvector;
|
|
ALTER EXTENSION tsearch2 ADD type @extschema@.tsquery;
|
|
ALTER EXTENSION tsearch2 ADD type @extschema@.gtsvector;
|
|
ALTER EXTENSION tsearch2 ADD type gtsq;
|
|
ALTER EXTENSION tsearch2 ADD function lexize(oid,text);
|
|
ALTER EXTENSION tsearch2 ADD function lexize(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function lexize(text);
|
|
ALTER EXTENSION tsearch2 ADD function set_curdict(integer);
|
|
ALTER EXTENSION tsearch2 ADD function set_curdict(text);
|
|
ALTER EXTENSION tsearch2 ADD function dex_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function dex_lexize(internal,internal,integer);
|
|
ALTER EXTENSION tsearch2 ADD function snb_en_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function snb_lexize(internal,internal,integer);
|
|
ALTER EXTENSION tsearch2 ADD function snb_ru_init_koi8(internal);
|
|
ALTER EXTENSION tsearch2 ADD function snb_ru_init_utf8(internal);
|
|
ALTER EXTENSION tsearch2 ADD function snb_ru_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function spell_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function spell_lexize(internal,internal,integer);
|
|
ALTER EXTENSION tsearch2 ADD function syn_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function syn_lexize(internal,internal,integer);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.thesaurus_init(internal);
|
|
ALTER EXTENSION tsearch2 ADD function thesaurus_lexize(internal,internal,integer,internal);
|
|
ALTER EXTENSION tsearch2 ADD type tokentype;
|
|
ALTER EXTENSION tsearch2 ADD function token_type(integer);
|
|
ALTER EXTENSION tsearch2 ADD function token_type(text);
|
|
ALTER EXTENSION tsearch2 ADD function token_type();
|
|
ALTER EXTENSION tsearch2 ADD function set_curprs(integer);
|
|
ALTER EXTENSION tsearch2 ADD function set_curprs(text);
|
|
ALTER EXTENSION tsearch2 ADD type tokenout;
|
|
ALTER EXTENSION tsearch2 ADD function parse(oid,text);
|
|
ALTER EXTENSION tsearch2 ADD function parse(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function parse(text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.prsd_start(internal,integer);
|
|
ALTER EXTENSION tsearch2 ADD function prsd_getlexeme(internal,internal,internal);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.prsd_end(internal);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.prsd_lextype(internal);
|
|
ALTER EXTENSION tsearch2 ADD function prsd_headline(internal,internal,internal);
|
|
ALTER EXTENSION tsearch2 ADD function set_curcfg(integer);
|
|
ALTER EXTENSION tsearch2 ADD function set_curcfg(text);
|
|
ALTER EXTENSION tsearch2 ADD function show_curcfg();
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.length(tsvector);
|
|
ALTER EXTENSION tsearch2 ADD function to_tsvector(oid,text);
|
|
ALTER EXTENSION tsearch2 ADD function to_tsvector(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.to_tsvector(text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.strip(tsvector);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.setweight(tsvector,"char");
|
|
ALTER EXTENSION tsearch2 ADD function concat(tsvector,tsvector);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.querytree(tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function to_tsquery(oid,text);
|
|
ALTER EXTENSION tsearch2 ADD function to_tsquery(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.to_tsquery(text);
|
|
ALTER EXTENSION tsearch2 ADD function plainto_tsquery(oid,text);
|
|
ALTER EXTENSION tsearch2 ADD function plainto_tsquery(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.plainto_tsquery(text);
|
|
ALTER EXTENSION tsearch2 ADD function tsearch2();
|
|
ALTER EXTENSION tsearch2 ADD function rank(real[],tsvector,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rank(real[],tsvector,tsquery,integer);
|
|
ALTER EXTENSION tsearch2 ADD function rank(tsvector,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rank(tsvector,tsquery,integer);
|
|
ALTER EXTENSION tsearch2 ADD function rank_cd(real[],tsvector,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rank_cd(real[],tsvector,tsquery,integer);
|
|
ALTER EXTENSION tsearch2 ADD function rank_cd(tsvector,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rank_cd(tsvector,tsquery,integer);
|
|
ALTER EXTENSION tsearch2 ADD function headline(oid,text,tsquery,text);
|
|
ALTER EXTENSION tsearch2 ADD function headline(oid,text,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function headline(text,text,tsquery,text);
|
|
ALTER EXTENSION tsearch2 ADD function headline(text,text,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function headline(text,tsquery,text);
|
|
ALTER EXTENSION tsearch2 ADD function headline(text,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD operator family gist_tsvector_ops using gist;
|
|
ALTER EXTENSION tsearch2 ADD operator class gist_tsvector_ops using gist;
|
|
ALTER EXTENSION tsearch2 ADD type statinfo;
|
|
ALTER EXTENSION tsearch2 ADD function stat(text);
|
|
ALTER EXTENSION tsearch2 ADD function stat(text,text);
|
|
ALTER EXTENSION tsearch2 ADD function reset_tsearch();
|
|
ALTER EXTENSION tsearch2 ADD function get_covers(tsvector,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD type tsdebug;
|
|
ALTER EXTENSION tsearch2 ADD function _get_parser_from_curcfg();
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.ts_debug(text);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.numnode(tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.tsquery_and(tsquery,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.tsquery_or(tsquery,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.tsquery_not(tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rewrite(tsquery,text);
|
|
ALTER EXTENSION tsearch2 ADD function rewrite(tsquery,tsquery,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rewrite_accum(tsquery,tsquery[]);
|
|
ALTER EXTENSION tsearch2 ADD function rewrite_finish(tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function rewrite(tsquery[]);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.tsq_mcontains(tsquery,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD function @extschema@.tsq_mcontained(tsquery,tsquery);
|
|
ALTER EXTENSION tsearch2 ADD operator family gist_tp_tsquery_ops using gist;
|
|
ALTER EXTENSION tsearch2 ADD operator class gist_tp_tsquery_ops using gist;
|
|
ALTER EXTENSION tsearch2 ADD operator family gin_tsvector_ops using gin;
|
|
ALTER EXTENSION tsearch2 ADD operator class gin_tsvector_ops using gin;
|
|
ALTER EXTENSION tsearch2 ADD operator family @extschema@.tsvector_ops using btree;
|
|
ALTER EXTENSION tsearch2 ADD operator class @extschema@.tsvector_ops using btree;
|
|
ALTER EXTENSION tsearch2 ADD operator family @extschema@.tsquery_ops using btree;
|
|
ALTER EXTENSION tsearch2 ADD operator class @extschema@.tsquery_ops using btree;
|
|
|
|
-- tsearch2 relies on the core functions gin_extract_tsvector,
|
|
-- gin_extract_tsquery, and gin_tsquery_consistent, which changed signature in
|
|
-- 9.1. To support upgrading, pg_catalog contains entries for these functions
|
|
-- with both the old and new signatures, and the former is what would have
|
|
-- been added to our opclass during initial restore of a 9.0 dump script.
|
|
-- Avert your eyes while we hack the pg_amproc entries to make them link to
|
|
-- the new forms ...
|
|
|
|
DO LANGUAGE plpgsql
|
|
$$
|
|
DECLARE
|
|
my_schema_unquoted pg_catalog.text := pg_catalog.current_schema();
|
|
my_schema pg_catalog.text := pg_catalog.quote_ident(pg_catalog.current_schema());
|
|
old_path pg_catalog.text := pg_catalog.current_setting('search_path');
|
|
BEGIN
|
|
-- for safety, transiently set search_path to just pg_catalog+pg_temp
|
|
PERFORM pg_catalog.set_config('search_path', 'pg_catalog, pg_temp', true);
|
|
|
|
UPDATE pg_catalog.pg_amproc
|
|
SET amproc = 'pg_catalog.gin_extract_tsvector(pg_catalog.tsvector,internal,internal)'::pg_catalog.regprocedure
|
|
WHERE amprocfamily =
|
|
(SELECT oid FROM pg_catalog.pg_opfamily WHERE opfname = 'gin_tsvector_ops' AND
|
|
opfnamespace = (SELECT oid FROM pg_catalog.pg_namespace
|
|
WHERE nspname = my_schema_unquoted))
|
|
AND amproclefttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocrighttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocnum = 2
|
|
AND amproc = 'pg_catalog.gin_extract_tsvector(pg_catalog.tsvector,internal)'::pg_catalog.regprocedure;
|
|
|
|
UPDATE pg_catalog.pg_amproc
|
|
SET amproc = 'pg_catalog.gin_extract_tsquery(pg_catalog.tsquery,internal,smallint,internal,internal,internal,internal)'::pg_catalog.regprocedure
|
|
WHERE amprocfamily =
|
|
(SELECT oid FROM pg_catalog.pg_opfamily WHERE opfname = 'gin_tsvector_ops' AND
|
|
opfnamespace = (SELECT oid FROM pg_catalog.pg_namespace
|
|
WHERE nspname = my_schema_unquoted))
|
|
AND amproclefttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocrighttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocnum = 3
|
|
AND amproc = 'pg_catalog.gin_extract_tsquery(pg_catalog.tsquery,internal,smallint,internal,internal)'::pg_catalog.regprocedure;
|
|
|
|
UPDATE pg_catalog.pg_amproc
|
|
SET amproc = 'pg_catalog.gin_tsquery_consistent(internal,smallint,pg_catalog.tsquery,integer,internal,internal,internal,internal)'::pg_catalog.regprocedure
|
|
WHERE amprocfamily =
|
|
(SELECT oid FROM pg_catalog.pg_opfamily WHERE opfname = 'gin_tsvector_ops' AND
|
|
opfnamespace = (SELECT oid FROM pg_catalog.pg_namespace
|
|
WHERE nspname = my_schema_unquoted))
|
|
AND amproclefttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocrighttype = 'pg_catalog.tsvector'::pg_catalog.regtype
|
|
AND amprocnum = 4
|
|
AND amproc = 'pg_catalog.gin_tsquery_consistent(internal,smallint,pg_catalog.tsquery,integer,internal,internal)'::pg_catalog.regprocedure;
|
|
|
|
PERFORM pg_catalog.set_config('search_path', old_path, true);
|
|
END
|
|
$$;
|