10 ms·
Exploding Git Repositories
- timdorr 9y agoI'm curious how this was uploaded to GitHub successfully. I guess they do less actual introspection on the repo's contents than I thought. Did it wreak havoc on any systems behind the scenes (similar to big repos like Homebrew's)?
- enzanki_ars 9y agoI too was curious about this. https://github.com/Katee/git-bomb/commit/45546f17e5801791d4bc5968b91253a2f4b0db72 https://github.com/Katee/git-bomb/commit/45546f17e5801791d4b... shows: "Sorry, this diff is taking too long to generate. It may be too large to display on GitHub." ...so they must have some kind of backend limits that may have prevented this for becoming an issue. I wonder what would happen if it was hosted on a GitLab instance? Might have to try that sometime...
- deckar01 9y agoGitLab uses a custom Git client called Gitaly [0]. > Project Goals > Make the git data storage tier of large GitLab instances, and GitLab.com in particular, fast. [0]: https://gitlab.com/gitlab-org/gitaly https://gitlab.com/gitlab-org/gitaly Edit: It looks like Gitaly still spawns git for low level operations. It is probably affected.
- jychang 9y agoSpawning git doesn't mean that it can't just check for a timeout and stop the task with an error. Someone will probably have to actually try an experiment with Gitlab.
- ballenf 9y agoSince GitHub paid a bounty and Ok'd release, perhaps they've patched some aspects of it already. Might be impossible to recreate the issue now. My naive question is whether CLI "git" would need or could benefit from a patch. Part of me thinks it doesn't, since there are legitimate reasons for each individual aspect of creating the problematic repo. But I probably don't understand god deeply enough to know for sure.
- ethomson 9y agoYes, hosting providers need rate limiting mitigations in place. GitHub's is called gitmon (at least unofficially), and you can learn more at https://m.youtube.com/watch?v=f7ecUqHxD7o https://m.youtube.com/watch?v=f7ecUqHxD7o Visual Studio Team Services has a fundamentally different architecture, but we do some similar mechanisms despite that. (I should do some talks about it - but it's always hard to know how much to say about your defenses lest it give attackers clever new ideas!)
- corobo 9y ago> how much to say about your defenses lest it give attackers clever new ideas attackers will try clever new ideas anyway if their less clever old ideas don't work :P
- lloeki 9y agoTested locally on a GitLab instance: trying to push the repo results in a unicorn worker allocating ~3GB and pegging a core, then being killed on a timeout by the unicorn watchdog. Counting objects: 18, done. Delta compression using up to 4 threads. Compressing objects: 100% (17/17), done. Writing objects: 100% (18/18), 2.13 KiB | 0 bytes/s, done. Total 18 (delta 3), reused 0 (delta 0) remote: GitLab: Failed to authorize your Git request: internal API unreachable To gitlab.example.com: lloeki/git-bomb.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'git@gitlab.example.com:lloeki/git-bomb.git' I had "Prevent committing secrets to Git" enable though. Disabling this makes the push work. The repo first then can be browsed at the first level only from the web UI, but clicking in any folder breaks the whole thing down with multiple git processes hanging onto git rev-list. EDIT: reported at https://gitlab.com/gitlab-org/gitlab-ce/issues/39093 https://gitlab.com/gitlab-org/gitlab-ce/issues/39093 (confidential).
- shade23 9y agoTo save folks from searching : https://github.com/cocoapods/cocoapods/issues/4989 https://github.com/cocoapods/cocoapods/issues/4989
- styfle 9y agoThanks. Here is the comment from a GitHub engineer addressing the root cause: https://github.com/cocoapods/cocoapods/issues/4989#issuecomment-193772935 https://github.com/cocoapods/cocoapods/issues/4989#issuecomm...
- stolee 9y agoThere isn't anything wrong with the objects. A 'fetch' succeeds but the 'checkout' is what blows up.
- yes_or_gnome 9y agoGood point. For those that are curious: Clone (--no-checkout): $ git clone --no-checkout https://github.com/Katee/git-bomb.git Cloning into 'git-bomb'... remote: Counting objects: 18, done. remote: Compressing objects: 100% (6/6), done. remote: Total 18 (delta 2), reused 0 (delta 0), pack-reused 12 Unpacking objects: 100% (18/18), done. From there, you can do some operations like `git log` and `git cat-file -p HEAD` (I use the "dump" alias[1]; `git config --global alias.dump catfile -p`), but not others `git checkout` or `git status`. [1] Thanks to Jim Weirich and Git-Immersion, http://gitimmersion.com/lab_23.html http://gitimmersion.com/lab_23.html. I never knew the guy, but, ~~8yrs~~ (corrected below) 3.5yrs after his passing, I still go back to his presentations on Git and Ruby often. Edit: And, to see the whole tree: NEXT_REF=HEAD while [ -n "$NEXT_REF" ]; do echo "$NEXT_REF" git dump "${NEXT_REF}" echo NEXT_REF=$(git dump "${NEXT_REF}"^{tree} 2>/dev/null | awk '{ if($4 == "d0" || $4 == "f0"){ print $3 } }') done
- matthewrudy 9y agoSad one to nitpick, but Jim died in 2014. So ~3.5 years ago. Had the pleasure of meeting him in Singapore in 2013. Still so much great code of his we use all the time.
- yes_or_gnome 9y agoThanks for the correction, he truly was a brilliant mind. One of my regrets was not being active and outgoing enough to go meet him myself. I was lived in the Cincinnati area from 2007-2012. I first got started with Ruby in 2009, and quickly became aware of who he was (Rake, Bundler, etc) and that he lived/worked close by. But, at the time, I wasn't interested in conferences, meetups, or simply emailing someone to say thanks.
- kowdermeister 9y agoI thought it would self destruct after cloning of forking before clicking :)
- warent 9y agoOdd. It's surprising to me that this example runs out of memory. What would be a possible solution? Admittedly I don't know that much about the inner-workings of git, but off the top of my head, perhaps something with traversing the tree depth-first and releasing resources as you hit the bottom?
- peff 9y agoGit assumes it can keep a small struct in memory for each file in the repository (not the file contents, but a fixed per-file size). This repository just has a very large number of files.
- glandium 9y agoLarge as in 10 billions. Even if git only needed 1 byte in memory per file, it would need 10GB.
- ericfrederich 9y agoYou need a problem to have a solution to it. What do you consider to be the problem here? This is essentially something that can be expressed in relatively few bytes that expands to something much larger. Imagine I had a compressed file format for blank files "0x00" the whole way. It is implemented by writing in ascii the size of the uncompressed file. So the contents of a file called terrabyte.blank is just ascii "1000000000000" ... or the contents of a file called petabyte.blank is "10000000000000" I cannot decompress these files... what is the solution?
- warent 9y agoI'm not following; why can't you decompress it? Of course you cant decompress it into memory, but if it's trying to that then there's a problem in the code (problem identified). Naive solution, just write to the end of the file and make sure you have enough disk. More sophisticated solution, shard the file across multiple disks.
- 9y ago
- hathawsh 9y agoI wonder what the author means by "a lot" of RAM and storage. I tried it for fun. The git process pegged one CPU core and swelled to 26 GB of RAM over 8 minutes, after which I had to kill it.
- wscott 9y agoYeah I tried it too. Killed at 65G. Disappointed that Linux killed Chrome first. Oct 12 15:47:52 x99 kernel: [552390.074468] Out of memory: Kill process 7898 (git) score 956 or sacrifice child Oct 12 15:47:52 x99 kernel: [552390.074471] Killed process 7898 (git) total-vm:65304212kB, anon-rss:63789568kB, file-rss:1384kB, shmem-rss:0kB Edit: Interesting. Linux didn't kill Chrome, it died on its own. Oct 12 15:42:21 x99 kernel: [552060.423448] TaskSchedulerFo[8425]: segfault at 0 ip 000055618c430740 sp 00007f344cc093f0 error 6 in chrome[556188a1d000+55d1000] Oct 12 15:42:21 x99 kernel: [552060.439116] Core dump to |/usr/share/apport/apport 16093 11 0 16093 pipe failed Oct 12 15:42:21 x99 kernel: [552060.450561] traps: chrome[16409] trap invalid opcode ip:55af00f34b4c sp:7ffee985fb20 error:0 Oct 12 15:42:21 x99 kernel: [552060.450564] in chrome[55aeffb76000+55d1000] Oct 12 15:47:52 x99 kernel: [552390.074289] syncthing invoked oom-killer: gfp_mask=0x14201ca(GFP_HIGHUSER_MOVABLE|__GFP_COLD), nodemask=0, order=0, oom_score_adj=0 Seems Chrome faulted first, but it was probably capturing all signals and didn't handle OOM. Then next, syncthing faulted and it started the oom-killer which correctly selected 'git' to kill.
- Tharre 9y ago> [..] and didn't handle OOM. How would Chrome 'handle' an OOM anyway? As far as I'm aware, malloc doesn't return ENOMEM when the system runs out of memory, only when you hit RLIMIT_AS and alike.
- exikyut 9y agoOr when you hit 4G VIRT on 32-bit. Took me a good day's worth of debugging before some bright spark piped up and said "wait, you said you were on x86-32...?" ...yeah, I use really old computers.
- porfirium 9y agoIf we all click "Download ZIP" on this repo we can crash GitHub together! Just click here: https://codeload.github.com/Katee/git-bomb/zip/master https://codeload.github.com/Katee/git-bomb/zip/master
- AceJohnny2 9y agoI hope and expect that GitHub has the basic infrastructure to monitor excessive processes and kill them.
- abritinthebay 9y agoWouldn't that just do a `git fetch` and therefore not have the issue?
- minitech 9y ago"Download ZIP" downloads the repository’s files as a zip. No Git involved for the downloader.
- chii 9y agoi expect the download zip to be implemented as running 'git archive --format zip | write-http-response-stream'
- mschuster91 9y agoHmm I'd hope they do a caching step in between ;)
- exikyut 9y agoScratches head ...I clicked Download a few seconds ago. GitHub is still thinking. :/ Edit: After about a minute I got a pink unicorn.
- JoshMnem 9y agoBecause that page is AMP by default, it takes about 7 seconds to load the page on my laptop. AMP is really slow in some cases. Edit: see my comment below before you downvote me.
- katee 9y agoHuh, I've tested on a bunch of devices/connections and haven't encountered that. Do you know what causes AMP to be that slow for you? I'll take a look at serving non-AMP pages by default. It will require tweaking how image inclusion works.
- Sir_Cmpwn 9y agoWould you please remove amp entirely?
- JoshMnem 9y agoFor people who use extensions or browsers that block third party JS, AMP pages will take many seconds to load in non-mobile Web browsers. Here is information about some of the other problems with AMP: https://www.theregister.co.uk/2017/05/19/open_source_insider_google_amp_bad_bad_bad/ https://www.theregister.co.uk/2017/05/19/open_source_insider... https://danielmiessler.com/blog/google-amp-not-good-thing/ https://danielmiessler.com/blog/google-amp-not-good-thing/ https://ethanmarcotte.com/wrote/ampersand/ https://ethanmarcotte.com/wrote/ampersand/ https://css-tricks.com/need-catch-amp-debate/ https://css-tricks.com/need-catch-amp-debate/ https://daringfireball.net/linked/2017/01/17/schreiber-amp https://daringfireball.net/linked/2017/01/17/schreiber-amp
- xpaulbettsx 9y agoFix your browser /shrug
- JoshMnem 9y agoIt isn't just my browser. AMP performs very badly in some non-mobile browsers (no extensions).
- Retr0spectrum 9y agoWhat happens if you try to make a recursive tree?
- ethomson 9y agoAs in a tree that points to itself? You cannot, since a tree would have to point to its own SHA1. So this would require you to know your own tree's SHA and embed it in the tree.
- katee 9y agoYou can't make a valid recursive tree without a pre-image attack against SHA1. However `git` doesn't actually verify the SHA1s when it does most commands. If you make a recursive tree and try `git status` it will segfault because the directory walking gets stuck in infinite recursion.
- ericfrederich 9y agoRun this to create a 40K file which expands to 1GiB yes | head -n536870912 | bzip2 -c > /tmp/foo.bz2 I would imagine you could do something really creative with ImageMagick to create a giant PNG file as well that'll make browsers, viewers, editors crash as well.
- tedunangst 9y agoPNG has dimensions in the header so the decoder should know when it's decompressed enough.
- Hupriene 9y agoYou can also make archives that contain themselves: https://research.swtch.com/zip https://research.swtch.com/zip
- Sean1708 9y agoYou can take it a step further using Zip Bombs[0]. [0]: https://en.wikipedia.org/wiki/Zip_bomb https://en.wikipedia.org/wiki/Zip_bomb
- gwerbin 9y agoWould this be possible with a patch-based version control system like Darcs or Pijul? Does patch-based version control have other analogous security risks, or is it "better" in this case?
- fanf2 9y agoIf the patch language includes a recursive copy than it's possible to reproduce this problem in that setting.
- geezerjay 9y agoIf I understood correctly, this problem isn't caused by recursive copies but simply by expanding references. The example shows that the reference expansion leads to an exponential increase in resources required by the service.
- TeMPOraL 9y agoThis means the same in this context; if it was just expanding references one by one while walking through the tree this would not happen - the bomb requires copies of expanded references to be stored in memory.
- emeraldd 9y agoBare for the win. git clone https://github.com/Katee/git-bomb.git --bare
- breakingcups 9y agoHas anyone tried to see how well BitBucket and Gitlab handle this?
- infinity0 9y agoDirectory hard links would "fix" this issue since `git checkout` could just create a directory hard link for each duplicated tree. I wonder why traditional UNIX does not support this for any filesystem. (Yes you would need to add a loop detector for paths and resolve ".." differently but it's not like doing this is conceptually hard.)
- TeMPOraL 9y agoGoing to second level on Github breaks commit name for me - it gets stuck with "Fetching latest commit..." message. Curiously, go one level deeper and the commit message is again correct. https://github.com/Katee/git-bomb/tree/master/d0/d0 https://github.com/Katee/git-bomb/tree/master/d0/d0 (INB4 The article suggests Github is aware of this repo, so I have no qualms posting this link here.)
- pmoriarty 9y agoWhy not just always run git under memory limits? For example: % ulimit -a -t: cpu time (seconds) unlimited -f: file size (blocks) unlimited -d: data seg size (kbytes) unlimited -s: stack size (kbytes) 8192 -c: core file size (blocks) 0 -m: resident set size (kbytes) unlimited -u: processes 30127 -n: file descriptors 1024 -l: locked-in-memory size (kbytes) unlimited -v: address space (kbytes) unlimited -x: file locks unlimited -i: pending signals 30127 -q: bytes in POSIX msg queues 819200 -e: max nice 30 -r: max rt priority 99 -N 15: unlimited % ulimit -d $((100 * 1024)) # 100 MB % ulimit -m $((100 * 1024)) # 100 MB % ulimit -l $((100 * 1024)) # 100 MB % ulimit -v $((100 * 1024)) # 100 MB % git clone https://github.com/Katee/git-bomb.git Cloning into 'git-bomb'... remote: Counting objects: 18, done. remote: Compressing objects: 100% (6/6), done. remote: Total 18 (delta 2), reused 0 (delta 0), pack-reused 12 Unpacking objects: 100% (18/18), done. fatal: Out of memory, malloc failed (tried to allocate 118 bytes) warning: Clone succeeded, but checkout failed. You can inspect what was checked out with 'git status' and retry the checkout with 'git checkout -f HEAD'