From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 62C631724545; Wed, 11 Feb 2026 13:24:26 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 62C631724545 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1770805466; bh=R4+lMgREIMZWespg4D+R5ivmUm065O34f90xlVq3tjY=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Dik+FCdYHnr1AbD7etYovrfcjKVVPzxQ6bH/EGREYwUJzRy8979HsG+ga7RQB+MRy R1bjtDrKoT/fMiT9MZcK1iVI9yqyeT3ww5ljwxBJnyUYVDPMCnBRloK/P9fwRkg0FR jPSjCsRRXZ2vYFGI+XjZ1zlFd02GFKTY4P8MAfBE= Received: from send277.i.mail.ru (send277.i.mail.ru [95.163.59.116]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id EB647722122 for ; Wed, 11 Feb 2026 13:24:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org EB647722122 Received: by exim-smtp-5d446c7b8f-qxlvt with esmtpa (envelope-from ) id 1vq7OR-000000001Mt-3hqJ; Wed, 11 Feb 2026 13:24:24 +0300 Date: Wed, 11 Feb 2026 13:24:26 +0300 To: Sergey Bronnikov Cc: tarantool-patches@dev.tarantool.org Message-ID: References: <4a852879bdecd2cedbe1bcb4ebecc89531fc9fe4.1765350224.git.sergeyb@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a852879bdecd2cedbe1bcb4ebecc89531fc9fe4.1765350224.git.sergeyb@tarantool.org> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9A6EFB945BF0DEAB2F96CBC83A3B9494A238C435315A85C5F182A05F53808504019EF15CF566A8BAA3DE06ABAFEAF6705DF4DD85551BE4DC729347951FD9F45CA2D7423A3730B98E4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7FE853634EDEBEC2EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC83A81C8FD4AD23D82A6BABE6F325AC2E85FA5F3EDFCBAA7353EFBB553375664C71A6A4846DE52126F971E4F33A56CFDB9989F5175EC9B45D092EA9FCA7A753389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C07E7E81EEA8A9722B8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B636DA1BED736F9328CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249EDF998CB16CCEE6976E601842F6C81A12EF20D2F80756B5FB606B96278B59C4276E601842F6C81A127C277FBC8AE2E8B7FE970921847EE7F3AA81AA40904B5D99C9F4D5AE37F343AD1F44FA8B9022EA23BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E7356436AE5DD6441DC7C4224003CC83647689D4C264860C145E X-C1DE0DAB: 0D63561A33F958A5433ECB52EE1F1E275002B1117B3ED696AC7FC12C1E32249A72305013E4AE841E823CB91A9FED034534781492E4B8EEAD220496FFA5CD4785BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0AD73CAD6646DEDE191716CD42B3DD1D34CAB70F9BE574AE9C625B6776AC983F447FC0B9F89525902EE6F57B2FD27647F25E66C117BDB76D659B53B3E9F4634AF9FF5828F6196DD4906BEF2399C6977AC67BC41ED995F6054F972444F768F0094FEB8341EE9D5BE9A0A79F572B46E5845B9648C356FD42E9682BFC6C69A6144D53D8CD93680B12512CF4C41F94D744909CECFA6C6B0C050A61A8CAF69B82BA93681CD72808BE417F3B9E0E7457915DAA85F X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu53w8ahmwBjZKM/YPHZyZHvz5uv+WouB9+ObcCpyrx6l7KImUglyhkEat/+ysWwi0gdhEs0JGjl6ggRWTy1haxBpVdbIX1nthFXMZebaIdHP2ghjoIc/363UZI6Kf1ptIMVemV+tRo3/+hMmanLpZ2D50= X-Mailru-Sender: 520A125C2F17F0B1A9638AD358559B59B6D65422B80C05223DE06ABAFEAF6705DF4DD85551BE4DC7B7CBEF92542CD7C88B0A2698F12F5C9EC77752E0C033A69E86920BD37369036789A8C6A0E60D2BB63A5DB60FBEB33A8A0DA7A0AF5A3A8387 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit 3/3][v2] Add stack check to pcall/xpcall. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey! Thanks for the patch! Please consider my comments below. On 10.12.25, Sergey Bronnikov wrote: > From: Mike Pall > > Analyzed by Peter Cawley. > > (cherry picked from commit a4c1640432a9d8a60624cdc8065b15078c228e36) > > In the previous commit ("LJ_FR2: Fix stack checks in vararg calls.") > stack overflow for vararg functions and metamethod invocations > was fixed partially and there are still cases where stack overflow > happens, see comments in the test. The patch fixes the issue by Please describe the issue regardless previous commit. Just mentioned missing stack checks for `pcall()`, `xpcall()` is enough. > adding the stack check to fast functions `pcall()` and `xpcall()`. > > Sergey Bronnikov: > * added the description and the test for the problem > > Part of tarantool/tarantool#12134 > --- > src/vm_arm.dasc | 7 +++++ > src/vm_arm64.dasc | 8 +++++ > src/vm_mips.dasc | 10 +++++- > src/vm_mips64.dasc | 14 +++++++-- > src/vm_ppc.dasc | 9 ++++++ > src/vm_x64.dasc | 6 ++++ > src/vm_x86.dasc | 6 ++++ > ...048-fix-stack-checks-vararg-calls.test.lua | 31 ++++++++++++++++++- > 8 files changed, 86 insertions(+), 5 deletions(-) > > diff --git a/src/vm_arm.dasc b/src/vm_arm.dasc > index 7095e660..efe9dcb2 100644 > --- a/src/vm_arm.dasc > +++ b/src/vm_arm.dasc > diff --git a/src/vm_arm64.dasc b/src/vm_arm64.dasc > index cf8e575a..53ff7162 100644 > --- a/src/vm_arm64.dasc > +++ b/src/vm_arm64.dasc > diff --git a/src/vm_mips.dasc b/src/vm_mips.dasc > index 32caabf7..69d09d52 100644 > --- a/src/vm_mips.dasc > +++ b/src/vm_mips.dasc > diff --git a/src/vm_mips64.dasc b/src/vm_mips64.dasc > index 6c2975b4..4e60ee07 100644 > --- a/src/vm_mips64.dasc > +++ b/src/vm_mips64.dasc > @@ -1418,8 +1418,12 @@ static void build_subroutines(BuildCtx *ctx) > |//-- Base library: catch errors ---------------------------------------- > | > |.ffunc pcall > + | ld TMP1, L->maxstack > + | daddu TMP2, BASE, NARGS8:RC > + | sltu AT, TMP1, TMP2 > + | bnez AT, ->fff_fallback > + |. lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) > | daddiu NARGS8:RC, NARGS8:RC, -8 > - | lbu TMP3, DISPATCH_GL(hookmask)(DISPATCH) > | bltz NARGS8:RC, ->fff_fallback > |. move TMP2, BASE > | daddiu BASE, BASE, 16 > @@ -1440,8 +1444,12 @@ static void build_subroutines(BuildCtx *ctx) > |. nop > | > |.ffunc xpcall > - | daddiu NARGS8:TMP0, NARGS8:RC, -16 This change is incorrect. It wipes out the first patch in the series. > - | ld CARG1, 0(BASE) > + | ld TMP1, L->maxstack > + | daddu TMP2, BASE, NARGS8:RC > + | sltu AT, TMP1, TMP2 > + | bnez AT, ->fff_fallback > + |. ld CARG1, 0(BASE) > + | daddiu NARGS8:RC, NARGS8:RC, -16 > | ld CARG2, 8(BASE) > | bltz NARGS8:TMP0, ->fff_fallback > |. lbu TMP1, DISPATCH_GL(hookmask)(DISPATCH) > diff --git a/src/vm_ppc.dasc b/src/vm_ppc.dasc > index 980ad897..f2ea933b 100644 > --- a/src/vm_ppc.dasc > +++ b/src/vm_ppc.dasc > diff --git a/src/vm_x64.dasc b/src/vm_x64.dasc > index d5296759..141f5f82 100644 > --- a/src/vm_x64.dasc > +++ b/src/vm_x64.dasc > diff --git a/src/vm_x86.dasc b/src/vm_x86.dasc > index b043b830..1ba5abce 100644 > --- a/src/vm_x86.dasc > +++ b/src/vm_x86.dasc > diff --git a/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > index d471d41e..b135042b 100644 > --- a/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > +++ b/test/tarantool-tests/lj-1048-fix-stack-checks-vararg-calls.test.lua > @@ -1,4 +1,5 @@ > local tap = require('tap') > +local ffi = require('ffi') > > -- A test file to demonstrate a stack overflow in `pcall()` in > -- some cases, see below testcase descriptions. > @@ -7,7 +8,7 @@ local test = tap.test('lj-1048-fix-stack-checks-vararg-calls'):skipcond({ > ['Test requires JIT enabled'] = not jit.status(), > }) > > -test:plan(2) > +test:plan(4) This patch covers only `pcall()` cases, please add the same tests for `xpcall()` (I suppose the most simple is `xpcall()` as `__call` metamethod). > > -- The testcase demonstrate a segmentation fault due to stack > -- overflow by recursive calling `pcall()`. The functions are > @@ -50,4 +51,32 @@ pcall(coroutine.wrap(looper), prober_2, 0) > > test:ok(true, 'no stack overflow with metamethod') > > +-- The testcase demonstrate a stack overflow in Typo: s/demonstrate/demonstrates/ > +-- `pcall()`/xpcall()` triggered using metamethod `__call`. > + > +t = setmetatable({}, { __call = pcall })() It's better to do this at the separate Lua stack, i.e. inside `coroutine.wrap()`. > + > +test:ok(true, 'no stack overflow with metamethod __call') > + > +-- The testcase demonstrate a stack overflow in Typo: s/demonstrate/demonstrates/ > +-- `pcall()`/`xpcall()` similar to the first testcase, but it is > +-- triggered using `unpack()`. > + > +t = {} > +local function f() > + return pcall(unpack(t)) > +end > + Please explain the amount of necessary iterations of calls. > +local N_ITERATIONS = 100 > +if ffi.abi('gc64') then > + N_ITERATIONS = 180 > +end > + > +for i = 1, N_ITERATIONS do > + t[i], t[i + 1], t[i + 2] = pcall, pairs, {} Let's use `type` here instead of pairs. > + coroutine.wrap(f)() > +end > + > +test:ok(true, 'no stack overflow with unpacked pcalls') > + > test:done(true) > -- > 2.43.0 > -- Best regards, Sergey Kaplun