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

Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Jan 9, 2019, 21:06 UTC
Message-ID
<CAN0heSqLUWpwRdeUvYj2KnDX-QxSOnWOdKWz77RjHKJ3AFUGEQ@mail.gmail.com>
In-Reply-To
<CAN0heSoRYYS3-UAamE9nibhORPoD+_TRHu5-ZTeYxYMS4BAnrA@mail.gmail.com>
On Wed, 9 Jan 2019 at 08:37, Martin Ågren <martin.agren@gmail.com> wrote:
Show 35 quoted lines
>
> On Tue, 8 Jan 2019 at 00:34, Junio C Hamano <gitster@pobox.com> wrote:
> > * bc/sha-256 (2018-11-14) 12 commits
> >  - hash: add an SHA-256 implementation using OpenSSL
> >  - sha256: add an SHA-256 implementation using libgcrypt
> >  - Add a base implementation of SHA-256 support
> >  - commit-graph: convert to using the_hash_algo
> >  - t/helper: add a test helper to compute hash speed
> >  - sha1-file: add a constant for hash block size
> >  - t: make the sha1 test-tool helper generic
> >  - t: add basic tests for our SHA-1 implementation
> >  - cache: make hashcmp and hasheq work with larger hashes
> >  - hex: introduce functions to print arbitrary hashes
> >  - sha1-file: provide functions to look up hash algorithms
> >  - sha1-file: rename algorithm to "sha1"
> >
> >  Add sha-256 hash and plug it through the code to allow building Git
> >  with the "NewHash".
>
> AddressSanitizer barks at current pu (855f98be272f19d16564e) for a
> handful of tests.
>
> One example is t5702-protocol-v2.sh. [...]
>
> ==1691823==ERROR: AddressSanitizer: heap-buffer-overflow on address
> 0x6040000004f2 at pc 0x0000004ea0fd bp 0x7ffc53082590 sp
> 0x7ffc53081d40
> READ of size 32 at 0x6040000004f2 thread T0
>     #0 0x4ea0fc in __asan_memcpy
> llvm/projects/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cc:23
>     #1 0x8603ec in oidset_insert oidset.c
>     #2 0x86c977 in add_promisor_object packfile.c:2129:4
>     #3 0x86c07a in for_each_object_in_pack packfile.c:2070:7
>     #4 0x86c535 in for_each_packed_object packfile.c:2095:7
>     #5 0x86c651 in is_promisor_object packfile.c:2151:4
Show 21 quoted lines
> 0x6040000004f2 is located 0 bytes to the right of 34-byte region
> [0x6040000004d0,0x6040000004f2)
> allocated by thread T0 here:
>     #0 0x4eb4cf in malloc
> llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146
>     #1 0x9fa1db in do_xmalloc wrapper.c:60:8
>     #2 0x9fa2fd in do_xmallocz wrapper.c:100:8
>     #3 0x9fa2fd in xmallocz_gently wrapper.c:113
>     #4 0x86a877 in unpack_compressed_entry packfile.c:1588:11
>     #5 0x86a02e in unpack_entry packfile.c:1737:11
>     #6 0x867431 in cache_or_unpack_entry packfile.c:1439:10
>     #7 0x867431 in packed_object_info packfile.c:1506
>     #8 0x96b7be in oid_object_info_extended sha1-file.c:1394:10
>     #9 0x96d7d0 in read_object sha1-file.c:1434:6
>     #10 0x96d7d0 in read_object_file_extended sha1-file.c:1476
>     #11 0x85cf40 in repo_read_object_file ./object-store.h:174:9
>     #12 0x85cf40 in parse_object object.c:273
>     #13 0x86c752 in add_promisor_object packfile.c:2108:23
>     #14 0x86c07a in for_each_object_in_pack packfile.c:2070:7
>     #15 0x86c535 in for_each_packed_object packfile.c:2095:7
>     #16 0x86c651 in is_promisor_object packfile.c:2151:4
I found some more time to look into this.

It seems we have a buffer with raw data and we set up a `struct object_id *` pointing into it, at a (supposed) OID value. Then `update_tree_entry_internal()` verifies that the buffer contains sufficiently many bytes, i.e., at least `the_hash_algo->rawsz` (=20). We immediately call `oidset_insert()` which copies an entire struct, i.e., we copy sizeof(struct object_id) (=32) bytes. Which is 12 more than what is known to be safe. For this particular input data, we read outside allocated memory.

I can think of three possible approaches:
* Allocate with a margin (GIT_MAX_RAWSZ - the_hash_algo->rawsz) where
  "necessary" (TM). Maybe not so maintainable.
* Teach `oidset_insert()` (i.e., khash) to only copy
  `the_hash_algo->rawsz` bytes. Maybe not so good for performance.
* Ignore.
I wonder which of these is the least awful, or if there are other ideas.
Martin
Previous: Martin ÅgrenNext: brian m. carlson
Message 9 of 41 in “What's cooking in git.git (Jan 2019, #01; Mon, 7)”
  1. Junio C HamanoJan 7, 2019
  2. tg/checkout-no-overlay, was Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Thomas Gummerer, Jan 8, 2019
  3. Junio C HamanoJan 8, 2019
  4. ag/sequencer-reduce-rewriting-todo Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Alban Gruin, Jan 8, 2019
  5. sb/more-repo-in-api, was Re: What's cooking in git.git (Jan 2019, #01; Mon, 7)Jonathan Tan, Jan 8, 2019
  6. Junio C HamanoJan 8, 2019
  7. Stefan BellerJan 9, 2019
  8. Martin ÅgrenJan 9, 2019
  9. Martin ÅgrenJan 9, 2019
  10. brian m. carlsonJan 10, 2019
  11. Junio C HamanoJan 10, 2019
  12. Martin ÅgrenJan 10, 2019
  13. 0/5 tree-walk object_id refactorbrian m. carlson, Jan 10, 2019
  14. 1/5 tree-walk: copy object ID before usebrian m. carlson, Jan 10, 2019
  15. 2/5 match-trees: compute buffer offset correctly when splicingbrian m. carlson, Jan 10, 2019
  16. 3/5 match-trees: use hashcpy to splice treesbrian m. carlson, Jan 10, 2019
  17. Jeff KingJan 10, 2019
  18. brian m. carlsonJan 10, 2019
  19. Jeff KingJan 11, 2019
  20. Jeff KingJan 11, 2019
  21. brian m. carlsonJan 14, 2019
  22. Jeff KingJan 14, 2019
  23. 4/5 tree-walk: store object_id in a separate memberbrian m. carlson, Jan 10, 2019
  24. Jeff KingJan 10, 2019
  25. brian m. carlsonJan 10, 2019
  26. 5/5 cache: make oidcpy always copy GIT_MAX_RAWSZ bytesbrian m. carlson, Jan 10, 2019
  27. Jeff KingJan 10, 2019
  28. Jeff KingJan 10, 2019
  29. brian m. carlsonJan 11, 2019
  30. Jeff KingJan 11, 2019
  31. 0/5 tree-walk object_id refactorbrian m. carlson, Jan 15, 2019
  32. 1/5 tree-walk: copy object ID before usebrian m. carlson, Jan 15, 2019
  33. 2/5 match-trees: compute buffer offset correctly when splicingbrian m. carlson, Jan 15, 2019
  34. 4/5 tree-walk: store object_id in a separate memberbrian m. carlson, Jan 15, 2019
  35. 5/5 cache: make oidcpy always copy GIT_MAX_RAWSZ bytesbrian m. carlson, Jan 15, 2019
  36. 3/5 match-trees: use hashcpy to splice treesbrian m. carlson, Jan 15, 2019
  37. Junio C HamanoJan 15, 2019
  38. Jeff KingJan 9, 2019
  39. Junio C HamanoJan 10, 2019
  40. Junio C HamanoJan 10, 2019
  41. Stefan BellerJan 10, 2019

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.