Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexec() interception broken on Ubuntu GLIBC 2.27 #1371

Closed
arichardson opened this issue Feb 9, 2021 · 2 comments
Closed

regexec() interception broken on Ubuntu GLIBC 2.27 #1371

arichardson opened this issue Feb 9, 2021 · 2 comments

Comments

@arichardson
Copy link

I was trying to use ASan to instrument a program that uses the REG_STARTSTOP flag for regexec.
This resulted in an inifite loop since this flag was being ignore. After lots of debugging I noticed that ASan instrumentation resulted in GLibc's __compat_regexec being called instead of __regexec.
The difference between those functions is that __compat_regexec strips the REG_STARTSTOP flag (https://code.woboq.org/userspace/glibc/posix/regexec.c.html#239).

I don't quite understand why dlsym gives the compat (the @GLIBC_2.2.5 version) symbol instead of the newer one (@GLIBC_2.3.4).
A small test program shows that resolving it using RTLD_DEFAULT finds the 2.3.4 version but RTLD_NEXT find 2.2.5:

#define _GNU_SOURCE

#include <regex.h>
#include <dlfcn.h>
#include <stdio.h>


__asm__(".symver __compat_regexec, regexec@GLIBC_2.2.5");
__asm__(".symver __regexec, regexec@GLIBC_2.3.4");
void __compat_regexec(void);
void __regexec(void);

int main() {
    printf("addrof regexec=%p\n", &regexec);
    printf("addrof __regexec=%p\n", &__regexec);
    printf("addrof __compat_regexec=%p\n", &__compat_regexec);
    printf("dlsym(RTLD_NEXT, regexec)=%p\n", dlsym(RTLD_NEXT, "regexec"));
    printf("dlsym(RTLD_DEFAULT, regexec)=%p\n", dlsym(RTLD_DEFAULT,"regexec"));
    printf("dlvsym(RTLD_NEXT, regexec@GLIBC_2.3.4)=%p\n", dlvsym(RTLD_NEXT, "regexec", "GLIBC_2.3.4"));
    printf("dlvsym(RTLD_DEFAULT, regexec@GLIBC_2.3.4)=%p\n", dlvsym(RTLD_DEFAULT, "regexec", "GLIBC_2.3.4"));
    printf("dlvsym(RTLD_NEXT, regexec@GLIBC_2.2.5)=%p\n", dlvsym(RTLD_NEXT, "regexec", "GLIBC_2.2.5"));
    printf("dlvsym(RTLD_DEFAULT, regexec@GLIBC_2.2.5)=%p\n", dlvsym(RTLD_DEFAULT, "regexec", "GLIBC_2.2.5"));
}

The output of this program on Ubuntu 18.04 is:

addrof regexec=0x7f3458cf8700
addrof __regexec=0x7f3458cf8700
addrof __compat_regexec=0x7f3458d5e540
dlsym(RTLD_NEXT, regexec)=0x7f3458d5e540
dlsym(RTLD_DEFAULT, regexec)=0x7f3458cf8700
dlvsym(RTLD_NEXT, regexec@GLIBC_2.3.4)=0x7f3458cf8700
dlvsym(RTLD_DEFAULT, regexec@GLIBC_2.3.4)=0x7f3458cf8700
dlvsym(RTLD_NEXT, regexec@GLIBC_2.2.5)=0x7f3458d5e540
dlvsym(RTLD_DEFAULT, regexec@GLIBC_2.2.5)=0x7f3458d5e540

I can see there is already a workaround fo realpath (llvm/llvm-project@77ef78a), maybe this needs a similar workaround (or we use dlvsym to resolve this symbol)?

Maybe it's sufficient to change
COMMON_INTERCEPT_FUNCTION(regexec);
to COMMON_INTERCEPT_FUNCTION_VER(regexec, "GLIBC_2.3.4"); if SANITIZER_GLIBC is defined?

@arichardson
Copy link
Author

https://reviews.llvm.org/D96348 fixes this.

arichardson added a commit to arichardson/freebsd that referenced this issue Feb 10, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 10, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 17, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 17, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 18, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 19, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 19, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 21, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 21, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 22, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 23, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 23, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 23, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 23, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 24, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 24, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 24, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 24, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 25, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Feb 25, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 1, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 1, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 2, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 3, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 3, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 4, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 4, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 5, 2021
Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371
arichardson added a commit to arichardson/freebsd that referenced this issue Mar 5, 2021
Summary:
sed: Fix a UBSan warning and clean up a pedantic few compiler warnings

This avoids adding a zero offset to a NULL pointer, but written in such
a way that the compiler can generate the same code as before. While
touching this file also clean up a few signed/unsigned warnings.

usr.bin/sed: Speed up vector grow

Double the size when we run out of space instead of using 1K at a time.
I noticed this while debugging an infinite loop due to
google/sanitizers#1371

usr.bin/sed: Add an assertion that REG_STARTEND

This was helpful while tracking down an ASan interceptor bug
(google/sanitizers#1371).

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D28557
arichardson added a commit to llvm/llvm-project that referenced this issue Mar 8, 2021
Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes google/sanitizers#1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
@arichardson
Copy link
Author

Fixed in llvm/llvm-project@ad294e5

arichardson added a commit to CTSRD-CHERI/llvm-project that referenced this issue Mar 31, 2021
Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes google/sanitizers#1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
jrtc27 pushed a commit to CTSRD-CHERI/compiler-rt that referenced this issue Jan 18, 2022
Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a0a5dbaa364529bd05ed7a7bd9a71dd8d4.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes google/sanitizers#1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Previously, on GLibc systems, the interceptor was calling __compat_regexec
(regexec@GLIBC_2.2.5) insead of the newer __regexec (regexec@GLIBC_2.3.4).
The __compat_regexec strips the REG_STARTEND flag but does not report an
error if other flags are present. This can result in infinite loops for
programs that use REG_STARTEND to find all matches inside a buffer (since
ignoring REG_STARTEND means that the search always starts from the first
character).

The underlying issue is that GLibc's dlsym(RTLD_NEXT, ...) appears to
always return the oldest versioned symbol instead of the default. This
means it does not match the behaviour of dlsym(RTLD_DEFAULT, ...) or the
behaviour documented in the manpage.

It appears a similar issue was encountered with realpath and worked around
in 77ef78a.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=14932 and
https://sourceware.org/bugzilla/show_bug.cgi?id=1319.

Fixes google/sanitizers#1371

Reviewed By: #sanitizers, vitalybuka, marxin

Differential Revision: https://reviews.llvm.org/D96348
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant