Skip to content

Conversation

jasonmolenda
Copy link
Collaborator

The qSpeedTest packet is used for experiments to determine the optimal packet size for a given communication medium, e.g. to transfer 10MB of memory, is it faster to send a hundred 100KB packets or ten 1MB packets. It creates a packet of the requested size in a stack allocation, but is not checking that its buffer is large enough for the requested size.

Change this allocation to be on heap, and impose a maximum size that can be tested (4MB, for now).

rdar://158630250

Only allow qSpeedTest packet size requests up to 4MB.
Allocate the temporary buffer for the packet on the
heap, instead of stack.
rdar://158630250
@llvmbot
Copy link
Member

llvmbot commented Aug 29, 2025

@llvm/pr-subscribers-lldb

Author: Jason Molenda (jasonmolenda)

Changes

The qSpeedTest packet is used for experiments to determine the optimal packet size for a given communication medium, e.g. to transfer 10MB of memory, is it faster to send a hundred 100KB packets or ten 1MB packets. It creates a packet of the requested size in a stack allocation, but is not checking that its buffer is large enough for the requested size.

Change this allocation to be on heap, and impose a maximum size that can be tested (4MB, for now).

rdar://158630250


Full diff: https://github.com/llvm/llvm-project/pull/156099.diff

1 Files Affected:

  • (modified) lldb/tools/debugserver/source/RNBRemote.cpp (+6-6)
diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp
index 102b2ab3e8484..d9fb22c6a1c06 100644
--- a/lldb/tools/debugserver/source/RNBRemote.cpp
+++ b/lldb/tools/debugserver/source/RNBRemote.cpp
@@ -4423,12 +4423,12 @@ rnb_err_t RNBRemote::HandlePacket_qSpeedTest(const char *p) {
     return HandlePacket_ILLFORMED(
         __FILE__, __LINE__, p,
         "Didn't find response_size value at right offset");
-  else if (*end == ';') {
-    static char g_data[4 * 1024 * 1024 + 16];
-    strcpy(g_data, "data:");
-    memset(g_data + 5, 'a', response_size);
-    g_data[response_size + 5] = '\0';
-    return SendPacket(g_data);
+  else if (*end == ';' && response_size < (4 * 1024 * 1024)) {
+    std::vector<char> buf(response_size + 6, 'a');
+    memcpy(buf.data(), "data:", 5);
+    buf[buf.size() - 1] = '\0';
+    rnb_err_t return_value = SendPacket(buf.data());
+    return return_value;
   } else {
     return SendErrorPacket("E79");
   }

@jasonmolenda jasonmolenda merged commit ac8e7be into llvm:main Sep 3, 2025
11 checks passed
@jasonmolenda jasonmolenda deleted the create-max-qspeedtest-packet-size branch September 3, 2025 23:31
ckoparkar added a commit to ckoparkar/llvm-project that referenced this pull request Sep 4, 2025
* main: (1483 commits)
  [clang] fix error recovery for invalid nested name specifiers (llvm#156772)
  Revert "[lldb] Add count for errors of DWO files in statistics and combine DWO file count functions" (llvm#156777)
  AMDGPU: Add agpr variants of multi-data DS instructions (llvm#156420)
  [libc][NFC] disable localtime on aarch64/baremetal (llvm#156776)
  [win/asan] Improve SharedReAlloc with HEAP_REALLOC_IN_PLACE_ONLY. (llvm#132558)
  [LLDB] Make internal shell the default for running LLDB lit tests. (llvm#156729)
  [lldb][debugserver] Max response size for qSpeedTest (llvm#156099)
  [AMDGPU] Define 1024 VGPRs on gfx1250 (llvm#156765)
  [flang] Check for BIND(C) name conflicts with alternate entries (llvm#156563)
  [RISCV] Add exhausted_gprs_fprs test to calling-conv-half.ll. NFC (llvm#156586)
  [NFC] Remove trailing whitespaces from `clang/include/clang/Basic/AttrDocs.td`
  [lldb] Mark scripted frames as synthetic instead of artificial (llvm#153117)
  [docs] Refine some of the wording in the quality developer policy (llvm#156555)
  [MLIR] Apply clang-tidy fixes for readability-identifier-naming in TransformOps.cpp (NFC)
  [MLIR] Add LDBG() tracing to VectorTransferOpTransforms.cpp (NFC)
  [NFC] Apply clang-format to PPCInstrFutureMMA.td (llvm#156749)
  [libc] implement template functions for localtime (llvm#110363)
  [llvm-objcopy][COFF] Update .symidx values after stripping (llvm#153322)
  Add documentation on debugging LLVM.
  [lldb] Add count for errors of DWO files in statistics and combine DWO file count functions (llvm#155023)
  ...
jasonmolenda added a commit to jasonmolenda/llvm-project that referenced this pull request Sep 8, 2025
The qSpeedTest packet is used for experiments to determine the optimal
packet size for a given communication medium, e.g. to transfer 10MB of
memory, is it faster to send a hundred 100KB packets or ten 1MB packets.
It creates a packet of the requested size in a stack allocation, but is
not checking that its buffer is large enough for the requested size.

Change this allocation to be on heap, and impose a maximum size that can
be tested (4MB, for now).

rdar://158630250
(cherry picked from commit ac8e7be)
jasonmolenda added a commit to swiftlang/llvm-project that referenced this pull request Sep 8, 2025
…max-packet-size

[lldb][debugserver] Max response size for qSpeedTest (llvm#156099)
jasonmolenda added a commit to jasonmolenda/llvm-project that referenced this pull request Sep 8, 2025
The qSpeedTest packet is used for experiments to determine the optimal
packet size for a given communication medium, e.g. to transfer 10MB of
memory, is it faster to send a hundred 100KB packets or ten 1MB packets.
It creates a packet of the requested size in a stack allocation, but is
not checking that its buffer is large enough for the requested size.

Change this allocation to be on heap, and impose a maximum size that can
be tested (4MB, for now).

rdar://158630250
(cherry picked from commit ac8e7be)
jasonmolenda added a commit to swiftlang/llvm-project that referenced this pull request Sep 9, 2025
…packet-cap-20240723

[lldb][debugserver] Max response size for qSpeedTest (llvm#156099)
jasonmolenda added a commit to jasonmolenda/llvm-project that referenced this pull request Sep 9, 2025
The qSpeedTest packet is used for experiments to determine the optimal
packet size for a given communication medium, e.g. to transfer 10MB of
memory, is it faster to send a hundred 100KB packets or ten 1MB packets.
It creates a packet of the requested size in a stack allocation, but is
not checking that its buffer is large enough for the requested size.

Change this allocation to be on heap, and impose a maximum size that can
be tested (4MB, for now).

rdar://158630250
(cherry picked from commit ac8e7be)
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request Sep 11, 2025
…-speedtest-packet-6.2.1

[lldb][debugserver] Max response size for qSpeedTest (llvm#156099)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants