Re: PG 12 beta 1 segfault during analyze - Mailing list pgsql-hackers

From Andres Freund
Subject Re: PG 12 beta 1 segfault during analyze
Date
Msg-id 20190618072307.konmfj6u4hbphg3x@alap3.anarazel.de
Whole thread Raw
In response to Re: PG 12 beta 1 segfault during analyze  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: PG 12 beta 1 segfault during analyze
List pgsql-hackers
Hi,

On 2019-06-18 00:32:17 -0400, Tom Lane wrote:
> Steve Singer <steve@ssinger.info> writes:
> > The attached patch fixes the issue.
>
> Hmm, that's a pretty obvious mistake :-( but after some fooling around
> I've not been able to cause a crash with it.  I wonder what test case
> you were using, on what platform?

I suspect that's because the bug is "only" in the
HEAPTUPLE_DELETE_IN_PROGRESS case. And it's "harmless" as far as
crashing goes in the !TransactionIdIsCurrentTransactionId() case,
because as the tuple is sampled, we just return. And then there still
needs to be an actually dead row afterwards, to actually trigger
dereferencing the modified deadrows. And then acquire_sample_rows()'s
deadrows actually needs to point to something that causes crashes when
modified.

I can definitely get it to do a "wild" pointer write:

Breakpoint 2, heapam_scan_analyze_next_tuple (scan=0x55f8fcb92728, OldestXmin=512, liverows=0x7fff56159850,
    deadrows=0x7fff56159f50, slot=0x55f8fcb92b40) at
/home/andres/src/postgresql/src/backend/access/heap/heapam_handler.c:1061
1061                    *deadrows += 1;
(gdb) p deadrows
$9 = (double *) 0x7fff56159f50
(gdb) up
#1  0x000055f8fad922c5 in table_scan_analyze_next_tuple (scan=0x55f8fcb92728, OldestXmin=512, liverows=0x7fff56159850,
    deadrows=0x7fff56159848, slot=0x55f8fcb92b40) at /home/andres/src/postgresql/src/include/access/tableam.h:1467
1467        return scan->rs_rd->rd_tableam->scan_analyze_next_tuple(scan, OldestXmin,
(gdb) p deadrows
$10 = (double *) 0x7fff56159848

making a question of a crash just a question of the exact stack layout
and the number of deleted tuples.

Will fix tomorrow morning.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Hash join explain is broken
Next
From: shawn wang
Date:
Subject: Re: [Proposal] Table-level Transparent Data Encryption (TDE) and KeyManagement Service (KMS)