[jdk8u-dev] RFR: 8173339: AArch64: Fix minimum stack size computations [v2]

Dongbo He dongbohe at openjdk.org
Fri Aug 26 14:34:09 UTC 2022


On Thu, 30 Jun 2022 03:34:39 GMT, Dongbo He <dongbohe at openjdk.org> wrote:

>> Hi,
>> 
>> I would like to backport this patch to fix minimum stack size computations on AArch64.
>> I updated the value directly on `define_pd_global` because [JDK-8078556](https://bugs.openjdk.java.net/browse/JDK-8078556) is not in 8u.
>> 
>> Testing: Performed full jtreg test aarch64-linux-gnu platforms with 4k page size.
>> Following test case worked correctly after patch.
>> Before patch:
>> $ java TLSStackOverflow
>> [1]    35476 segmentation fault (core dumped) java TLSStackOverflow
>> After patch:
>> $ java TLSStackOverflow
>> got expected stackoverflow, passed
>> 
>> $ keytool -genkey -keyalg RSA -keystore localhost-rsa.jks -storepass changeit -storetype pkcs12
>> $ cat TLSStackOverflow.java
>> 
>> import javax.net.ServerSocketFactory;
>> import javax.net.SocketFactory;
>> import javax.net.ssl.*;
>> import java.io.*;
>> import java.net.InetAddress;
>> import java.net.InetSocketAddress;
>> import java.net.Socket;
>> import java.security.KeyStore;
>> import java.security.KeyStoreException;
>> import java.security.NoSuchAlgorithmException;
>> import java.security.SecureRandom;
>> import java.security.cert.CertificateException;
>> import java.security.cert.X509Certificate;
>> 
>> public class TLSStackOverflow
>> {
>> 
>>     private static final String keystore = "/home/hedongbo/myprojects/study/stackoverflow/new/localhost-rsa.jks";
>>     private static final char[] passphrase = "changeit".toCharArray();
>>     private static final int port = 8447;
>> 
>>     private static KeyStore pfx = null;
>> 
>>     public static void doWrite(OutputStream out) throws Exception {
>>         out.write("hello".getBytes(), 0, 3);
>>         out.flush();
>>         doWrite(out);
>>     }
>> 
>>     public TLSStackOverflow()
>>     {}
>> 
>>     public static void main(String[] args) throws Exception
>>     {
>>         new Thread(() -> {
>>             try {
>>                 pfx = KeyStore.getInstance("PKCS12");
>>                 pfx.load(new FileInputStream(keystore), passphrase);
>>                 SSLContext ctx = SSLContext.getInstance("TLS");
>>                 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
>>                 kmf.init(pfx, passphrase);
>>                 KeyManager[] kms = kmf.getKeyManagers();
>>                 ctx.init(kms, null, null);
>>                 ServerSocketFactory fact = ctx.getServerSocketFactory();
>>                 SSLServerSocket serversocket = (SSLServerSocket) fact.createServerSocket(port);
>>                 while (true)
>>                 {
>>                     Socket socket = null;
>>                     try
>>                     {
>>                         socket = serversocket.accept();
>> 
>>                         DataInputStream in = new DataInputStream(socket.getInputStream());
>>                         DataOutputStream out = new DataOutputStream(socket.getOutputStream());
>> 
>>                         byte[] buf = new byte[8192];
>>                         int len = in.read(buf);
>>                     }
>>                     catch (Exception e)
>>                     {
>>                         e.printStackTrace();
>>                     }
>>                     finally
>>                     {
>> //                        try
>> //                        {
>> //                            socket.close();
>> //                        }
>> //                        catch (Exception e) {
>> //                            e.printStackTrace();
>> //                        }
>>                     }
>>                 }
>>             } catch (Exception e) {
>>                 e.printStackTrace();
>>             }
>>         }).start();
>> 
>>         Thread.sleep(2000);
>> 
>>         new Thread(() -> {
>>             SSLSocket socket = null;
>>             try {
>>                 pfx = KeyStore.getInstance("PKCS12");
>>                 pfx.load(new FileInputStream(keystore), passphrase);
>>                 SSLContext ctx = SSLContext.getInstance("TLS");
>>                 KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
>>                 kmf.init(pfx, passphrase);
>>                 TrustAllManager[] trust = { new TrustAllManager() };
>>                 ctx.init(null, trust, null);
>>                 SocketFactory fact = ctx.getSocketFactory();
>>                 socket = (SSLSocket) fact.createSocket();
>>                 socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 2000);
>>                 socket.setTcpNoDelay(true);
>>                 socket.startHandshake();
>> 
>>                 DataInputStream in = new DataInputStream(socket.getInputStream());
>>                 DataOutputStream out = new DataOutputStream(socket.getOutputStream());
>> 
>>                 String s = "GET " + " HTTP/1.1\r\n";
>>                 s+= "Accept: */*\r\n";
>>                 s+= "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)\r\n";
>>                 s+= "Connection: Close\r\n";
>>                 s+= "\r\n";
>>                 try {
>>                     doWrite(out);
>>                 } catch (StackOverflowError e) {
>>                     System.out.println("got expected stackoverflow, passed");
>>                     System.exit(0);
>>                 }
>> 
>>                 byte[] buf = new byte[8192];
>>                 int len = in.read(buf);
>>                 if (len == -1)
>>                 {
>>                     System.out.println("eof");
>>                     return;
>>                 }
>>                 System.out.println(new String(buf, 0, len));
>>             }
>>             catch (Exception e)
>>             {
>>                 e.printStackTrace();
>>             }
>>             finally
>>             {
>>                 try
>>                 {
>>                     socket.close();
>>                 }
>>                 catch (Exception e)
>>                 {}
>>             }
>> 
>>         }).start();
>> 
>>     }
>> 
>> }
>> 
>> 
>> class TrustAllManager implements X509TrustManager
>> {
>>     private X509Certificate[] issuers;
>> 
>>     public TrustAllManager()
>>     {
>>         this.issuers = new X509Certificate[0];
>>     }
>> 
>>     public X509Certificate[] getAcceptedIssuers()
>>     {
>>         return issuers ;
>>     }
>> 
>>     public void checkClientTrusted(X509Certificate[] chain, String authType)
>>     {}
>> 
>>     public void checkServerTrusted(X509Certificate[] chain, String authType)
>>     {}
>> }
>
> Dongbo He has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
> 
>  - Merge branch 'master' into 8173339
>  - Backport 540ec375c30e973ceb1a944d5cc60cc8532e88ec

I should do it, thanks for the sponsor.

-------------

PR: https://git.openjdk.org/jdk8u-dev/pull/66


More information about the jdk8u-dev mailing list