Re: Assert in pageinspect with NULL pages
Peter Geoghegan <pg@bowt.ie>
From: Peter Geoghegan <pg@bowt.ie>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>,
Alexander Lakhin <exclusion@gmail.com>, Justin Pryzby <pryzby@telsasoft.com>,
Daria Lepikhova <d.lepikhova@postgrespro.ru>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2022-03-27T20:26:26Z
Lists: pgsql-hackers
On Sun, Mar 27, 2022 at 7:24 AM Robert Haas <robertmhaas@gmail.com> wrote: > It's my impression that there are many ways of crashing the system > using pageinspect right now. We aren't very careful about making sure > that our code that reads from disk doesn't crash if the data on disk > is corrupted, and all of that systemic weakness is inherited by > pageinspect. It's significantly worse than the core code, I'd say (before we even consider the fact that you can supply your own pages). At least with index AMs, where functions like _bt_checkpage() and gistcheckpage() provide the most basic sanity checks for any page that is read from disk. > Fixing this seems like a lot of work and problematic for various > reasons. And I do agree that if we can allow people to look at what's > going on with a corrupt page, that's useful. On the other hand, if by > "looking" they crash the system, that sucks a lot. So overall I think > we need a lot more sanity checks here. I don't think it's particularly hard to do a little more. That's all it would take to prevent practically all crashes. We're not dealing with adversarial page images here. Sure, it would be overkill to fully adapt something like palloc_btree_page() for pageinspect, for the reason Michael gave. But there are a couple of checks that it does that would avoid practically all real world hard crashes, without any plausible downside: * The basic _bt_checkpage() call that every nbtree page uses in the core code (as well as in amcheck). * The maxoffset > MaxIndexTuplesPerPage check. You could even go a bit further, and care about individual index tuples. My commit 93ee38eade added some basic sanity checks for index tuples to bt_page_items(). That could go a bit further as well. In particular, the sanity checks from amcheck's PageGetItemIdCareful() function could be carried over. That would make it impossible for bt_page_items() to read past the end of the page when given a page that has an index tuple whose item pointer offset has some wildly unreasonable value. I'm not volunteering. Just saying that this is quite possible. -- Peter Geoghegan
Commits
-
pageinspect: Fix handling of all-zero pages
- 12d32b7bc151 10.21 landed
- 79fed072ba5f 11.16 landed
- 5378d55cb2f3 12.11 landed
- 2275d044d084 13.7 landed
- df6bbe73b86c 14.3 landed
- cd4868a5700f 15.0 landed
-
pageinspect: Add more sanity checks to prevent out-of-bound reads
- ab80b0fbbbc4 10.21 landed
- 1a2fdf86aae8 11.16 landed
- 5ca2aa2f26ea 12.11 landed
- 3d4d6dee0777 13.7 landed
- 27d384441851 14.3 landed
- 291e517a4dc9 15.0 landed
-
pageinspect: Fix handling of page sizes and AM types
- c42b88932b9d 10.21 landed
- 2389ee8dd800 11.16 landed
- af8a8eb54245 12.11 landed
- d3a9b83c30b6 13.7 landed
- b61e6214cfac 14.3 landed
- 076f4d9539e9 15.0 landed
-
Teach pageinspect about nbtree deduplication.
- 93ee38eade1b 13.0 cited