diff mbox series

[v8,10/10] mcheck Fix malloc_usable_size [BZ #22057]

Message ID 20210713073845.504356-11-siddhesh@sourceware.org
State Superseded
Headers show
Series malloc hooks removal | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Siddhesh Poyarekar July 13, 2021, 7:38 a.m. UTC
Interpose malloc_usable_size to return the correct mcheck value for
malloc_usable_size.
---
 malloc/Makefile       | 4 +---
 malloc/malloc-debug.c | 8 ++++++--
 malloc/mcheck-impl.c  | 6 ++++++
 3 files changed, 13 insertions(+), 5 deletions(-)

Comments

Carlos O'Donell July 17, 2021, 10:04 p.m. UTC | #1
On 7/13/21 3:38 AM, Siddhesh Poyarekar wrote:
> Interpose malloc_usable_size to return the correct mcheck value for
> malloc_usable_size.

OK for 2.34.

Tested without regression on x86_64 and i686.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>

> ---
>  malloc/Makefile       | 4 +---
>  malloc/malloc-debug.c | 8 ++++++--
>  malloc/mcheck-impl.c  | 6 ++++++
>  3 files changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/malloc/Makefile b/malloc/Makefile
> index c9504d0916..04c6b09949 100644
> --- a/malloc/Makefile
> +++ b/malloc/Makefile
> @@ -83,7 +83,7 @@ ifeq ($(have-GLIBC_2.24)$(build-shared),yesyes)
>  # the tests expect specific internal behavior that is changed due to linking to
>  # libmcheck.a.
>  tests-exclude-mcheck = tst-mallocstate \
> -	tst-safe-linking tst-malloc-usable \
> +	tst-safe-linking \

OK.

>  	tst-malloc-backtrace \
>  	tst-malloc-fork-deadlock \
>  	tst-malloc-stats-cancellation \
> @@ -92,8 +92,6 @@ tests-exclude-mcheck = tst-mallocstate \
>  	tst-malloc-thread-fail \
>  	tst-malloc-usable-tunables \
>  	tst-malloc_info \
> -	tst-pvalloc-fortify \
> -	tst-reallocarray \

OK.

>  	tst-compathooks-off tst-compathooks-on
>  
>  tests-mcheck = $(filter-out $(tests-exclude-mcheck), $(tests))
> diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
> index ef44546a4e..7968787ad6 100644
> --- a/malloc/malloc-debug.c
> +++ b/malloc/malloc-debug.c
> @@ -357,8 +357,12 @@ strong_alias (__debug_calloc, calloc)
>  size_t
>  malloc_usable_size (void *mem)
>  {
> -  return (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)
> -	  ? malloc_check_get_size (mem) : musable (mem));
> +  if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK))
> +    return mcheck_usable_size (mem);
> +  if (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK))
> +    return malloc_check_get_size (mem);
> +
> +  return musable (mem);

OK.

>  }
>  
>  #define LIBC_SYMBOL(sym) libc_ ## sym
> diff --git a/malloc/mcheck-impl.c b/malloc/mcheck-impl.c
> index 8857e6b179..6597a290a6 100644
> --- a/malloc/mcheck-impl.c
> +++ b/malloc/mcheck-impl.c
> @@ -404,3 +404,9 @@ __mcheck_initialize (void (*func) (enum mcheck_status), bool in_pedantic)
>    pedantic = in_pedantic;
>    return 0;
>  }
> +
> +static int
> +mcheck_usable_size (struct hdr *h)
> +{
> +  return (h - 1)->size;
> +}

OK.

>
diff mbox series

Patch

diff --git a/malloc/Makefile b/malloc/Makefile
index c9504d0916..04c6b09949 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -83,7 +83,7 @@  ifeq ($(have-GLIBC_2.24)$(build-shared),yesyes)
 # the tests expect specific internal behavior that is changed due to linking to
 # libmcheck.a.
 tests-exclude-mcheck = tst-mallocstate \
-	tst-safe-linking tst-malloc-usable \
+	tst-safe-linking \
 	tst-malloc-backtrace \
 	tst-malloc-fork-deadlock \
 	tst-malloc-stats-cancellation \
@@ -92,8 +92,6 @@  tests-exclude-mcheck = tst-mallocstate \
 	tst-malloc-thread-fail \
 	tst-malloc-usable-tunables \
 	tst-malloc_info \
-	tst-pvalloc-fortify \
-	tst-reallocarray \
 	tst-compathooks-off tst-compathooks-on
 
 tests-mcheck = $(filter-out $(tests-exclude-mcheck), $(tests))
diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c
index ef44546a4e..7968787ad6 100644
--- a/malloc/malloc-debug.c
+++ b/malloc/malloc-debug.c
@@ -357,8 +357,12 @@  strong_alias (__debug_calloc, calloc)
 size_t
 malloc_usable_size (void *mem)
 {
-  return (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK)
-	  ? malloc_check_get_size (mem) : musable (mem));
+  if (__is_malloc_debug_enabled (MALLOC_MCHECK_HOOK))
+    return mcheck_usable_size (mem);
+  if (__is_malloc_debug_enabled (MALLOC_CHECK_HOOK))
+    return malloc_check_get_size (mem);
+
+  return musable (mem);
 }
 
 #define LIBC_SYMBOL(sym) libc_ ## sym
diff --git a/malloc/mcheck-impl.c b/malloc/mcheck-impl.c
index 8857e6b179..6597a290a6 100644
--- a/malloc/mcheck-impl.c
+++ b/malloc/mcheck-impl.c
@@ -404,3 +404,9 @@  __mcheck_initialize (void (*func) (enum mcheck_status), bool in_pedantic)
   pedantic = in_pedantic;
   return 0;
 }
+
+static int
+mcheck_usable_size (struct hdr *h)
+{
+  return (h - 1)->size;
+}