Skip to content

Reject untrusted Lua bytecode while preserving script caching - #2138

Draft
Tiago Nápoli (tiagonapoli) wants to merge 9 commits into
microsoft:mainfrom
tiagonapoli:tiagonapoli/fix-lua-bytecode
Draft

Tiago Nápoli (tiagonapoli) wants to merge 9 commits into
microsoft:mainfrom
tiagonapoli:tiagonapoli/fix-lua-bytecode

Conversation

@tiagonapoli

Copy link
Copy Markdown
Collaborator

Summary

  • reject customer-supplied Lua binary chunks for EVAL and SCRIPT LOAD
  • compile customer input using Lua text-only mode before generating cacheable bytecode
  • preserve Garnet's application bytecode cache and binary-only session loading performance
  • tag script data as source text or Garnet-generated bytecode so only internally generated chunks reach the binary loader
  • remove the fallback that returned original customer bytes when compilation failed
  • use exact-length text loading for internal loadstring compatibility handling

Security boundary

Customer input is always treated as source text and compiled with mode t. Only successful internal compilation produces a GarnetGeneratedBinary chunk, which is cached and subsequently loaded with mode b. The public LuaScriptHandle constructor creates source-text handles, so arbitrary host-provided bytes cannot opt into binary loading.

Testing

  • full Lua scripting suite on .NET 8: 638 passed, 30 skipped, 0 failed
  • full Lua scripting suite on .NET 10: 638 passed, 30 skipped, 0 failed
  • full Debug solution build for net8.0 and net10.0: 0 warnings, 0 errors
  • regression coverage for binary-safe EVAL, SCRIPT LOAD, cache exclusion, blocked side effects, compilation failure output, embedded NUL input, host-inserted source, and cross-session caching

Supersedes #2111 while retaining bytecode caching.

Tiago Napoli added 9 commits September 15, 2026 14:34
Keep application bytecode caching while requiring customer input to compile in text-only mode and tagging internally generated chunks for binary-only loading.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Generate the test bytecode directly through Garnet's internal compiler instead of round-tripping through a Lua script.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Keep regression coverage focused on supported network-facing scripting workflows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Remove the unrelated ScriptHashKey allocation refactor from the Lua bytecode fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ec2a6abf-4bb4-48e1-a752-32672cb07303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant