Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <orvqd5fmog5d6drocpkys7ermgnuddojl6hd3l6kqyv5wtcnyg@qxbnzu72hqt2>
Date: Sat, 1 Nov 2025 20:14:05 +0100
From: Alejandro Colomar <alx@...nel.org>
To: Rich Felker <dalias@...c.org>
Cc: Florian Weimer <fw@...eb.enyo.de>, libc-alpha@...rceware.org, 
	musl@...ts.openwall.com, Arthur O'Dwyer <arthur.j.odwyer@...il.com>, 
	Jonathan Wakely <jwakely@...hat.com>, Thiago Macieira <thiago@...ieira.org>
Subject: Re: Re: realloci(): A realloc() variant that works in-place

Hi Rich,

On Sat, Nov 01, 2025 at 02:10:17PM -0400, Rich Felker wrote:
> > Would this work?:
> > 
> > 	ssize_t realloci(void *p, size_t size);
> > 
> > Where realloci() allocates at least 'size' bytes (but possibly more),
> > and returns the actual usable size of the block.  So, you could
> > 
> > 		realloci(p, 3000);
> > 
> > and it would return for example 4096, which would be the usable size of
> > the block.  Or it would return -1 if it is unable to grow that much.
> > realloci() would never fail when shrinking, as it could just return a
> > larger size and be done with it.
> 
[...]
> 
> Actually returning a value larger than n seems bad (makes it
> impossible to detect OOB writes beyond the actually requested size)

You could still detect OOB writes beyond the requested size after
malloc(3) and realloc(3).  It would only be memory grown with realloci()
that you couldn't detect OOB writes beyond the requested size.

However, I don't see this as a problem.  If we consider that not as
a requested size, but as a hint, then we can consider that the size is
the value returned, and OOB writes beyond that size would still be
detected.

In the draft for v2 I'll send soon, I have this, which entirely ignores
the requested (hint) size:

	+size_t realloci(void *p, size_t n)
	+{
	+       struct meta *g = get_meta(p);
	+       int idx = get_slot_index(p);
	+       size_t stride = get_stride(g);
	+       unsigned char *start = g->mem->storage + stride*idx;
	+       unsigned char *end = start + stride - IB;
	+       size_t avail_size = end-(unsigned char *)p;
	+
	+       set_size(p, end, avail_size);
	+       return avail_size;
	+}

As you can see, it sets the size as 'avail_size', so OOB detectors still
work as expected.  It's just that the size is not 'n'.

> though so this seems like a dubious feature.


Have a lovely night!
Alex

> 
> Rich

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.