* Re: [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34
[not found] <20231024143144.76490-1-vincent@vinc17.net>
@ 2023-10-24 15:32 ` Alejandro Colomar
2023-10-24 16:28 ` Adhemerval Zanella Netto
0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2023-10-24 15:32 UTC (permalink / raw)
To: Vincent Lefevre; +Cc: linux-man, GNU C Library
[-- Attachment #1: Type: text/plain, Size: 1974 bytes --]
Hi Vincent,
On Tue, Oct 24, 2023 at 04:31:17PM +0200, Vincent Lefevre wrote:
> The glibc 2.34 NEWS file says that mtrace() and mcheck() have now been
> disabled in the main C library, and preloading libc_malloc_debug.so is
Can you please clarify "disabled"? What is the behavior if that library
is not preloaded? My attempt to run this program is that mcheck(3)
returns -1. So, the preload interposes the dummy function that only
returns -1 with an actual mcheck(3) implementation?
Are these functions deprecated by glibc? If so, we should probably use
[[deprecated]] in the SYNOPSIS. Or did they just move the functionality
for other reasons but without deprecating?
Should we document the need for LD_PRELOAD in the LIBRARY section?
Thanks,
Alex
> needed to get this functionality back.
>
> So the examples now need a "LD_PRELOAD=libc_malloc_debug.so".
>
> Signed-off-by: Vincent Lefevre <vincent@vinc17.net>
> ---
> man3/mcheck.3 | 2 +-
> man3/mtrace.3 | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/man3/mcheck.3 b/man3/mcheck.3
> index 285ea946c..e17650a4c 100644
> --- a/man3/mcheck.3
> +++ b/man3/mcheck.3
> @@ -169,7 +169,7 @@ when running the program:
> .PP
> .in +4n
> .EX
> -.RB "$" " ./a.out"
> +.RB "$ " "LD_PRELOAD=libc_malloc_debug.so ./a.out"
> About to free
> \&
> About to free a second time
> diff --git a/man3/mtrace.3 b/man3/mtrace.3
> index f30511cd0..d0cde42c9 100644
> --- a/man3/mtrace.3
> +++ b/man3/mtrace.3
> @@ -153,7 +153,7 @@ diagnosed memory leaks at two different locations in the program:
> .EX
> .RB "$ " "cc \-g t_mtrace.c \-o t_mtrace"
> .RB "$ " "export MALLOC_TRACE=/tmp/t"
> -.RB "$ " "./t_mtrace"
> +.RB "$ " "LD_PRELOAD=libc_malloc_debug.so ./t_mtrace"
> .RB "$ " "mtrace ./t_mtrace $MALLOC_TRACE"
> Memory not freed:
> -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
> --
> 2.42.0
>
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34
2023-10-24 15:32 ` [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34 Alejandro Colomar
@ 2023-10-24 16:28 ` Adhemerval Zanella Netto
2023-10-24 18:44 ` Alejandro Colomar
0 siblings, 1 reply; 4+ messages in thread
From: Adhemerval Zanella Netto @ 2023-10-24 16:28 UTC (permalink / raw)
To: Alejandro Colomar, Vincent Lefevre; +Cc: linux-man, GNU C Library
On 24/10/23 12:32, Alejandro Colomar wrote:
> Hi Vincent,
>
> On Tue, Oct 24, 2023 at 04:31:17PM +0200, Vincent Lefevre wrote:
>> The glibc 2.34 NEWS file says that mtrace() and mcheck() have now been
>> disabled in the main C library, and preloading libc_malloc_debug.so is
>
> Can you please clarify "disabled"? What is the behavior if that library
> is not preloaded? My attempt to run this program is that mcheck(3)
> returns -1. So, the preload interposes the dummy function that only
> returns -1 with an actual mcheck(3) implementation?
The libc mcheck and mcheck_pedantic now return -1, while mprobe returns
MCHECK_DISABLED. All the implementation that used to live in libc.so
were moved to libc_malloc_debug.so.
>
> Are these functions deprecated by glibc? If so, we should probably use
> [[deprecated]] in the SYNOPSIS. Or did they just move the functionality
> for other reasons but without deprecating?
There is no deprecation because the functionality is still fully supported,
albeit in a different library. Setting to deprecated would require to move
the prototypes to a different header.
>
> Should we document the need for LD_PRELOAD in the LIBRARY section?
Yes, I think it would be better.
>
> Thanks,
> Alex
>
>> needed to get this functionality back.
>>
>> So the examples now need a "LD_PRELOAD=libc_malloc_debug.so".
>>
>> Signed-off-by: Vincent Lefevre <vincent@vinc17.net>
>> ---
>> man3/mcheck.3 | 2 +-
>> man3/mtrace.3 | 2 +-
>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/man3/mcheck.3 b/man3/mcheck.3
>> index 285ea946c..e17650a4c 100644
>> --- a/man3/mcheck.3
>> +++ b/man3/mcheck.3
>> @@ -169,7 +169,7 @@ when running the program:
>> .PP
>> .in +4n
>> .EX
>> -.RB "$" " ./a.out"
>> +.RB "$ " "LD_PRELOAD=libc_malloc_debug.so ./a.out"
>> About to free
>> \&
>> About to free a second time
>> diff --git a/man3/mtrace.3 b/man3/mtrace.3
>> index f30511cd0..d0cde42c9 100644
>> --- a/man3/mtrace.3
>> +++ b/man3/mtrace.3
>> @@ -153,7 +153,7 @@ diagnosed memory leaks at two different locations in the program:
>> .EX
>> .RB "$ " "cc \-g t_mtrace.c \-o t_mtrace"
>> .RB "$ " "export MALLOC_TRACE=/tmp/t"
>> -.RB "$ " "./t_mtrace"
>> +.RB "$ " "LD_PRELOAD=libc_malloc_debug.so ./t_mtrace"
>> .RB "$ " "mtrace ./t_mtrace $MALLOC_TRACE"
>> Memory not freed:
>> -\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
>> --
>> 2.42.0
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34
2023-10-24 16:28 ` Adhemerval Zanella Netto
@ 2023-10-24 18:44 ` Alejandro Colomar
2023-10-24 19:28 ` DJ Delorie
0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2023-10-24 18:44 UTC (permalink / raw)
To: Adhemerval Zanella Netto; +Cc: Vincent Lefevre, linux-man, GNU C Library
[-- Attachment #1: Type: text/plain, Size: 2578 bytes --]
Hi Adhemerval,
On Tue, Oct 24, 2023 at 01:28:06PM -0300, Adhemerval Zanella Netto wrote:
> On 24/10/23 12:32, Alejandro Colomar wrote:
> > On Tue, Oct 24, 2023 at 04:31:17PM +0200, Vincent Lefevre wrote:
> >> The glibc 2.34 NEWS file says that mtrace() and mcheck() have now been
> >> disabled in the main C library, and preloading libc_malloc_debug.so is
> >
> > Can you please clarify "disabled"? What is the behavior if that library
> > is not preloaded? My attempt to run this program is that mcheck(3)
> > returns -1. So, the preload interposes the dummy function that only
> > returns -1 with an actual mcheck(3) implementation?
>
> The libc mcheck and mcheck_pedantic now return -1, while mprobe returns
> MCHECK_DISABLED. All the implementation that used to live in libc.so
> were moved to libc_malloc_debug.so.
Ok. This should probably be documented.
>
> >
> > Are these functions deprecated by glibc? If so, we should probably use
> > [[deprecated]] in the SYNOPSIS. Or did they just move the functionality
> > for other reasons but without deprecating?
>
> There is no deprecation because the functionality is still fully supported,
> albeit in a different library. Setting to deprecated would require to move
> the prototypes to a different header.
Why was it moved to a different library? I guess it wasn't often used,
maybe? This should probably go to a HISTORY section.
Regarding the move, maybe I'm doing something wrong, but I'd expect the
following to work (but it doesn't):
$ cc -Wall -Wextra mcheck.c -lc_malloc_debug -lc
mcheck.c: In function ‘main’:
mcheck.c:21:12: warning: pointer ‘p’ used after ‘free’ [-Wuse-after-free]
21 | free(p);
| ^~~~~~~
mcheck.c:19:12: note: call to ‘free’ here
19 | free(p);
| ^~~~~~~
$ ./a.out
mcheck() failed
$ ldd ./a.out
linux-vdso.so.1 (0x00007fff048de000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f82fe810000)
/lib64/ld-linux-x86-64.so.2 (0x00007f82fea0c000)
Do you know why this program isn't linking correctly to
libc_malloc_debug?
Thanks,
Alex
> >
> > Should we document the need for LD_PRELOAD in the LIBRARY section?
>
> Yes, I think it would be better.
>
> >
> > Thanks,
> > Alex
> >
> >> needed to get this functionality back.
> >>
> >> So the examples now need a "LD_PRELOAD=libc_malloc_debug.so".
> >>
> >> Signed-off-by: Vincent Lefevre <vincent@vinc17.net>
--
<https://www.alejandro-colomar.es/>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34
2023-10-24 18:44 ` Alejandro Colomar
@ 2023-10-24 19:28 ` DJ Delorie
0 siblings, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2023-10-24 19:28 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: adhemerval.zanella, vincent, linux-man, libc-alpha
Alejandro Colomar <alx@kernel.org> writes:
> Why was it moved to a different library?
Security. Moving unneeded code out of libc.so makes it unavailable to
hackers. The malloc-related code in glibc is a common target for such
things.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-10-24 19:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20231024143144.76490-1-vincent@vinc17.net>
2023-10-24 15:32 ` [PATCH] mcheck.3, mtrace.3: update examples for glibc 2.34 Alejandro Colomar
2023-10-24 16:28 ` Adhemerval Zanella Netto
2023-10-24 18:44 ` Alejandro Colomar
2023-10-24 19:28 ` DJ Delorie
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 read-only IMAP folder(s) and NNTP newsgroup(s).