git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Hommey <mh@glandium.org>
To: git@vger.kernel.org
Subject: Integer-overflow in read-cache.c can cause buffer-overflow (bug requires a crafted/corrupted index)
Date: Fri, 8 Jul 2016 20:43:02 +0900	[thread overview]
Message-ID: <20160708114302.GA20350@glandium.org> (raw)

Hi,

I had a procastination episode today and wrote
https://glandium.org/blog/?p=3659 . It started with me looking what git
was doing with the size of the index when writing the index header,
leading me to find a rather improbable integer overflow in
https://github.com/git/git/blob/5c589a73de4394ad125a4effac227b3aec856fa1/read-cache.c#L1040
requiring hundreds of gigabytes of memory before happening.

But right after I finished the post and clicked "publish", I actually
looked at the reading side and found another separate integer overflow
that can lead to buffer overflow.

The possible integer overflow is here:
https://github.com/git/git/blob/5c589a73de4394ad125a4effac227b3aec856fa1/read-cache.c#L1589

where alloc_nr is:
#define alloc_nr(x) (((x)+16)*3/2)

So a crafter header with a number of entries above 1.something billion
would overflow (cache_nr is an unsigned int), and istate->cache would
be allocated with less than it should.

Then there can be a buffer overflow when reading the entries.

But this all require a crafted or corrupted index. If an attacker has
been able to alter your index, you've already lost.

So I'd say the risk is rather low on the security scale.

Cheers,

Mike

                 reply	other threads:[~2016-07-08 11:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160708114302.GA20350@glandium.org \
    --to=mh@glandium.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).