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

Re: [PATCH v2] merge: fix cache_entry use-after-free

From
David Turner <dturner@twopensource.com>
Date
Oct 14, 2015, 22:00 UTC
Message-ID
<1444860042.18742.13.camel@twopensource.com>
In-Reply-To
<xmqqk2qp6tg1.fsf@gitster.mtv.corp.google.com>
On Wed, 2015-10-14 at 14:17 -0700, Junio C Hamano wrote:
Show 44 quoted lines
> David Turner <dturner@twopensource.com> writes:
> 
> > +	unsigned int ref_count; /* count the number of refs to this in dir_hash */
> 
> Me makes a mental note of the type used...
> 
> > @@ -213,6 +214,32 @@ struct cache_entry {
> >  struct pathspec;
> >  
> >  /*
> > + * Increment the cache_entry reference count.  Should be called
> > + * whenever a pointer to a cache_entry is retained in a data structure,
> > + * thus marking it as alive.
> > + */
> > +static inline void add_ce_ref(struct cache_entry *ce)
> > +{
> > +	assert(ce != NULL && ce->ref_count >= 0);
> 
> ... and notices that ce->ref_count will always be non-negative here
> 
> 
> > +	ce->ref_count++;
> > +}
> > +
> > +/*
> > + * Decrement the cache_entry reference count.  Should be called whenever
> > + * a pointer to a cache_entry is dropped.  Once the counter drops to 0
> > + * the cache_entry memory will be safely freed.
> > + */
> > +static inline void drop_ce_ref(struct cache_entry *ce)
> > +{
> > +	if (ce != NULL) {
> > +		assert(ce->ref_count >= 0);
> 
> ... and here.
> 
> By not checking integer overflow/wraparound, the code is assuming
> that a ce entry will never referenced more than 4 billion times on
> 32-bit platform.  And that is a sensible assumption as there aren't
> that many pointers in the address space to make that many reference
> anyway.
> 
> Perhaps the code can assume the number won't be more than 2 billion
> and use a signed type instead for the reference counting?
Will do.
Previous: Junio C Hamano
Message 6 of 6 in “merge: fix cache_entry use-after-free”
  1. merge: fix cache_entry use-after-freeDavid Turner, Oct 12, 2015
  2. Junio C HamanoOct 12, 2015
  3. David TurnerOct 13, 2015
  4. Junio C HamanoOct 13, 2015
  5. Junio C HamanoOct 14, 2015
  6. David TurnerOct 14, 2015

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.