Re: BUG #17462: Invalid memory access in heapam_tuple_lock
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: anisimow.d@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2022-04-11T19:00:42Z
Lists: pgsql-bugs
Hi, On 2022-04-11 13:51:38 -0400, Tom Lane wrote: > Andres Freund <andres@anarazel.de> writes: > > One way to address it in a way not requiring an API break would be to pass > > SnapshotAny to heap_fetch and then do an explicit visibility check "ourselves" > > in heapam_lock_tuple(). > > I'm not really interested in fixing this without an API break (going > forward anyway), because as it stands heap_fetch is just an invitation > to make this same mistake again. My suggestion was about the back branch situation... But it seems viable going forward as well, if we we reset tuple->t_data in the !valid case. As you say: > It should never return a tuple pointer if we don't keep the pin on the > associated buffer. Agreed. If tuple->t_data were reset in the !valid case, not just the !ItemIdIsNormal() case, bug would have been noticed immediately (isolation tests do fail, I checked). Another approach is to extend the SatisfiesDirty approach and store the tid of the next tuple version in addition the xmin/xmax we already store. And have heap_fetch() always set t_data to NULL if the snapshot check fails. Greetings, Andres Freund
Commits
-
Prevent access to no-longer-pinned buffer in heapam_tuple_lock().
- 7b7ed046cb2a 15.0 landed
- e0ed20d0b66e 12.11 landed
- c590e514a90d 14.3 landed
- 44096c31eaf0 13.7 landed
-
Add Valgrind buffer access instrumentation.
- 1e0dfd166b3f 14.0 cited
-
tableam: Add tuple_{insert, delete, update, lock} and use.
- 5db6df0c0117 12.0 cited