Bug 1311638 - Issues when root tries to attach to non-root JVMs
Summary: Issues when root tries to attach to non-root JVMs
Keywords:
Status: CLOSED EOL
Alias: None
Product: Fedora
Classification: Fedora
Component: java-1.8.0-openjdk
Version: 27
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Elliott Baron
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-02-24 16:23 UTC by Marko Myllynen
Modified: 2018-11-30 20:49 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-11-30 20:49:25 UTC
Type: Bug
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
openjdk bug system JDK-8036559 0 None None None Never
openjdk bug system JDK-8177154 0 None None None 2018-04-05 15:15:56 UTC

Description Marko Myllynen 2016-02-24 16:23:42 UTC
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 16:24:22 UTC
Created attachment 1130253 [details]
AttachTarget.java

Comment 2 Marko Myllynen 2016-02-24 16:24:56 UTC
Created attachment 1130254 [details]
AttachClient.java

Comment 3 Deepak Bhole 2016-02-24 21:17:10 UTC
Assigning to Elliott, who may have come across something similar when working on Thermostat.

Comment 4 Marko Myllynen 2016-02-25 18:30:25 UTC
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 12:17:03 UTC
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 12:34:05 UTC
(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 20:12:56 UTC
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 15:44:54 UTC
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.

Comment 9 Fedora End Of Life 2017-11-16 19:22:08 UTC
This message is a reminder that Fedora 25 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 25. 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 '25'.

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 25 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.

Comment 10 Marko Myllynen 2018-03-20 12:52:34 UTC
FWIW, since the Attach API is nowadays available as an integral part of JVM starting with Java 9 (no need for the separate jars or the -devel package), this may in theory become a more relevant issue.

Comment 11 Severin Gehwolf 2018-04-05 15:15:56 UTC
Yet again, there is JDK-8177154 to consider.

Comment 12 Ben Cotton 2018-11-27 16:19:28 UTC
This message is a reminder that Fedora 27 is nearing its end of life.
On 2018-Nov-30  Fedora will stop maintaining and issuing updates for
Fedora 27. 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 '27'.

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 27 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.

Comment 13 Ben Cotton 2018-11-30 20:49:25 UTC
Fedora 27 changed to end-of-life (EOL) status on 2018-11-30. Fedora 27 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.


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