Skip to content

Disable loading of Lua bytecode#3

Merged
git-hulk merged 1 commit into
v2.1from
harden/disable-bytecode-load
May 17, 2026
Merged

Disable loading of Lua bytecode#3
git-hulk merged 1 commit into
v2.1from
harden/disable-bytecode-load

Conversation

@git-hulk
Copy link
Copy Markdown
Member

Loading untrusted Lua bytecode is unsafe — the LuaJIT FAQ explicitly states the bytecode loader does not validate input, and maliciously crafted bytecode can crash the VM or be used for sandbox escapes (type confusion, OOB reads, fake GCobj pointers).

Reject any chunk whose lexer setup detects bytecode (BCDUMP_HEAD1, i.e. 0x1B at the start of the stream). All chunk-loading APIs — lua_load, lua_loadx, luaL_loadbuffer(x), luaL_loadfile(x) — funnel through cpparser, so this single check covers loadstring, load, string.dump round-trips, and any host-side luaL_loadbuffer call.

Source loading is unaffected. This mirrors the approach Redis took for vanilla Lua in redis/redis@fdf9d455.

Loading untrusted Lua bytecode is unsafe — the LuaJIT FAQ explicitly
states the bytecode loader does not validate input, and maliciously
crafted bytecode can crash the VM or be used for sandbox escapes
(type confusion, OOB reads, fake GCobj pointers).

Reject any chunk whose lexer setup detects bytecode (BCDUMP_HEAD1,
i.e. 0x1B at the start of the stream). All chunk-loading APIs —
lua_load, lua_loadx, luaL_loadbuffer(x), luaL_loadfile(x) — funnel
through cpparser, so this single check covers loadstring, load,
string.dump round-trips, and any host-side luaL_loadbuffer call.

Source loading is unaffected. This mirrors the approach Redis took
for vanilla Lua in redis/redis@fdf9d455.
@git-hulk git-hulk requested review from PragmaTwice and jihuayu May 17, 2026 04:13
@git-hulk git-hulk merged commit 02dfcc3 into v2.1 May 17, 2026
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.

3 participants