public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Possible glibc 2.35 ARM regression in LD_BIND_NOT
@ 2022-07-04 19:14 Nathan Nye
  2022-07-04 19:31 ` Nathan Nye
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Nye @ 2022-07-04 19:14 UTC (permalink / raw)
  To: libc-help


[-- Attachment #1.1.1: Type: text/plain, Size: 687 bytes --]

Good afternoon,

I'm reviewing what could be a regression in LD_BIND_NOT's functionality 
in glibc 2.35 on ARM architectures (there were a few recent ARM audit 
changes). Symbol binding only occurs a single time on glibc 2.35/ARM, 
even when LD_BIND_NOT is enabled. I've tested:

  * Ubuntu 22.04 x86_64 glibc 2.35
  * Ubuntu 20.04 ARM glibc 2.34
  * Ubuntu 22.04 ARM glibc 2.35

I could use a second pair of eyes on this issue to verify it exists. 
Here is the test case I cobbled together, please excuse the poor C code 
I wrote while testing: https://pastebin.com/raw/HSSYjemj

I've also attached the test case to this email. Thanks!

Very respectfully,
Nathan Nye

[-- Attachment #1.1.2: ldbindnot235.txt --]
[-- Type: text/plain, Size: 1214 bytes --]

runevp.c:
// gcc runevp.c -o runevp
#include <stdio.h>
#include <unistd.h>

int main() {
    int i;
    for (i=0; i < 5; i++) {
        if(fork()==0) {
            execvp("true", NULL);
        }
    }
    return 0;
}

auditlib.c:
// gcc -Wall -fPIC -shared -o auditlib.so auditlib.c
#include <link.h>
#include <stdio.h>
typedef long int Lmid_t;
unsigned int la_version(unsigned int version) { return version; }
unsigned int la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie) { return 3; }
uintptr_t la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook, uintptr_t *defcook, unsigned int *flags, const char *symname) {
    if (strcmp(symname, "execvp") == 0) {
        printf("symbol binding for '%s'\n", symname);
    }
    return sym->st_value;
}

Any glibc release except glibc 2.35 on ARM: Symbol binding occurs repeatedly (LD_BIND_NOT)
$ LD_AUDIT=/path/to/auditlib.so LD_BIND_NOT=1 ./runevp
symbol binding for 'execvp'
symbol binding for 'execvp'
symbol binding for 'execvp'
symbol binding for 'execvp'
symbol binding for 'execvp'

glibc 2.35 on ARM: Symbol binding occurs once (ignores LD_BIND_NOT)
$ LD_AUDIT=/path/to/auditlib.so LD_BIND_NOT=1 ./runevp
symbol binding for 'execvp'

[-- Attachment #1.1.3: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 673 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible glibc 2.35 ARM regression in LD_BIND_NOT
  2022-07-04 19:14 Possible glibc 2.35 ARM regression in LD_BIND_NOT Nathan Nye
@ 2022-07-04 19:31 ` Nathan Nye
  2022-07-05 14:34   ` Nathan Nye
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Nye @ 2022-07-04 19:31 UTC (permalink / raw)
  To: libc-help


[-- Attachment #1.1.1: Type: text/plain, Size: 966 bytes --]

+Adhemerval

Hi Adhemerval,

I think you may know the relevant source best if this issue exists. Your 
feedback would be really valuable if you're able to test it.

Very respectfully,
Nathan Nye

On 7/4/22 3:14 PM, Nathan Nye wrote:
> Good afternoon,
>
> I'm reviewing what could be a regression in LD_BIND_NOT's 
> functionality in glibc 2.35 on ARM architectures (there were a few 
> recent ARM audit changes). Symbol binding only occurs a single time on 
> glibc 2.35/ARM, even when LD_BIND_NOT is enabled. I've tested:
>
>   * Ubuntu 22.04 x86_64 glibc 2.35
>   * Ubuntu 20.04 ARM glibc 2.34
>   * Ubuntu 22.04 ARM glibc 2.35
>
> I could use a second pair of eyes on this issue to verify it exists. 
> Here is the test case I cobbled together, please excuse the poor C 
> code I wrote while testing: https://pastebin.com/raw/HSSYjemj
>
> I've also attached the test case to this email. Thanks!
>
> Very respectfully,
> Nathan Nye


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 673 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible glibc 2.35 ARM regression in LD_BIND_NOT
  2022-07-04 19:31 ` Nathan Nye
@ 2022-07-05 14:34   ` Nathan Nye
  2022-07-05 17:04     ` Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: Nathan Nye @ 2022-07-05 14:34 UTC (permalink / raw)
  To: libc-help


[-- Attachment #1.1.1: Type: text/plain, Size: 1415 bytes --]

All,

I isolated the issue. When compiling binaries using gcc on Ubuntu 20.04 
or below, the resulting binary does not have PIE - regardless of the 
-pie argument being passed to the compiler. Ubuntu 22.04 correctly 
reflects the default build flags being PIE and the binaries have PIE 
unless the arguments passed to gcc include -no-pie.

Thanks,
Nathan Nye

On 7/4/22 3:31 PM, Nathan Nye wrote:
> +Adhemerval
>
> Hi Adhemerval,
>
> I think you may know the relevant source best if this issue exists. 
> Your feedback would be really valuable if you're able to test it.
>
> Very respectfully,
> Nathan Nye
>
> On 7/4/22 3:14 PM, Nathan Nye wrote:
>> Good afternoon,
>>
>> I'm reviewing what could be a regression in LD_BIND_NOT's 
>> functionality in glibc 2.35 on ARM architectures (there were a few 
>> recent ARM audit changes). Symbol binding only occurs a single time 
>> on glibc 2.35/ARM, even when LD_BIND_NOT is enabled. I've tested:
>>
>>   * Ubuntu 22.04 x86_64 glibc 2.35
>>   * Ubuntu 20.04 ARM glibc 2.34
>>   * Ubuntu 22.04 ARM glibc 2.35
>>
>> I could use a second pair of eyes on this issue to verify it exists. 
>> Here is the test case I cobbled together, please excuse the poor C 
>> code I wrote while testing: https://pastebin.com/raw/HSSYjemj
>>
>> I've also attached the test case to this email. Thanks!
>>
>> Very respectfully,
>> Nathan Nye
>


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 673 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Possible glibc 2.35 ARM regression in LD_BIND_NOT
  2022-07-05 14:34   ` Nathan Nye
@ 2022-07-05 17:04     ` Adhemerval Zanella
  0 siblings, 0 replies; 4+ messages in thread
From: Adhemerval Zanella @ 2022-07-05 17:04 UTC (permalink / raw)
  To: Nathan Nye; +Cc: libc-help



> On 5 Jul 2022, at 11:34, Nathan Nye <nnye@whitebeamsec.com> wrote:
> 
> All,
> 
> I isolated the issue. When compiling binaries using gcc on Ubuntu 20.04 or below, the resulting binary does not have PIE - regardless of the -pie argument being passed to the compiler. Ubuntu 22.04 correctly reflects the default build flags being PIE and the binaries have PIE unless the arguments passed to gcc include -no-pie.
> 
> Thanks,
> Nathan Nye

The problem is not in fact PIE, but rather that newer toolchain default to
bindnow. Using the provided example on 

* Ubuntu 14 (glibc 2.19), Ubuntu 16 (glibc 2.23), and Ubuntu 18 (glibc 2.27)

$ gcc -Wall runevp.c -o runevp -Wl,-z,lazy
$ gcc -Wall -fPIC -shared -o auditlib.so auditlib.c
$ LD_AUDIT=./auditlib.so LD_BIND_NOT=1 LD_BIND_NOW=1 ./runevp
$

* And on Ubuntu 22.04 (glibc 2.35)

$ gcc -Wall runevp.c -o runevp -Wl,-z,lazy
$ gcc -Wall -fPIC -shared -o auditlib.so auditlib.c
$ LD_AUDIT=./auditlib.so LD_BIND_NOT=1 LD_BIND_NOW=1 ./runevp
symbol binding for ‘execvp'

On glibc 2.34 we now see a bind-now la_symbind event, different than
previous version.  If you build with -Wl,-z,lazy we will see the previous
behavior where la_symbind will be called on each symbol resolution.

Now for LD_BIND_NOT and bind-now, I think this is the correct behavior:
we need to always update the GOT entry since runtime won’t setup a
lazy resolution PLT entry (symbols resolution is always setup at 
startup phase).  Otherwise we will need to add a hack similar to
LD_PROFILE and I really don’t think this is the best strategy.

> 
> On 7/4/22 3:31 PM, Nathan Nye wrote:
>> +Adhemerval
>> 
>> Hi Adhemerval,
>> 
>> I think you may know the relevant source best if this issue exists. Your feedback would be really valuable if you're able to test it.
>> 
>> Very respectfully,
>> Nathan Nye
>> 
>> On 7/4/22 3:14 PM, Nathan Nye wrote:
>>> Good afternoon,
>>> 
>>> I'm reviewing what could be a regression in LD_BIND_NOT's functionality in glibc 2.35 on ARM architectures (there were a few recent ARM audit changes). Symbol binding only occurs a single time on glibc 2.35/ARM, even when LD_BIND_NOT is enabled. I've tested:
>>> 	• Ubuntu 22.04 x86_64 glibc 2.35
>>> 	• Ubuntu 20.04 ARM glibc 2.34
>>> 	• Ubuntu 22.04 ARM glibc 2.35
>>> I could use a second pair of eyes on this issue to verify it exists. Here is the test case I cobbled together, please excuse the poor C code I wrote while testing: https://pastebin.com/raw/HSSYjemj
>>> 
>>> I've also attached the test case to this email. Thanks!
>>> 
>>> Very respectfully,
>>> Nathan Nye
>> 
> 
> <OpenPGP_0xCB7269934F16882E.asc>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-05 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04 19:14 Possible glibc 2.35 ARM regression in LD_BIND_NOT Nathan Nye
2022-07-04 19:31 ` Nathan Nye
2022-07-05 14:34   ` Nathan Nye
2022-07-05 17:04     ` Adhemerval Zanella

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).