Andrew Geissler | bffdb3e | 2020-08-21 16:13:29 -0500 | [diff] [blame] | 1 | From 6298903e35217ab69c279056f925fb72900ce0b7 Mon Sep 17 00:00:00 2001 |
| 2 | From: Roberto Ierusalimschy <roberto@inf.puc-rio.br> |
| 3 | Date: Mon, 6 Jul 2020 12:11:54 -0300 |
| 4 | Subject: [PATCH] Keep minimum size when shrinking a stack |
| 5 | |
| 6 | When shrinking a stack (during GC), do not make it smaller than the |
| 7 | initial stack size. |
| 8 | --- |
| 9 | ldo.c | 5 ++--- |
| 10 | 1 file changed, 2 insertions(+), 3 deletions(-) |
| 11 | ==== end of original header ==== |
| 12 | |
| 13 | CVE: CVE-2020-15888 |
| 14 | |
| 15 | Upstream-Status: backport [https://github.com/lua/lua.git] |
| 16 | |
| 17 | Signed-off-by: Joe Slater <joe.slater@windriver.com> |
| 18 | |
| 19 | ==== |
| 20 | diff --git a/ldo.c b/ldo.c |
| 21 | index c563b1d9..a89ac010 100644 |
| 22 | --- a/src/ldo.c |
| 23 | +++ b/src/ldo.c |
| 24 | @@ -220,7 +220,7 @@ static int stackinuse (lua_State *L) { |
| 25 | |
| 26 | void luaD_shrinkstack (lua_State *L) { |
| 27 | int inuse = stackinuse(L); |
| 28 | - int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK; |
| 29 | + int goodsize = inuse + BASIC_STACK_SIZE; |
| 30 | if (goodsize > LUAI_MAXSTACK) |
| 31 | goodsize = LUAI_MAXSTACK; /* respect stack limit */ |
| 32 | if (L->stacksize > LUAI_MAXSTACK) /* had been handling stack overflow? */ |
| 33 | @@ -229,8 +229,7 @@ void luaD_shrinkstack (lua_State *L) { |
| 34 | luaE_shrinkCI(L); /* shrink list */ |
| 35 | /* if thread is currently not handling a stack overflow and its |
| 36 | good size is smaller than current size, shrink its stack */ |
| 37 | - if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && |
| 38 | - goodsize < L->stacksize) |
| 39 | + if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && goodsize < L->stacksize) |
| 40 | luaD_reallocstack(L, goodsize); |
| 41 | else /* don't change stack */ |
| 42 | condmovestack(L,{},{}); /* (change only for debugging) */ |
| 43 | -- |
| 44 | 2.17.1 |
| 45 | |