This service will be undergoing maintenance at 00:00 UTC, 2017-10-23 It is expected to last about 30 minutes
Bug 1311638 - Issues when root tries to attach to non-root JVMs
Issues when root tries to attach to non-root JVMs
Status: ASSIGNED
Product: Fedora
Classification: Fedora
Component: java-1.8.0-openjdk (Show other bugs)
25
Unspecified Unspecified
unspecified Severity unspecified
: ---
: ---
Assigned To: Elliott Baron
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-02-24 11:23 EST by Marko Myllynen
Modified: 2016-11-24 11:08 EST (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
AttachTarget.java (210 bytes, text/plain)
2016-02-24 11:24 EST, Marko Myllynen
no flags Details
AttachClient.java (1.68 KB, text/plain)
2016-02-24 11:24 EST, Marko Myllynen
no flags Details

  None (edit)
Description Marko Myllynen 2016-02-24 11:23:42 EST
Description of problem:
There's a well-known issue that on Linux/UNIX root is not allowed to attach to non-root JVMs, see https://bugs.openjdk.java.net/browse/JDK-8036559.

I'd like to point out an additional issue in this area:

1)  Run the attached AttachTarget as user1 on a terminal
2)  Run the attached AttachClient as user1 on a terminal
3)  Notice how this works

4)  sudo killall -9 java ; sudo rm -rf /tmp/hsperfdata* /tmp/.attach_pid* /tmp/.java_pid* ;

5)  Run the attached AttachTarget as user1 on a terminal
6)  Run the attached AttachClient as root  on a terminal
7)  Notice how this fails - unrequested thread dump on AttachTarget terminal and "com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded" printed after a pause on the root terminal

8)  sudo killall -9 java ; sudo rm -rf /tmp/hsperfdata* /tmp/.attach_pid* /tmp/.java_pid* ;

9)  Run the attached AttachTarget as user1 on a terminal
10) Run the attached AttachClient as user1 on a terminal
11) Notice how this works
12) Run the attached AttachClient as root  on a terminal
13) Notice how this fails differently than 6) above - no thread dump on AttachTarget terminal but "java.io.IOException: well-known file is not secure" is printed immediately on the root terminal

I think ideally the upstream issue should be fixed. But if that is not going to happen then at least we should avoid printing out the unrequested thread dump on attach target terminal and provide consistent errors for root when trying to connect non-root JVMs, the current situation is just messy.

Version-Release number of selected component (if applicable):
OpenJDK 1.7 / OpenJDK 1.8
Comment 1 Marko Myllynen 2016-02-24 11:24 EST
Created attachment 1130253 [details]
AttachTarget.java
Comment 2 Marko Myllynen 2016-02-24 11:24 EST
Created attachment 1130254 [details]
AttachClient.java
Comment 3 Deepak Bhole 2016-02-24 16:17:10 EST
Assigning to Elliott, who may have come across something similar when working on Thermostat.
Comment 4 Marko Myllynen 2016-02-25 13:30:25 EST
Additional inconvenience here for root is that

    VirtualMachine.list()

returns descriptors for all running JVMs, including non-root ones and

    VirtualMachine.attach(...)

hangs shortly and then fails on those non-root JVMs but attach() would be required to know (via getProperties()) whether a JVM is a root or non-root owned one so skipping non-root JVMs as root is a bit hard AFAICS.

(For non-root users VirtualMachine.list() returns only JVMs of the same user.)

Thanks,
Comment 5 Marko Myllynen 2016-03-08 07:17:03 EST
Looks like Attach API isn't reliable even for the user running the JVMs:

https://bugzilla.redhat.com/show_bug.cgi?id=1315256
Comment 6 Severin Gehwolf 2016-03-08 07:34:05 EST
(In reply to Marko Myllynen from comment #4)
> Additional inconvenience here for root is that
> 
>     VirtualMachine.list()
> 
> returns descriptors for all running JVMs, including non-root ones and
> 
>     VirtualMachine.attach(...)
> 
> hangs shortly and then fails on those non-root JVMs but attach() would be
> required to know (via getProperties()) whether a JVM is a root or non-root
> owned one so skipping non-root JVMs as root is a bit hard AFAICS.
> 
> (For non-root users VirtualMachine.list() returns only JVMs of the same
> user.)
> 
> Thanks,

FWIW:
The way we worked around this problem in Thermostat is that we drop to the JVM owning user before doing the attach. You can get the pid from VirtualMachineDescriptor.id(). Then look up the owning user via /proc/<pid>/status. Once you have the JMX connect URL you should be able to connect.
Comment 7 Elliott Baron 2016-03-22 16:12:56 EDT
I think it's best to fix this issue upstream, and allow root to attach to non-root JVMs. This will give users the expected behaviour and get rid of the confusing errors mentioned above. I have proposed a new patch upstream targeting OpenJDK 9:

http://mail.openjdk.java.net/pipermail/serviceability-dev/2016-March/019108.html
Comment 8 Fedora End Of Life 2016-11-24 10:44:54 EST
This message is a reminder that Fedora 23 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 23. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as EOL if it remains open with a Fedora  'version'
of '23'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 23 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Note You need to log in before you can comment on or make changes to this bug.