You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2025/09/03 07:31:09 UTC

[Bug 69801] New: SIGSEGV during shutdown when using tomcat-native and certificate client auth

https://bz.apache.org/bugzilla/show_bug.cgi?id=69801

            Bug ID: 69801
           Summary: SIGSEGV during shutdown when using tomcat-native and
                    certificate client auth
           Product: Tomcat 10
           Version: 10.1.44
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Connectors
          Assignee: dev@tomcat.apache.org
          Reporter: mfusek@newps.cz
  Target Milestone: ------

tomcat native 2.0.9, apr 1.6.3, openssl 3.1.4, tomcat more versions in 10.1.4x

setClientAuth in JNI version of OpenSSLEngine should be somehow guarded against
calling during tomcat shutdown

    private void setClientAuth(ClientAuthMode mode) {
        if (clientMode) {
            return;
        }
        synchronized (this) {
            if (clientAuth == mode) {
                // No need to issue any JNI calls if the mode is the same
                return;
            }
            if (destroyed) {
                return new SSLEngineResult(SSLEngineResult.Status.CLOSED,
SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING,
                    0, 0);
            }
            switch (mode) {
                case NONE:
                    SSL.setVerify(state.ssl, SSL.SSL_CVERIFY_NONE,
certificateVerificationDepth);
                    break;

Because in other case tcn_ssl_ctxt_t::ctx is null

For me guard in tomcat-native ssl.c::setVerify also works

    if (c->verify_mode == SSL_CVERIFY_REQUIRE)
        verify |= SSL_VERIFY_PEER_STRICT;
    if ((c->verify_mode == SSL_CVERIFY_OPTIONAL) ||
        (c->verify_mode == SSL_CVERIFY_OPTIONAL_NO_CA))
        verify |= SSL_VERIFY_PEER;
    if (!c->store) {
        if (c->ctx == NULL) {
            tcn_ThrowException(e, "context->ctx is null");
            return;
        }
        c->store = SSL_CTX_get_cert_store(c->ctx);
    }

#7  0x00007f719b2dc692 in JVM_handle_linux_signal () from
/opt/nps-jdk17.0.16/lib/server/libjvm.so
#8  <signal handler called>
#9  SSL_CTX_get_cert_store (ctx=0x0) at ssl/ssl_lib.c:4565
#10 0x00007f71980e0f4e in Java_org_apache_tomcat_jni_SSL_setVerify
(e=0x7f712c005dd0, o=<optimized out>, ssl=140124314928336, level=<optimized
out>, depth=10) at src/ssl.c:1181

09:02:49.240 ERROR {catalina-exec-3} [o.a.t.u.n.NioEndpoint] : Error running
socket processor
java.lang.Exception: context->ctx is null
        at org.apache.tomcat.jni.SSL.setVerify(Native Method)
        at
org.apache.tomcat.util.net.openssl.OpenSSLEngine.setClientAuth(OpenSSLEngine.java:1132)
        at
org.apache.tomcat.util.net.openssl.OpenSSLEngine.setWantClientAuth(OpenSSLEngine.java:1107)
        at
java.base/javax.net.ssl.SSLEngine.setSSLParameters(SSLEngine.java:1340)
        at
org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLEngine(AbstractJsseEndpoint.java:163)
        at
org.apache.tomcat.util.net.SecureNioChannel.processSNI(SecureNioChannel.java:305)
        at
org.apache.tomcat.util.net.SecureNioChannel.handshake(SecureNioChannel.java:154)
        at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1753)
        at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:975)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:493)
        at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
        at java.base/java.lang.Thread.run(Thread.java:842)

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69801] SIGSEGV during shutdown when using tomcat-native and certificate client auth

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69801

--- Comment #2 from Martin FĂșsek <mf...@newps.cz> ---
Hi because it hapend when i reboot tomcat, whole standard output from tomcat

12:18:58.482 INFO  {main} [o.a.c.h.Http11NioProtocol] : Starting
ProtocolHandler ["https-openssl-nio-8453"]
12:42:41.347 INFO  {main} [o.a.c.h.Http11NioProtocol] : Pausing ProtocolHandler
["https-openssl-nio-8453"]
12:42:41.526 INFO  {main} [o.a.c.h.Http11NioProtocol] : Stopping
ProtocolHandler ["https-openssl-nio-8453"]
12:42:41.699 INFO  {main} [o.a.c.h.Http11NioProtocol] : Destroying
ProtocolHandler ["https-openssl-nio-8453"]
12:42:41.707 ERROR {catalina-exec-27} [o.a.t.u.n.NioEndpoint] : Error running
socket processor
java.lang.Exception: context->ctx is null
        at org.apache.tomcat.jni.SSL.setVerify(Native Method)
        at
org.apache.tomcat.util.net.openssl.OpenSSLEngine.setClientAuth(OpenSSLEngine.java:1132)
        at
org.apache.tomcat.util.net.openssl.OpenSSLEngine.setWantClientAuth(OpenSSLEngine.java:1107)
        at
java.base/javax.net.ssl.SSLEngine.setSSLParameters(SSLEngine.java:1340)
        at
org.apache.tomcat.util.net.AbstractJsseEndpoint.createSSLEngine(AbstractJsseEndpoint.java:163)
        at
org.apache.tomcat.util.net.SecureNioChannel.processSNI(SecureNioChannel.java:305)
        at
org.apache.tomcat.util.net.SecureNioChannel.handshake(SecureNioChannel.java:154)
        at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1753)
        at
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:975)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:493)
        at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
        at java.base/java.lang.Thread.run(Thread.java:842)
free(): invalid pointer

and stop.log

The stop command failed. Attempting to signal the process to stop through OS
signal.
Tomcat stopped.

and catalina.log

12:42:41.346 INFO  {main} [org.apache.catalina.core.StandardServer(615)] : A
valid shutdown command was received via the shutdown port. Stopping the Server
instance.
12:42:41.351 INFO  {main} [o.apache.catalina.core.StandardService(462)] :
Stopping service [Catalina]
12:42:41.459 WARN  {Catalina-utility-3}
[o.a.c.loader.WebappClassLoaderBase(1732)] : The web application [agw-ats5]
appears to have started a thread named [logback-1] but has failed to stop it.
This is very likely to create a memory leak. Stack trace of thread:
12:42:41.519 WARN  {Catalina-utility-2}
[o.a.c.loader.WebappClassLoaderBase(1732)] : The web application [agw-ats8]
appears to have started a thread named [logback-2] but has failed to stop it.
This is very likely to create a memory leak. Stack trace of thread:
12:42:48.105 ERROR {main} [org.apache.catalina.startup.Catalina(665)] : Could
not contact [localhost:8015] (base port [8015] and offset [0]). Tomcat may not
be running.
12:42:48.106 ERROR {main} [org.apache.catalina.startup.Catalina(668)] : Error
stopping Catalina
java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.connect0(Native Method)
        at java.base/sun.nio.ch.Net.connect(Net.java:579)
        at java.base/sun.nio.ch.Net.connect(Net.java:568)
        at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
        at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
        at java.base/java.net.Socket.connect(Socket.java:633)
        at java.base/java.net.Socket.connect(Socket.java:583)
        at java.base/java.net.Socket.<init>(Socket.java:507)
        at java.base/java.net.Socket.<init>(Socket.java:287)
        at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:657)
        at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:393)

We use old SUSE startup skript (SLES 12 SP2 time) but on SLES 15 SP6.

It crash only on one environment, for about an year, it don't do any harm, but
i dislike core dumps (because it overshadows real problems). I'm ok with my
local patch in tomcat native.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 69801] SIGSEGV during shutdown when using tomcat-native and certificate client auth

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=69801

Christopher Schultz <ch...@christopherschultz.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Christopher Schultz <ch...@christopherschultz.net> ---
Thanks for the report, this may be a good find, especially with your analysis
and proposed patch. Just about anything is better than a SIGSEGV.

Your report says "on shutdown" but the stack trace suggests that this happens
during the handshake. Can you give some more explanation?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org