git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 00/12] reftable: harden against corrupted tables

From
Patrick Steinhardt <ps@pks.im>
Date
Jul 3, 2026, 12:58 UTC
Message-ID
<20260703-pks-reftable-hardening-v3-0-b87c555b9920@pks.im>
In-Reply-To
<20260624-pks-reftable-hardening-v1-0-66e4ce87c6b9@pks.im>
Hi,

this patch series addresses a bunch of errors that may happen when trying to read corrupted tables. These errors include out-of-bounds writes, out-of-bounds reads and the ability to hit abort(3p) calls.

The out-of-bounds write was originally reported by awo on the security mailing list. As we never transfer reftables over the protocol it would require local disk access to create such corrupted reftables, so there isn't really an easy way to exploit these.

In any case, I took that chance and wrote a fuzzer for parsing the tables, which surfaced a bunch of issues. At the end of this series though the fuzzer can now run for an extended amount of time (2hrs+) without surfacing any new issues.

Changes in v3:
  - Make one of the unit tests a bit stricter.
  - Link to v2: https://patch.msgid.link/20260629-pks-reftable-hardening-v2-0-b0228e7d908d@pks.im
Changes in v2:
  - Introduce a test helper that writes a reftable block.
  - Link to v1: https://patch.msgid.link/20260624-pks-reftable-hardening-v1-0-66e4ce87c6b9@pks.im
Thanks!
Patrick
---
Patrick Steinhardt (12):
      meson: support building fuzzers with libFuzzer
      oss-fuzz: add fuzzer for parsing reftables
      reftable/basics: fix OOB read on binary search of empty range
      reftable/record: don't abort when decoding invalid ref value type
      t/unit-tests: introduce test helper to write reftable blocks
      reftable/block: fix OOB write with bogus inflated log size
      reftable/block: fix OOB read with bogus block size
      reftable/block: fix OOB read with bogus restart count
      reftable/block: fix use of uninitialized memory when binsearch fails
      reftable/block: fix OOB read with bogus restart offset
      reftable/table: fix NULL pointer access when seeking to bogus offsets
      reftable/table: fix OOB read on truncated table
 Makefile                            |   1 +
 ci/run-build-and-minimal-fuzzers.sh |   1 +
 meson.build                         |  15 +++
 meson_options.txt                   |   2 +
 oss-fuzz/.gitignore                 |   1 +
 oss-fuzz/fuzz-reftable.c            |  74 ++++++++++++++
 oss-fuzz/meson.build                |   2 +
 reftable/basics.c                   |   3 +
 reftable/block.c                    |  39 +++++++-
 reftable/record.c                   |   6 +-
 reftable/table.c                    |   7 ++
 t/unit-tests/u-reftable-basics.c    |  11 +++
 t/unit-tests/u-reftable-block.c     | 189 ++++++++++++++++++++++++++++++++----
 t/unit-tests/u-reftable-record.c    |  24 +++++
 t/unit-tests/u-reftable-table.c     |  91 +++++++++++++++++
 15 files changed, 440 insertions(+), 26 deletions(-)
Range-diff versus v2:
 1:  cd28489ce9 =  1:  53673a5044 meson: support building fuzzers with libFuzzer
 2:  2f304e5bef =  2:  06037f8cc6 oss-fuzz: add fuzzer for parsing reftables
 3:  d74a5b244d =  3:  21b4025e1d reftable/basics: fix OOB read on binary search of empty range
 4:  f710410b28 =  4:  dfed39b876 reftable/record: don't abort when decoding invalid ref value type
 5:  0f90c22ccf =  5:  badbfdc070 t/unit-tests: introduce test helper to write reftable blocks
 6:  b69a8c40a0 =  6:  b0d13e79c5 reftable/block: fix OOB write with bogus inflated log size
 7:  19046dbb2e !  7:  612df3c909 reftable/block: fix OOB read with bogus block size
    @@ Commit message
         block size that exceeds the data we have actually read this can lead to
         an out-of-bounds read:
     
    -      ==1458284==ERROR: AddressSanitizer: SEGV on unknown address 0x7d8ff7de4b7d (pc 0x55555598c339 bp 0x7fffffff4ef0 sp 0x7fffffff4eb0 T0)
    -      ==1458284==The signal is caused by a READ memory access.
    -          #0 0x55555598c339 in reftable_get_be16 ./build/../reftable/basics.h:118:9
    -          #1 0x55555598bee2 in reftable_block_init ./build/../reftable/block.c:344:18
    -          #2 0x555555813e0e in test_reftable_block__corrupt_block_size ./build/../t/unit-tests/u-reftable-block.c:540:8
    -          #3 0x5555557f684e in clar_run_test ./build/../t/unit-tests/clar/clar.c:335:3
    -          #4 0x5555557f2e69 in clar_run_suite ./build/../t/unit-tests/clar/clar.c:431:3
    -          #5 0x5555557f2882 in clar_test_run ./build/../t/unit-tests/clar/clar.c:636:4
    -          #6 0x5555557f375f in clar_test ./build/../t/unit-tests/clar/clar.c:687:11
    -          #7 0x5555557fa49d in cmd_main ./build/../t/unit-tests/unit-test.c:62:8
    -          #8 0x55555584b55a in main ./build/../common-main.c:9:11
    -          #9 0x7ffff7a2b284 in __libc_start_call_main (/nix/store/57iz36553175g3178pvxjij8z5rcsd4n-glibc-2.42-61/lib/libc.so.6+0x2b284) (BuildId: 8ae0b698f2d4e727f569f64bb166e08ae30bd077)
    -          #10 0x7ffff7a2b337 in __libc_start_main@GLIBC_2.2.5 (/nix/store/57iz36553175g3178pvxjij8z5rcsd4n-glibc-2.42-61/lib/libc.so.6+0x2b337) (BuildId: 8ae0b698f2d4e727f569f64bb166e08ae30bd077)
    -          #11 0x555555694c24 in _start (./build/t/unit-tests+0x140c24)
    +      ==2274138==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7c3ff6de2e3f at pc 0x55555598c6ea bp 0x7fffffff4ee0 sp 0x7fffffff4ed8
    +      READ of size 1 at 0x7c3ff6de2e3f thread T0
    +          #0 0x55555598c6e9 in reftable_get_be16 /home/pks/Development/git/build/../reftable/basics.h:119:20
    +          #1 0x55555598c252 in reftable_block_init /home/pks/Development/git/build/../reftable/block.c:343:18
    +          #2 0x555555813c70 in test_reftable_block__corrupt_block_size /home/pks/Development/git/build/../t/unit-tests/u-reftable-block.c:531:20
    +          #3 0x5555557f684e in clar_run_test /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:335:3
    +          #4 0x5555557f2e69 in clar_run_suite /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:431:3
    +          #5 0x5555557f2882 in clar_test_run /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:636:4
    +          #6 0x5555557f375f in clar_test /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:687:11
    +          #7 0x5555557fa49d in cmd_main /home/pks/Development/git/build/../t/unit-tests/unit-test.c:62:8
    +          #8 0x55555584b8aa in main /home/pks/Development/git/build/../common-main.c:9:11
    +          #9 0x7ffff7a2b284 in __libc_start_call_main (/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6+0x2b284) (BuildId: 5a702452a01df1d7d50ce0663acec7be3c71fd4d)
    +          #10 0x7ffff7a2b337 in __libc_start_main@GLIBC_2.2.5 (/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6+0x2b337) (BuildId: 5a702452a01df1d7d50ce0663acec7be3c71fd4d)
    +          #11 0x555555694c24 in _start (/home/pks/Development/git/build/t/unit-tests+0x140c24)
     
    -      ==1458284==Register values:
    -      rax = 0x00007d8ff7de4b7d  rbx = 0x00007fffffff4f00  rcx = 0x0000000000000006  rdx = 0x0000000000000010
    -      rdi = 0x00007d8ff7de4b7d  rsi = 0x00007bfff5cf0420  rbp = 0x00007fffffff4ef0  rsp = 0x00007fffffff4eb0
    -       r8 = 0x00000f807eb960b8   r9 = 0x0000000000000001  r10 = 0x00007bfff5cf05e7  r11 = 0x000000000000000f
    -      r12 = 0x00007fffffff58f8  r13 = 0x0000000000000001  r14 = 0x0000555555ee8160  r15 = 0x0000000000000000
    -      AddressSanitizer can not provide additional info.
    +      0x7c3ff6de2e3f is located 0 bytes after 47-byte region [0x7c3ff6de2e10,0x7c3ff6de2e3f)
    +      allocated by thread T0 here:
    +          #0 0x55555579e95b in malloc (/home/pks/Development/git/build/t/unit-tests+0x24a95b)
    +          #1 0x5555559871c2 in reftable_malloc /home/pks/Development/git/build/../reftable/basics.c:24:9
    +          #2 0x5555559872e8 in reftable_calloc /home/pks/Development/git/build/../reftable/basics.c:54:6
    +          #3 0x55555598f0d3 in reftable_buf_read_data /home/pks/Development/git/build/../reftable/blocksource.c:67:2
    +          #4 0x55555598ea7e in block_source_read_data /home/pks/Development/git/build/../reftable/blocksource.c:41:19
    +          #5 0x55555598c555 in read_block /home/pks/Development/git/build/../reftable/block.c:224:9
    +          #6 0x55555598b69e in reftable_block_init /home/pks/Development/git/build/../reftable/block.c:258:9
    +          #7 0x555555813c70 in test_reftable_block__corrupt_block_size /home/pks/Development/git/build/../t/unit-tests/u-reftable-block.c:531:20
    +          #8 0x5555557f684e in clar_run_test /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:335:3
    +          #9 0x5555557f2e69 in clar_run_suite /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:431:3
    +          #10 0x5555557f2882 in clar_test_run /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:636:4
    +          #11 0x5555557f375f in clar_test /home/pks/Development/git/build/../t/unit-tests/clar/clar.c:687:11
    +          #12 0x5555557fa49d in cmd_main /home/pks/Development/git/build/../t/unit-tests/unit-test.c:62:8
    +          #13 0x55555584b8aa in main /home/pks/Development/git/build/../common-main.c:9:11
    +          #14 0x7ffff7a2b284 in __libc_start_call_main (/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6+0x2b284) (BuildId: 5a702452a01df1d7d50ce0663acec7be3c71fd4d)
    +          #15 0x7ffff7a2b337 in __libc_start_main@GLIBC_2.2.5 (/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6+0x2b337) (BuildId: 5a702452a01df1d7d50ce0663acec7be3c71fd4d)
    +          #16 0x555555694c24 in _start (/home/pks/Development/git/build/t/unit-tests+0x140c24)
    +
    +      SUMMARY: AddressSanitizer: heap-buffer-overflow /home/pks/Development/git/build/../reftable/basics.h:119:20 in reftable_get_be16
    +      Shadow bytes around the buggy address:
    +        0x7c3ff6de2b80: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
    +        0x7c3ff6de2c00: fa fa fd fd fd fd fd fa fa fa fd fd fd fd fd fa
    +        0x7c3ff6de2c80: fa fa fd fd fd fd fd fd fa fa fd fd fd fd fd fa
    +        0x7c3ff6de2d00: fa fa fd fd fd fd fd fd fa fa fd fd fd fd fd fa
    +        0x7c3ff6de2d80: fa fa 00 00 00 00 00 00 fa fa fd fd fd fd fd fd
    +      =>0x7c3ff6de2e00: fa fa 00 00 00 00 00[07]fa fa fa fa fa fa fa fa
    +        0x7c3ff6de2e80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    +        0x7c3ff6de2f00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    +        0x7c3ff6de2f80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    +        0x7c3ff6de3000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    +        0x7c3ff6de3080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
    +      Shadow byte legend (one shadow byte represents 8 application bytes):
    +        Addressable:           00
    +        Partially addressable: 01 02 03 04 05 06 07
    +        Heap left redzone:       fa
    +        Freed heap region:       fd
    +        Stack left redzone:      f1
    +        Stack mid redzone:       f2
    +        Stack right redzone:     f3
    +        Stack after return:      f5
    +        Stack use after scope:   f8
    +        Global redzone:          f9
    +        Global init order:       f6
    +        Poisoned by user:        f7
    +        Container overflow:      fc
    +        Array cookie:            ac
    +        Intra object redzone:    bb
    +        ASan internal:           fe
    +        Left alloca redzone:     ca
    +        Right alloca redzone:    cb
     
         Verify that the claimed block size fits into the block data before using
         it.
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_log_block_siz
     +	};
     +	struct reftable_block block = { 0 };
     +	struct reftable_buf data = REFTABLE_BUF_INIT;
    ++	uint32_t block_size;
    ++	unsigned char *p;
     +
     +	cl_reftable_write_block(&data, REFTABLE_BLOCK_TYPE_REF, &rec, 1);
     +
    @@ t/unit-tests/u-reftable-block.c: void test_reftable_block__corrupt_log_block_siz
     +	 * the restart count and restart table relative to such a bogus block
     +	 * size must not access out-of-bounds memory.
     +	 */
    -+	reftable_put_be24((uint8_t *) data.buf + 1, 0xffffff);
    ++	p = (unsigned char *) data.buf + 1;
    ++	block_size = reftable_get_be24(p);
    ++	cl_assert_equal_i(block_size, 47);
    ++	reftable_put_be24(p, block_size + 1);
     +
     +	block_source_from_buf(&source, &data);
     +	cl_assert_equal_i(reftable_block_init(&block, &source, 0, 0, data.len,
 8:  bc0e0e5f30 =  8:  6df5cc741a reftable/block: fix OOB read with bogus restart count
 9:  668108e851 =  9:  74e7d35bd9 reftable/block: fix use of uninitialized memory when binsearch fails
10:  bb3f76e084 = 10:  3264933eba reftable/block: fix OOB read with bogus restart offset
11:  6b7e61728b = 11:  638964395c reftable/table: fix NULL pointer access when seeking to bogus offsets
12:  ea051207e1 = 12:  6745a7fca8 reftable/table: fix OOB read on truncated table

--- base-commit: ab776a62a78576513ee121424adb19597fbb7613 change-id: 20260623-pks-reftable-hardening-f54de69fea63

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 35 of 48 in “reftable: harden against corrupted tables”
  1. 00/11 reftable: harden against corrupted tablesPatrick Steinhardt, Jun 24, 2026
  2. 01/11 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jun 24, 2026
  3. 02/11 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jun 24, 2026
  4. 03/11 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jun 24, 2026
  5. 04/11 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jun 24, 2026
  6. 05/11 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jun 24, 2026
  7. Christian CouderJun 26, 2026
  8. Patrick SteinhardtJun 29, 2026
  9. 06/11 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jun 24, 2026
  10. 07/11 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jun 24, 2026
  11. 08/11 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jun 24, 2026
  12. 09/11 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jun 24, 2026
  13. 10/11 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jun 24, 2026
  14. 11/11 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jun 24, 2026
  15. 00/12 reftable: harden against corrupted tablesPatrick Steinhardt, Jun 29, 2026
  16. 01/12 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jun 29, 2026
  17. 02/12 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jun 29, 2026
  18. 03/12 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jun 29, 2026
  19. 04/12 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jun 29, 2026
  20. 05/12 t/unit-tests: introduce test helper to write reftable blocksPatrick Steinhardt, Jun 29, 2026
  21. Junio C HamanoJun 30, 2026
  22. Christian CouderJul 2, 2026
  23. Junio C HamanoJul 3, 2026
  24. 06/12 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jun 29, 2026
  25. Toon ClaesJul 3, 2026
  26. Patrick SteinhardtJul 3, 2026
  27. 07/12 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jun 29, 2026
  28. Toon ClaesJul 3, 2026
  29. Patrick SteinhardtJul 3, 2026
  30. 08/12 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jun 29, 2026
  31. 09/12 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jun 29, 2026
  32. 10/12 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jun 29, 2026
  33. 11/12 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jun 29, 2026
  34. 12/12 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jun 29, 2026
  35. 00/12 reftable: harden against corrupted tablesPatrick Steinhardt, Jul 3, 2026
  36. 01/12 meson: support building fuzzers with libFuzzerPatrick Steinhardt, Jul 3, 2026
  37. 02/12 oss-fuzz: add fuzzer for parsing reftablesPatrick Steinhardt, Jul 3, 2026
  38. 03/12 reftable/basics: fix OOB read on binary search of empty rangePatrick Steinhardt, Jul 3, 2026
  39. 04/12 reftable/record: don't abort when decoding invalid ref value typePatrick Steinhardt, Jul 3, 2026
  40. 05/12 t/unit-tests: introduce test helper to write reftable blocksPatrick Steinhardt, Jul 3, 2026
  41. 06/12 reftable/block: fix OOB write with bogus inflated log sizePatrick Steinhardt, Jul 3, 2026
  42. 07/12 reftable/block: fix OOB read with bogus block sizePatrick Steinhardt, Jul 3, 2026
  43. 08/12 reftable/block: fix OOB read with bogus restart countPatrick Steinhardt, Jul 3, 2026
  44. 09/12 reftable/block: fix use of uninitialized memory when binsearch failsPatrick Steinhardt, Jul 3, 2026
  45. 10/12 reftable/block: fix OOB read with bogus restart offsetPatrick Steinhardt, Jul 3, 2026
  46. 11/12 reftable/table: fix NULL pointer access when seeking to bogus offsetsPatrick Steinhardt, Jul 3, 2026
  47. 12/12 reftable/table: fix OOB read on truncated tablePatrick Steinhardt, Jul 3, 2026
  48. Toon ClaesJul 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.