[PATCH] Add Safe-Linking to fastbins and tcache

Andreas Schwab schwab@suse.de
Mon Mar 30 08:01:35 GMT 2020


On Mär 20 2020, Eyal Itkin via Libc-alpha wrote:

> @@ -2960,7 +2979,10 @@ tcache_thread_shutdown (void)
>        while (tcache_tmp->entries[i])
>  	{
>  	  tcache_entry *e = tcache_tmp->entries[i];
> -	  tcache_tmp->entries[i] = e->next;
> +      if (__glibc_unlikely (!aligned_OK (e)))
> +        malloc_printerr ("tcache_thread_shutdown(): " \
> +                         "unaligned tcache chunk detected");
> +	  tcache_tmp->entries[i] = REVEAL_PTR (e->next);
>  	  __libc_free (e);

Wrong indentation, extra backslash.

> @@ -4196,11 +4226,15 @@ _int_free (mstate av, mchunkptr p, int have_lock)
>  	    LIBC_PROBE (memory_tcache_double_free, 2, e, tc_idx);
>  	    for (tmp = tcache->entries[tc_idx];
>  		 tmp;
> -		 tmp = tmp->next)
> +		 tmp = REVEAL_PTR (tmp->next))
> +        {
> +	      if (__glibc_unlikely (!aligned_OK (tmp)))
> +		malloc_printerr ("free(): unaligned chunk detected in tcache 2");
>  	      if (tmp == e)
>  		malloc_printerr ("free(): double free detected in tcache 2");
>  	    /* If we get here, it was a coincidence.  We've wasted a
>  	       few cycles, but don't abort.  */
> +        }

Wrong indentation.

> @@ -4896,8 +4935,13 @@ int_mallinfo (mstate av, struct mallinfo *m)
>  
>    for (i = 0; i < NFASTBINS; ++i)
>      {
> -      for (p = fastbin (av, i); p != 0; p = p->fd)
> +      for (p = fastbin (av, i);
> +           p != 0;
> +           p = REVEAL_PTR (p->fd))
>          {
> +          if (__glibc_unlikely (!aligned_OK (p)))
> +            malloc_printerr ("int_mallinfo(): " \
> +                             "unaligned fastbin chunk detected");

Extra backslash.

> @@ -5437,8 +5481,11 @@ __malloc_info (int options, FILE *fp)
>  
>  	      while (p != NULL)
>  		{
> +          if (__glibc_unlikely (!aligned_OK (p)))
> +            malloc_printerr ("__malloc_info(): " \
> +                             "unaligned fastbin chunk detected");
>  		  ++nthissize;

Wrong indentation, extra backslash.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


More information about the Libc-alpha mailing list