forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commite0ed20d
committed
Prevent access to no-longer-pinned buffer in heapam_tuple_lock().
heap_fetch() used to have a "keep_buf" parameter that told it to returnownership of the buffer pin to the caller after finding that therequested tuple TID exists but is invisible to the specified snapshot.This was thoughtlessly removed in commit5db6df0, which brokeheapam_tuple_lock() (formerly EvalPlanQualFetch) because that functionneeds to do more accesses to the tuple even if it's invisible. The neteffect is that we would continue to touch the page for a microsecond ortwo after releasing pin on the buffer. Usually no harm would result;but if a different session decided to defragment the page concurrently,we could see garbage data and mistakenly conclude that there's no newertuple version to chain up to. (It's hard to say whether this hashappened in the field. The bug was actually found thanks to a laterchange that allowed valgrind to detect accesses to non-pinned buffers.)The most reasonable way to fix this is to reintroduce keep_buf,although I made it behave slightly differently: buffer ownershipis passed back only if there is a valid tuple at the requested TID.In HEAD, we can just add the parameter back to heap_fetch().To avoid an API break in the back branches, introduce an additionalfunction heap_fetch_extended() in those branches.In HEAD there is an additional, less obvious API change: tuple->t_datawill be set to NULL in all cases where buffer ownership is not returned,in particular when the tuple exists but fails the time qual (and!keep_buf). This is to defend against any other callers attempting toaccess non-pinned buffers. We concluded that making that change in backbranches would be more likely to introduce problems than cure any.In passing, remove a comment about heap_fetch that was obsoleted by9a8ee1d.Per bug #17462 from Daniil Anisimov. Back-patch to v12 where the bugwas introduced.Discussion:https://postgr.es/m/17462-9c98a0f00df9bd36@postgresql.org1 parent2eb3ec8 commite0ed20d
File tree
3 files changed
+43
-15
lines changed- src
- backend/access/heap
- include/access
3 files changed
+43
-15
lines changedLines changed: 33 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1405 | 1405 |
| |
1406 | 1406 |
| |
1407 | 1407 |
| |
1408 |
| - | |
| 1408 | + | |
| 1409 | + | |
1409 | 1410 |
| |
1410 | 1411 |
| |
1411 |
| - | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
1412 | 1415 |
| |
1413 | 1416 |
| |
1414 | 1417 |
| |
| |||
1427 | 1430 |
| |
1428 | 1431 |
| |
1429 | 1432 |
| |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
1430 | 1452 |
| |
1431 | 1453 |
| |
1432 | 1454 |
| |
| |||
1508 | 1530 |
| |
1509 | 1531 |
| |
1510 | 1532 |
| |
1511 |
| - | |
1512 |
| - | |
1513 |
| - | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
1514 | 1541 |
| |
1515 | 1542 |
| |
1516 | 1543 |
| |
| |||
1533 | 1560 |
| |
1534 | 1561 |
| |
1535 | 1562 |
| |
1536 |
| - | |
1537 |
| - | |
| 1563 | + | |
1538 | 1564 |
| |
1539 | 1565 |
| |
1540 | 1566 |
| |
|
Lines changed: 7 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
405 | 405 |
| |
406 | 406 |
| |
407 | 407 |
| |
408 |
| - | |
| 408 | + | |
| 409 | + | |
409 | 410 |
| |
410 | 411 |
| |
411 | 412 |
| |
| |||
504 | 505 |
| |
505 | 506 |
| |
506 | 507 |
| |
| 508 | + | |
507 | 509 |
| |
508 | 510 |
| |
509 | 511 |
| |
| |||
513 | 515 |
| |
514 | 516 |
| |
515 | 517 |
| |
516 |
| - | |
517 |
| - | |
| 518 | + | |
518 | 519 |
| |
519 | 520 |
| |
520 | 521 |
| |
| |||
530 | 531 |
| |
531 | 532 |
| |
532 | 533 |
| |
533 |
| - | |
| 534 | + | |
534 | 535 |
| |
535 | 536 |
| |
536 | 537 |
| |
537 | 538 |
| |
538 |
| - | |
539 |
| - | |
| 539 | + | |
540 | 540 |
| |
541 | 541 |
| |
542 | 542 |
| |
543 | 543 |
| |
544 | 544 |
| |
545 | 545 |
| |
546 | 546 |
| |
547 |
| - | |
548 |
| - | |
| 547 | + | |
549 | 548 |
| |
550 | 549 |
| |
551 | 550 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
123 | 123 |
| |
124 | 124 |
| |
125 | 125 |
| |
| 126 | + | |
| 127 | + | |
| 128 | + | |
126 | 129 |
| |
127 | 130 |
| |
128 | 131 |
| |
|
0 commit comments
Comments
(0)