11 Replies Latest reply on Jul 3, 2014 3:37 PM by niksajur

    binfmt_misc kernel issue or something else?

    niksajur

      OS: Oracle Linux 6.5 x86_64
      Issue: Oracle jdk1.7.0 x86_64 jexec startup script fails to provide direct execution of standalone jar files

       

      I have been in doubt whether to post this topic on one of numerous OTN Java forums or here. Taking into consideration however that the issue is related to binfmt_misc (a capability of linux kernel to recognize file format of an executable, allowing it to be executed directly), I decided to put it on this forum.

       

      Oracle jdk1.7.0 comes with jexec init script that fails to provide direct execution of standalone jar files, although it creates virtual jexec in mounted binfmt_misc. According to official Oracle JDK documentation page, "a new service script, named jexec, is added to /etc/init.d. This script allows users to directly execute any standalone JAR file that has an execution permission set. This can be demonstrated using an example from the JDK:

       

              cd /usr/java/jdk1.6.0/demo/jfc/SwingSet2
         chmod +x SwingSet2.jar
         /SwingSet2.jar
      "
      Following this example and trying to execute SwingSet2.jar directly, I am getting the severe error message:

       

      [root@proton ~]# cd /usr/java/jdk1.7.0_60/demo/jfc/SwingSet2
      [root@proton SwingSet2]# chmod +x SwingSet2.jar
      [root@proton SwingSet2]# ./SwingSet2.jar
      invalid file (bad magic number): Exec format error

       

      The same happens using jexec binary:

      [root@proton SwingSet2]# /usr/java/jdk1.7.0_60/lib/jexec SwingSet2.jar
      invalid file (bad magic number): Exec format error

       

      This happens regardless of which kernel currently is running - 2.6.32 or 3.8.13. The normal execution 'java -jar SwingSet2.jar' however works correctly as expected. Note that binfmt_misc is mounted and contains 3 virtual files:

       

      [root@proton ~]# cat /proc/sys/fs/binfmt_misc/jexec
      enabled
      interpreter /usr/java/default/lib/jexec
      flags:
      offset 0
      magic 504b0304

       

      [root@proton ~]# cat /proc/sys/fs/binfmt_misc/status
      enabled

       

      The third virtual file /proc/sys/fs/binfmt_misc/register is empty.

       

      I don't know whether the issue existed in OL5.x x86_64 or not, as I didn't use Oracle JDK in OL5.x, but a friend of mine, who has 32-bit Oracle JDK installed on 32-bit OL5.10, tells me that direct execution of jar files always succeeds.

       

      Is this known issue/bug in OL6.5 kernels, or something is wrong or missing in my OL6.5 installation?

        • 1. Re: binfmt_misc kernel issue or something else?
          Dude!

          I think the error messages is a generic shell error indicating that the file you are trying to execute does not match the expected system architecture or cannot be interpreted. Such errors can occur when trying to execute 64-bit software on a 32-bit OS, or when executing 32-bit software without 32-bit libraries with a x64 CPU. Magic "504b0304" is a PKZip file.

           

          I'm not a Java expert, but I remember reading that java code should be machine independent and therefore it does not matter if a jar file is compiled with 32-bit or 64-bit JDK. Perhaps you installed the wrong version of JDK for your platform or the jar file contains native code. What is the output of the following:

           

          uname -m

          java --version

           

          If you are trying to use a specific Java runtime that is not your current system default you will also have to export the appropriate Java shell environment, such as JAVA_HOME and CLASSPATH depending on what you are trying to use.

          • 2. Re: binfmt_misc kernel issue or something else?
            niksajur

            [root@proton ~]# uname -a
            Linux proton.example.com 3.8.13-35.1.1.el6uek.x86_64 #2 SMP Fri Jun 6 10:52:33 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux

             

            [root@proton ~]# java -version
            java version "1.7.0_60"
            Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
            Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

            • 3. Re: binfmt_misc kernel issue or something else?
              Dude!

              Does the following work:

               

              cd /usr/java/jdk1.7.0_60/demo/jfc/SwingSet2

              java -jar SwingSet2.jar

              • 4. Re: binfmt_misc kernel issue or something else?
                niksajur

                It works perfectly. Seems you are not reading my posts carefully. It has been already pointed in the first post: "The normal execution 'java -jar SwingSet2.jar' however works correctly as expected".

                 

                Now I am going to download and install 32 bit jdk1.7.0 to see if the problem exists there. Just curious. I will report tomorrow.

                • 5. Re: binfmt_misc kernel issue or something else?
                  niksajur

                  Tried 32-bit jdk1.7.0 and 64-bit jdk1.8.0. The same problem with both and the same error.

                   

                  It may be interesting to compare my results with my freind's results. We both have the same hardware platform (64-bit architecture). I am runnung 64-bit OL6.5, he is running 32-bit OL5.10.

                   

                  ON MY SYSTEM:

                  32-bit jdk1.7.0_60 with 32-bit demos doesn't work

                  64-bit jdk1.7.0_60 with 64-bit demos doesn't work

                  64-bit jdk1.8.0_05 with 64-bit demos doesn't work

                   

                  ON HIS SYSTEM:

                  32-bit jdk1.7.0_60 with 32-bit demos always works

                  32-bit jdk1.8.0_05 with 32-bit demos always works

                   

                  Here is a link that may be of interest:

                  http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6401361

                  • 6. Re: binfmt_misc kernel issue or something else?
                    Dude!

                    Rather looks like a problem for the Java community to sort out.

                    • 7. Re: binfmt_misc kernel issue or something else?
                      niksajur

                      Hmm... it may be, but it is not likely to be and cannot be taken for sure. For me it rather looks like 64-bit OS issue as it follows from the comparison in my previous post:

                       

                      1. it cannot be hardware arch issue as we both have 64-bit architecture
                      2. the issue doesn't exist in 32-bit OS environment running 32-bit jdk

                       

                      Well, everything suggests that it rather looks like 64-bit OS issue. In fact, I am not talking about java at all. I am talking about jexec binary (run directly by CPU)

                       

                      [root@proton ~]# file /usr/java/jdk1.7.0_60/lib/jexec
                      /usr/java/jdk1.7.0_60/lib/jexec: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

                       

                      [root@proton ~]# ldd /usr/java/jdk1.7.0_60/lib/jexec
                              linux-vdso.so.1 =>  (0x00007ffff7ffd000)
                              libc.so.6 => /lib64/libc.so.6 (0x00007ffff7c21000)
                              /lib64/ld-linux-x86-64.so.2 (0x0000555555554000)

                       

                      that is closely related and depends on binfmt_misc kernel capability. The report whose link I provided is eight years old (dated 2006-03-21) and shows that the issue once existed even in 32-bit OS environment (that time as the jexec issue), but that was fixed in jdk1.6 (b95).

                       

                      BTW, I am "deeply impressed" with the way they responded to the bug report: "In the sense that jexec is not documented for independent execution, there is no defect here. We never asserted that jexec could be executed directly. As a matter of fact, we never publically said anything about jexec. However, this is curious as to why it fails". Very practical way to avoid any liability. I can only imagine the face of my client, whom I shipped a non-working application that failed to start, hearing my response: "If you carefully read the User Manual, you will notice that nowhere is explicitly said that application works. However, it could be a matter of curiosity to find out why it fails". Very, very practical. Even ingeniously. 

                      • 8. Re: binfmt_misc kernel issue or something else?
                        Dude!

                        From what I understand reading the link to the bug database you outlined and other sources on the Web, the error message is misleading and pointing to a problem in the jar file and not the OS or jexec. The accompanied readme of the SwingSet2 package shows to use java -jar to run the software.

                        • 9. Re: binfmt_misc kernel issue or something else?
                          niksajur

                          Dude! wrote:

                          The accompanied readme of the SwingSet2 package shows to use java -jar to run the software.

                          It doesn't matter. The fact is that the same SwingSet2 jar file from 32-bit demos can be executed directly on 32-bit OS, but not on 64-bit OS. I presented the example with SwingSet2.jar as it was described on Oracle documentation site, but the same happens with any other jar file.

                           

                          See the end of this page

                          http://www.oracle.com/technetwork/java/javase/install-linux-rpm-137089.html

                          • 10. Re: binfmt_misc kernel issue or something else?
                            Dude!

                            The fact that something works under x86 Linux and not x64 Linux does not necessarily point to a failure of the OS or kernel. The bug documentation outlines that the cause is unknown and the error message could be misleading.

                             

                            Since you receive the same error using /usr/java/jdk1.7.0_60/lib/jexec SwingSet2.jar as well as executing SwingSet2.jar directly this seems to indicate that the binfmt_misc kernel feature, which simply uses jexec is not the culprit. Btw, the process of associating a file's magic number with jexec using the binfmt_misc kernel feature is only installed when installing the java rpm package.

                             

                            It might be an issue with the jexec launcher or the jar file itself. I'm not trying to argue with you, but you asked if this problem is a issue of the binfmt_misc kernel feature and from what I understand it is not. Since no one else has answered I suggest to ask the question in the Java forum.

                            • 11. Re: binfmt_misc kernel issue or something else?
                              niksajur

                              > The fact that something works under x86 Linux and not x64 Linux
                              > does not necessarily point to a failure of the OS or kernel.

                               

                              I have never said the issue necessarily points to the 64-bit OS failure or its kernel failure. It points to, but not necessarily. It still can be 64-bit jexec binary issue, although the issue itself has been known for eight years (and fixed in jdk1.6 (b95) for 32-bit jexec).

                               

                              All in all, this feature is not a big deal and I can live fine without jexec binary and jexec init script. It was just the last known issue on my OL6.5 system that I wanted to sort out. But not necessarily.