GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — When shaded, `OpenSsl.isAvailable()` hangs on Alpine x86_64 · Issue #1024 · netty/netty-tcnative

When shaded, OpenSsl.isAvailable() hangs on Alpine x86_64 #1024

New issue
Copy link
New issue
Copy link
Closed
Closed
When shaded, OpenSsl.isAvailable() hangs on Alpine x86_64#1024
Copy link
Milestone
2.0.85.Final

Description

@dnault
dnault
opened on Oct 26, 2026
Issue body actions

Summary, written by a human

If the tc-native library is shaded/relocated, OpenSsl.isAvailable() hangs in an infinite loop in native code when running on Alpine x86_64.

The infinite loop is a regression in version 2.0.82; in earlier versions, OpenSsl.isAvailable() threw UnsatisfiedLinkError in this case, allowing the application to fall back to JDK TLS.

We ran into this at Couchbase, where we shade Netty and tc-native into the Couchbase JVM SDKs.

Root cause: the x86_64 musl fallbacks __strdup/__isinf/__isnan compile to infinite loops, causing hangs in JNI_OnLoad on Alpine.

This only happens when the library is shaded, because strdup is called only if the library has been shaded, in which case packagePrefix is not null:

netty-tcnative/openssl-dynamic/src/main/c/sslcontext.c

Lines 3259 to 3261 in 68007b7

if (packagePrefix != NULL) {
staticPackagePrefix = strdup(packagePrefix);
}

We suspect this only happens with the x86_64 artifact because it was built using an old Centos 6 toolchain; the working arm64 artifact appears to be using a Centos 7 toolchain.

The proposed fix (see below in the collapsed section) resolves the issue on Centos 6. An alternate solution might be to update the x86 builder to Centos 7, although we haven't explored that path.

Netty version

netty-tcnative-boringssl-static 2.0.82.Final through 2.0.84.Final, linux-x86_64.

JVM version

Not JVM-specific. Seen with Eclipse Temurin 21 on Alpine.

OS version

Alpine Linux 3.22 / 3.24 (musl 1.2.5), x86_64

AI analysis and proposed fix

The rest of this issue report, including the proposed fix, was generated by AI tools.

Click to expand the AI analysis

Expected behavior

On musl (Alpine Linux) x86_64, the weak fallbacks in openssl-dynamic/src/main/c/musl_compat.c (added in #997) behave like the glibc functions they replace.

Actual behavior

In the linux-x86_64 artifacts, __strdup, __isinf and __isnan compile to an infinite loop: a single jmp to themselves. Any call to them on musl never returns and spins a CPU core at 100%.

$ objdump -d --start-address=0x32ae0 --stop-address=0x32b10 libnetty_tcnative_linux_x86_64.so   # 2.0.84.Final
0000000000032ae0 <__isinf>:
   32ae0:  eb fe   jmp 32ae0 <__isinf>
0000000000032af0 <__isnan>:
   32af0:  eb fe   jmp 32af0 <__isnan>
0000000000032b00 <__strdup>:
   32b00:  eb fe   jmp 32b00 <__strdup>

The linux-aarch_64 artifact is correct: there, __strdup tail-calls strdup@plt, and __isinf/__isnan compute their results.

On glibc these fallbacks are never used, because glibc's own definitions win. On musl, libc doesn't define these names, so the library's PLT entries bind to the looping fallbacks.

Where it's hit. netty_internal_tcnative_SSLContext_JNI_OnLoad calls strdup(packagePrefix) when the package prefix is non-NULL:

310a1:  test  %r14,%r14            ; packagePrefix != NULL ?
310a4:  je    310b5
310a9:  call  __strdup@plt         ; staticPackagePrefix = strdup(packagePrefix)

So loading a relocated/shaded copy of the library on Alpine x86_64 hangs forever inside JNI_OnLoad (System.load never returns). Under its original name, the prefix is NULL, the call is skipped, and the library loads.

__isnan/__isinf are called from apr_vformatter, so formatting a NaN or infinite double through APR would hang the same way. We haven't seen that happen.

Cause

The x86_64 artifacts are built against glibc 2.12 headers (docker/Dockerfile.centos6: CentOS 6.10, devtoolset-9 GCC 9.1.1). In an optimized build there:

  • <bits/string2.h> defines #define strdup(s) __strdup (s).
  • <math.h> defines isinf(x) and isnan(x) as macros that call __isinf(x) and __isnan(x) for doubles.

musl_compat.c #undefs __strdup, __isinf and __isnan, but not strdup, isinf and isnan. So, for example:

TCN_MUSL_COMPAT char *__strdup(const char *str) {
    return strdup(str);   /* expands to: return __strdup (str); */
}

Each fallback calls itself, and GCC turns the unconditional self tail call into jmp self. Newer glibc headers don't have these macros, which is why the aarch64 build is fine.

Steps to reproduce

This needs no JVM. It uses the upstream netty-tcnative-boringssl-static-2.0.84.Final-linux-x86_64.jar (.so sha256 a5266540ec07da354fa4d4e0e1fd7798e99dcf7b41bbe3cffac2ba2683dc9a8a).

strdup_loop.c:

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

int main(int argc, char **argv) {
    void *lib = dlopen(argv[1], RTLD_LAZY);
    if (!lib) { printf("dlopen failed: %s\n", dlerror()); return 1; }
    char *(*fn)(const char *) = (char *(*)(const char *)) dlsym(lib, "__strdup");
    printf("libc defines __strdup: %s\n", dlsym(RTLD_DEFAULT, "__strdup") ? "yes" : "no");
    printf("calling the library's __strdup at %p...\n", (void *) fn);
    fflush(stdout);
    printf("__strdup(\"hello\") = %s\n", fn("hello"));
    return 0;
}
unzip -j netty-tcnative-boringssl-static-2.0.84.Final-linux-x86_64.jar META-INF/native/libnetty_tcnative_linux_x86_64.so
docker run --rm --platform linux/amd64 -v "$PWD:/w" -w /w alpine:3.22 sh -c \
  'apk add -q gcc musl-dev && gcc -o strdup_loop strdup_loop.c && timeout 20 ./strdup_loop /w/libnetty_tcnative_linux_x86_64.so; echo "exit=$?"'

The program asks the library for its __strdup and calls it once.

Output with 2.0.84.Final (the bug):

libc defines __strdup: no
calling the library's __strdup at 0x7fffff502b00...
Terminated
exit=143

How to read it:

  • libc defines __strdup: no: musl has no __strdup, so the library's own calls to __strdup bind to its fallback. On glibc this says yes, and those calls bind to glibc's __strdup instead. (This program calls the fallback directly through dlsym, so it would hang on glibc too; it only shows what the library's own calls hit on musl.)
  • The address ends in 2b00: the fallback at offset 0x32b00, the jmp to itself shown above.
  • __strdup("hello") = … never prints. The call doesn't return, and the process spins at 100% CPU until timeout kills it after 20 s. Terminated and exit=143 (128 + SIGTERM) come from that kill, not from the library crashing.

Output with the fix (the patched musl_compat.c below, compiled the same way the release does; see "Tested"):

libc defines __strdup: no
calling the library's __strdup at 0x7fffff755240...
__strdup("hello") = hello
exit=0

Here the fallback is still used, since musl still has no __strdup, but it forwards to musl's strdup and returns right away.

Proposed fix

In musl_compat.c:

 /* glibc-internal math aliases emitted via APR's configure-era headers. */
 TCN_MUSL_COMPAT int __isinf(double value) {
-    return isinf(value);
+    /* Not isinf(): old glibc (e.g. 2.12) defines it as a macro calling __isinf.
+       Not (isinf)(): musl has no isinf function symbol. */
+    return __builtin_isinf_sign(value);
 }
 
 TCN_MUSL_COMPAT int __isnan(double value) {
-    return isnan(value);
+    return __builtin_isnan(value);
 }
 
 /* glibc-internal alias APR links against directly. */
 TCN_MUSL_COMPAT char *__strdup(const char *str) {
-    return strdup(str);
+    /* Parentheses suppress old glibc's (e.g. 2.12) `#define strdup(s) __strdup (s)`,
+       which would otherwise make this call itself. */
+    return (strdup)(str);
 }

__builtin_isinf_sign keeps glibc's exact result for __isinf (-1 for negative infinity, 1 for positive), where __builtin_isinf would return 1 for both.

Tested. We compiled the original and the patched file the way the release build does: centos:6.10 with devtoolset-9 GCC 9.1.1 (glibc-devel 2.12), -O3 -Werror -fno-omit-frame-pointer -fvisibility=hidden -Wunused -Wno-unused-value -D_LARGEFILE64_SOURCE -fPIC -shared.

  • Original: all three fallbacks compile to jmp self, exactly as in the released artifact. gcc -E shows why: return __strdup (str);, and isinf/isnan expand to ... ? __isinf (value) : ....
  • Patched: it compiles cleanly. __strdup compiles to jmp strdup@plt, and __isinf/__isnan compile to inline SSE code with no calls.

We then called each fallback through dlsym on Alpine 3.22 x86_64 (musl), and compared with glibc 2.12's own functions on CentOS 6:

Call Original on musl Patched on musl glibc 2.12
__strdup("hello") hangs "hello" (new copy) "hello" (new copy)
__isinf(1.0 / +inf / -inf / nan) hangs 0 / 1 / -1 / 0 0 / 1 / -1 / 0
__isnan(1.0 / +inf / -inf / nan) hangs 0 / 0 / 0 / 1 0 / 0 / 0 / 1

We didn't rebuild netty-tcnative itself. To check that fixing these fallbacks is enough, we ran the released, relocated 2.0.84 library on Alpine x86_64 with the patched fallbacks LD_PRELOADed, so musl binds __strdup/__isinf/__isnan to them. OpenSsl.isAvailable() returned true. An in-memory handshake between BoringSSL client and server engines then completed (TLSv1.3, TLS_AES_128_GCM_SHA256), and data was exchanged both ways. Without the preload, the same test hangs.

Related hardening

  • fopen64 has the same trap under -D_FILE_OFFSET_BITS=64. glibc then renames fopen to fopen64, so the fallback compiles to jmp fopen64@plt, which binds back to itself on musl. The release build doesn't pass that flag today, but a guard would keep it from regressing silently: #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 / #error in musl_compat.c.
  • docker/musl-verify can't see this class of bug. MuslLoadCheck loads the library under its original name, so the package prefix is NULL and __strdup is never called. The symbol check is also satisfied by the weak definitions themselves. Calling each fallback through dlsym, as in the repro above, would catch a fallback that loops or calls itself.

Why arm64 isn't affected

Short answer: the aarch64 build uses newer glibc headers. There, strdup isn't rewritten to __strdup, so the shaded path never reaches the looping fallback.

What differs

x86_64 aarch64
Build image centos:6.10 CentOS 7, Arm GNU toolchain GCC 10.2 (cross-compile)
glibc headers 2.12 2.26 or newer (inferred from the binary, not confirmed)
Shaded strdup(packagePrefix) compiles to call __strdup@plt bl strdup@plt
On musl, the call binds to the library's own fallback, which loops musl's strdup
Fallback __strdup / __isinf / __isnan jmp self (infinite loop) correct

Why

Old glibc headers define macros that turn calls into their __-prefixed glibc-internal names:

glibc headers strdup → __strdup macro isinf(x) expands to
2.12, 2.17 yes __isinf (x)
2.25 yes __builtin_isinf_sign (x)
2.26+ removed __builtin_isinf_sign (x)

Takeaways

  • The cause is CentOS 6's old glibc headers, not x86_64 as such.
  • The strdup macro was removed in glibc 2.26, so "glibc < 2.26" in the draft's patch comment is correct.
  • musl_compat.c already #undefs __strdup because of glibc 2.17's headers, but it misses the strdup → __strdup macro in those same headers.

Activity

  1. normanmaurer
    added this to the 2.0.85.Final milestone on Oct 29, 2026
  2. normanmaurer
    added a commit that references this issue on Oct 29, 2026

    Fix infinite loop in musl_compat fallbacks on old glibc headers (#1037)

    9e9ed1d
  3. normanmaurer
    closed this as completedon Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 2.0.85.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.