cmd: pstore: fix out-of-bounds accesses in display and save
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest6 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | cmd: pstore: check the record header before using itcmd/ | +4 | 0 replies | |
| 2/6 | test: pstore: check that records with an invalid header are skippedtest/ | +37 | 0 replies | |
| 3/6 | cmd: pstore: size the buffer again after pstore setcmd/ | +3 | 0 replies | |
| 4/6 | test: pstore: check pstore save after a record is made largertest/ | +31 | 0 replies | |
| 5/6 | cmd: pstore: look for the end of the dump header within the recordcmd/ | +6 | 0 replies | |
| 6/6 | test: pstore: check a dump record whose header line is cuttest/ | +20 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH v1 0/6] cmd: pstore: fix out-of-bounds accesses in display and save
pstore display and pstore save read the records that the Linux ramoops driver left in RAM. This series fixes three ways in which they access memory past a record or a buffer. Each fix is followed by a test in test_pstore.py that fails without it.
Patch 1 checks the record header. pstore_get_buffer() copies the bytes from offset start to the end of the record, but only rejected a record whose size is 0 or larger than its zone, so a start beyond the size made the length wrap around and crashed U-Boot. The ftrace records are read without checking their signature, so leftover data in RAM is enough. The record is now rejected, as Linux does in persistent_ram_post_init(), when its size does not fit in the zone after the 12-byte header or its start is beyond its size. Patch 2 writes such headers and checks that the records are skipped.
Patch 3 fixes a heap overflow. Each record is copied into a buffer sized for the largest record on the first pstore display or save, and pstore set changed the record sizes without sizing it again. Patch 4 makes the console record larger after a first display and saves a full one.
Patch 5 looks for the newline that ends the header line of a dump record within the record. strchr() went past the end of a record without one, the header length got larger than the record, and pstore save tried to write almost 4 GiB. Patch 6 cuts the header line of a dump record.
Without patch 3, the test in patch 4 trips an assertion in the sandbox malloc checks, which stops U-Boot with "### ERROR ### Please RESET the board ###". test.py treats that as fatal and stops the whole run instead of failing one test.
Each commit builds for sandbox, and cmd/pstore.c builds without warnings with W=1 for pinephone (arm64) and r8a78000_ironhide_cm33 (32-bit). All pstore tests pass on sandbox.
Aristo Chen (6):
cmd: pstore: check the record header before using it
test: pstore: check that records with an invalid header are skipped
cmd: pstore: size the buffer again after pstore set
test: pstore: check pstore save after a record is made larger
cmd: pstore: look for the end of the dump header within the record
test: pstore: check a dump record whose header line is cut
cmd/pstore.c | 20 +++++--- test/py/tests/test_pstore.py | 88 ++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 7 deletions(-)
Signature · 1 line
2.43.0