pgsql: Disallow converting a table to a view within an outer SQL comman

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Disallow converting a table to a view within an outer SQL comman
Дата
Msg-id E1s1t4C-000pqU-Vq@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Disallow converting a table to a view within an outer SQL command.

We have long disallowed all forms of ALTER TABLE if the table is
already opened by some outer SQL command in the same session.
This has the same purpose as obtaining AccessExclusiveLock, but
since a session's own locks don't conflict the lock only blocks use
of the table by other sessions, not our own.  Without this check,
the ALTER might confuse the outer SQL command since any previous
inspection of the table would potentially become invalid.

However, the RelisBecomingView code path in DefineQueryRewrite never
got that memo, and assumed that AccessExclusiveLock is sufficient
for performing something morally equivalent to a rather invasive
ALTER TABLE.  Unsurprisingly, this can confuse an outer command
that is trying to do something with the table.

This was submitted as a security issue, but the security team
has been unable to identify any consequence worse than a null
pointer dereference (from trying to access rd_tableam methods
that the relation no longer has).  Therefore, in accordance
with our usual policy, it's not security material and should
just be fixed as a routine bug.

Fix by disallowing the operation if the table is open locally,
exactly as ALTER TABLE does it.

Per an anonymous security researcher, via Bundesamt für Sicherheit
in der Informationstechnik.

Patch v12-v15 only.  In v16 and later, we removed this code
altogether (cf. commit b23cd185f), so that there's no issue.

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/bf379b555c06034bcd1be384cc145d8264213f41

Modified Files
--------------
src/backend/rewrite/rewriteDefine.c | 6 ++++++
1 file changed, 6 insertions(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix one more portability shortcoming in new test_pg_dump test.
Следующее
От: Jeff Davis
Дата:
Сообщение: pgsql: Fix locale options checking in CREATE DATABASE.