JDK-8219896 : Enhance Attach API to support arbitrary length arguments
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: tools
  • Affected Version: 13
  • Priority: P3
  • Status: Resolved
  • Resolution: Delivered
  • Submitted: 2019-02-28
  • Updated: 2025-04-11
  • Resolved: 2025-04-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25Resolved
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Sub Tasks
JDK-8339289 :  
JDK-8342995 :  
JDK-8342996 :  
Description
In the VM the attach logic sets limits on the number and types of arguments that can be received:

class AttachOperation: public CHeapObj<mtInternal> {
 public:
  enum {
    name_length_max = 16,       // maximum length of  name
    arg_length_max = 1024,      // maximum length of argument
    arg_count_max = 4           // maximum number of arguments
  };

but the client tools that send these requests may include arbitrary length arguments, such as filenames, that might exceed these limits.
Comments
attach API v2 is now supported on all platforms
11-04-2025

Current implementation: AttachOperation has fixed-size buffers for required data: char _name[name_length_max+1]; char _arg[arg_count_max][arg_length_max+1]; Windows: Attach operations are enqueued by allocating memory for operation parameters (name, arg1, arg2, arg3) in the target process, copying their values and call CreateRemoteThread to put the operation into queue; Operation results are transferred by using named pipe (created by client, name of the pipe is passed with other operation parameters); Other platforms (linux, bsd, aix): Use unix sockets with predefined path; Clients connect to the socket, send attach operation parameters and read the operation results. Operation request has the following format: "<ver>0<cmd>0<arg1>0<arg2>0<arg3>0" (<ver> is "1") Proposed solution: Make attach operation parameters arbitrary size (heap allocated), remove restrictions on argument count, unify implementations on different platforms. - On Windows there are restriction on the code executed by CreateRemoteThread, it should be kept small and simple. "enqueue" routine will pass only pipe name(fixed length at it is now), the rest of IPC (sending operation parameters and retrieving operation results) is performed via bi-directional pipe. - Bump Attach API version to 2. new request format: "<ver>0<size>0<cmd>0<arg>0...<arg>0" (<ver> is "2") <size> is number of bytes followed (contains command name and any number of arguments) For safety <size> is restricted by 256K Compatibility: To allow clients from previous releases attach to newer VMs, operation requests v1 are supported (shared code provides methods to read both v1 and v2 requests); To detect if target VM supports v2, new "getVersion" command (v1) is used. Old VMs report "command not supported" if they does not support v2. For testing purposes it makes sense to introduce internal property ("jdk.attach.compat" ?) to disables v2 request handling. Security: security mechanisms remain the same (Windows security model for OpenProcess/CreateRemoteThread on Windows, checking permissions to file on unix socket based platforms)
17-07-2024