Re: BUG #17462: Invalid memory access in heapam_tuple_lock
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: anisimow.d@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2022-04-11T23:07:31Z
Lists: pgsql-bugs
Attachments
- fix-unsafe-buffer-reference-after-heap_fetch-wip.patch (text/x-diff) patch
Andres Freund <andres@anarazel.de> writes: > On 2022-04-11 15:59:30 -0400, Tom Lane wrote: >> Yeah, that could work. You want to draft a patch, or shall I? > If you would, I'd appreciate it. I abandoned that idea after noticing that heapam_tuple_lock needs not only the tuple's xmin and ctid, but usually also the result of HeapTupleHeaderGetUpdateXid, which is expensive (it can require a multixact lookup). I do not think it's a great idea to expect HeapTupleSatisfiesDirty to compute that. So the attached patch goes back to my original idea of reverting the removal of the keep_buf argument. This worked out pretty cleanly, with minimal code changes. In HEAD, we might want to avoid the extra heap_fetch_extended layer by adding that argument back to heap_fetch, but having the extra layer avoids an API break for the back branches. As written here, even though there's no obvious API break, there is a subtle change: heap_fetch will now return tuple->t_data = NULL after a snapshot failure. I'm of two minds whether to back-patch that part (not doing so would require more changes in heapam_tuple_lock, though). I'm concerned that some caller might be using that legitimately, say by testing for pointer nullness without actually dereferencing it. And even if they are unsafely dereferencing it, I'm not sure people would thank us for converting a subtle low-probability failure into a subtle higher-probability one. Thoughts? regards, tom lane
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