From f04d254b61e4f05fd647fbcbcb61de32fea1d652 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Mon, 29 Apr 2024 22:55:06 +0200 Subject: [PATCH] Add property to allow disabling user check for J9 which does not seem to be implemented. --- .../main/java/net/bytebuddy/agent/VirtualMachine.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java b/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java index ab5125c942..d502327e44 100644 --- a/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java +++ b/byte-buddy-agent/src/main/java/net/bytebuddy/agent/VirtualMachine.java @@ -1627,6 +1627,13 @@ protected Connection doConnect(File socket) { */ class ForOpenJ9 extends AbstractBase { + /** + * Property to indicate that the attachment does not validate that the attach file is owned by + * the current user. J9 requires this by its documentation but it does not appear to always be + * implemented. + */ + public static final String IGNORE_USER = "net.bytebuddy.attach.j9.ignoreuser"; + /** * The temporary folder for attachment files for OpenJ9 VMs. */ @@ -1688,10 +1695,11 @@ public static VirtualMachine attach(String processId, int timeout, Dispatcher di if (vmFolder == null) { throw new IllegalStateException("No descriptor files found in " + directory); } + boolean ignoreUser = Boolean.getBoolean(IGNORE_USER); long userId = dispatcher.userId(); virtualMachines = new ArrayList(); for (File aVmFolder : vmFolder) { - if (aVmFolder.isDirectory() && dispatcher.getOwnerIdOf(aVmFolder) == userId) { + if (aVmFolder.isDirectory() && (ignoreUser || dispatcher.getOwnerIdOf(aVmFolder) == userId)) { File attachInfo = new File(aVmFolder, "attachInfo"); if (attachInfo.isFile()) { Properties virtualMachine = new Properties();