Re: Confine vacuum skip logic to lazy_scan_skip
Ranier Vilela <ranier.vf@gmail.com>
From: Ranier Vilela <ranier.vf@gmail.com>
To: Melanie Plageman <melanieplageman@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Thomas Munro <thomas.munro@gmail.com>, Masahiko Sawada <sawada.mshk@gmail.com>, Tomas Vondra <tomas@vondra.me>,
Noah Misch <noah@leadboat.com>, vignesh C <vignesh21@gmail.com>, Andres Freund <andres@anarazel.de>, Pg Hackers <pgsql-hackers@postgresql.org>,
Heikki Linnakangas <hlinnaka@iki.fi>, Nazir Bilal Yavuz <byavuz81@gmail.com>, Robert Haas <robertmhaas@gmail.com>, "Andrey M. Borodin" <x4mmm@yandex-team.ru>
Date: 2025-02-27T17:32:28Z
Lists: pgsql-hackers
Attachments
- fix-possible-invalid-pointer-read_stream.patch (application/octet-stream) patch
Hi. Em ter., 18 de fev. de 2025 às 11:31, Melanie Plageman < melanieplageman@gmail.com> escreveu: > On Sun, Feb 16, 2025 at 1:12 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > > > > Thomas Munro <thomas.munro@gmail.com> writes: > > > Thanks! It's green again. > > > > The security team's Coverity instance complained about this patch: > > > > *** CID 1642971: Null pointer dereferences (FORWARD_NULL) > > > /srv/coverity/git/pgsql-git/postgresql/src/backend/access/heap/vacuumlazy.c: > 1295 in lazy_scan_heap() > > 1289 buf = read_stream_next_buffer(stream, > &per_buffer_data); > > 1290 > > 1291 /* The relation is exhausted. */ > > 1292 if (!BufferIsValid(buf)) > > 1293 break; > > 1294 > > >>> CID 1642971: Null pointer dereferences (FORWARD_NULL) > > >>> Dereferencing null pointer "per_buffer_data". > > 1295 blk_info = *((uint8 *) per_buffer_data); > > 1296 CheckBufferIsPinnedOnce(buf); > > 1297 page = BufferGetPage(buf); > > 1298 blkno = BufferGetBlockNumber(buf); > > 1299 > > 1300 vacrel->scanned_pages++; > > > > Basically, Coverity doesn't understand that a successful call to > > read_stream_next_buffer must set per_buffer_data here. I don't > > think there's much chance of teaching it that, so we'll just > > have to dismiss this item as "intentional, not a bug". > > Is this easy to do? Like is there a list of things from coverity to ignore? > > > I do have a suggestion: I think the "per_buffer_data" variable > > should be declared inside the "while (true)" loop not outside. > > That way there is no chance of a value being carried across > > iterations, so that if for some reason read_stream_next_buffer > > failed to do what we expect and did not set per_buffer_data, > > we'd be certain to get a null-pointer core dump rather than > > accessing data from a previous buffer. > > Done and pushed. Thanks! > Per Coverity. CID 1592454: (#1 of 1): Explicit null dereferenced (FORWARD_NULL) 8. var_deref_op: Dereferencing null pointer per_buffer_data. I think that function *read_stream_next_buffer* can return a invalid per_buffer_data pointer, with a valid buffer. Sorry if I'm wrong, but the function is very suspicious. Attached a patch, which tries to fix. best regards, Ranier Vilela
Commits
-
Fix explicit valgrind interaction in read_stream.c.
- 57dca6faa9bd 17.5 landed
- 2a8a00674e97 18.0 landed
-
Reduce scope of heap vacuum per_buffer_data
- c623e8593ec4 18.0 landed
-
Use streaming read I/O in VACUUM's third phase
- c3e775e608f2 18.0 landed
-
Use streaming read I/O in VACUUM's first phase
- 9256822608f3 18.0 landed
-
Convert heap_vac_scan_next_block() boolean parameters to flags
- 32acad7d1d0a 18.0 landed
-
Refactor tidstore.c iterator buffering.
- f6bef362cac8 18.0 landed
-
Increase default vacuum_buffer_usage_limit to 2MB.
- 98f320eb2ef0 17.0 landed
-
Remove unneeded vacuum_delay_point from heap_vac_scan_get_next_block
- 3d8652cd3284 17.0 landed
-
Confine vacuum skip logic to lazy_scan_skip()
- 4e76f984a773 17.0 landed
-
Set all_visible_according_to_vm correctly with DISABLE_PAGE_SKIPPING
- 407cb6c6589f 16.3 landed
- 674e49c73c1c 17.0 landed
-
Tighten up VACUUM's approach to setting VM bits.
- 980ae173108e 16.0 cited