Bug in ginRedoRecompress that causes opaque data on page to beoverrun

Поиск
Список
Период
Сортировка
От R, Siva
Тема Bug in ginRedoRecompress that causes opaque data on page to beoverrun
Дата
Msg-id 1536091151804.6588@amazon.com
обсуждение исходный текст
Ответы Re: Bug in ginRedoRecompress that causes opaque data on page to be overrun  (Alexander Korotkov <a.korotkov@postgrespro.ru>)
Re: Bug in ginRedoRecompress that causes opaque data on page to be overrun  (Peter Geoghegan <pg@bowt.ie>)
Re: Bug in ginRedoRecompress that causes opaque data on page to be overrun  (Masahiko Sawada <sawada.mshk@gmail.com>)
Список pgsql-hackers

Hi,

We recently encountered an issue where the opaque data flags on a gin data leaf page was corrupted while replaying a gin insert WAL record. Upon further examination of the redo code, we found a bug in ginRedoRecompress code, which extracts the WAL information and updates the page.

Specifically, when a new segment is inserted in the middle of a page, a memmove operation is performed [1] at the current point in the page to make room for the new segment. If this segment insertion is followed by delete segment actions that are yet to be processed and the total data size is very close to GinDataPageMaxDataSize, then we may move the data portion beyond the boundary causing the opaque data to be corrupted.

One way of solving this problem is to perform the replay work on a scratch space, perform sanity check on the total size of the data portion before copying it back to the actual page. While it involves additional memory allocation and memcpy operations, it is safer and similar to the 'do' code path where we ensure to make a copy of all segment past the first modified segment before placing them back on the page [2].

I have attached a patch for that approach here. Please let us know any comments or feedback.
Thanks!

Best
Siva

References:
[1] - https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/access/gin/ginxlog.c;h=7515f8bc167c2eafceced5d6ad5d74f7ec09e0a5;hb=refs/heads/REL9_6_STABLE#l278
[2] - https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/backend/access/gin/gindatapage.c;h=cd3b9dfb784b084dd27a37146a4909fa1109ee81;hb=refs/heads/REL9_6_STABLE#l1726

Вложения

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

Предыдущее
От: Victor Wagner
Дата:
Сообщение: Re: Bug fix for glibc broke freebsd build in REL_11_STABLE
Следующее
От: Victor Wagner
Дата:
Сообщение: Re: Bug fix for glibc broke freebsd build in REL_11_STABLE