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 994506C3D65; Thu, 1 Feb 2024 13:48:54 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 994506C3D65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1706784534; bh=L271AgrkH8l14CmLgRZmtnWdgcAfsK9BLYSm2RFPrY8=; 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=RiNlQSc2Dqmp8zs8MRv5iSb5Zk/wfMBKPDgzphRTCO0p6WhBljF8Ly48CWTGg9LXy ci1VkED4cI29cC0mUBTzH/UPVQK86WRkEPVMuexw/X+N7Ll0vIJyX3p9bSkBtfJXER ONNhcG1lNZDgcuiAX/uk1XrZw00uPwVv2TmC/gN8= Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [95.163.41.87]) (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 618FB6C3D65 for ; Thu, 1 Feb 2024 13:48:53 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 618FB6C3D65 Received: by smtp51.i.mail.ru with esmtpa (envelope-from ) id 1rVUcl-000000095bZ-0DuF; Thu, 01 Feb 2024 13:48:51 +0300 Message-ID: Date: Thu, 1 Feb 2024 13:48:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20240131121859.18071-1-skaplun@tarantool.org> Content-Language: en-US In-Reply-To: <20240131121859.18071-1-skaplun@tarantool.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9A3FCF9DB4FFE09550F3821568BA28ED6F8DF3A4580FB22E5182A05F53808504009902D59665DB63A5D1BE6A8D71B10A5520393E02F73740A588A6B1876A3CC46A02D50AE20F21E99 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7C27E92EFAD44F80DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637AC18FED211962C318638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B31A5097D28B59EF60996F8F2C69F61B03FD38E08B67A485CC7F00164DA146DAFE8445B8C89999728AA50765F7900637BA939FD1B3BAB99B389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8989FD0BDF65E50FBF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C13BDA61BF53F5E1DC0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3BDAC7C1A22EEE9F4BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C33EA60AFABC492F3035872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5BBEECE535E1E81BD5002B1117B3ED69665D686E34588CA4CED71F038FC046993823CB91A9FED034534781492E4B8EEAD1E02C13459908652BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFA4A71D876D91B97FE03C14338A6BD6F4513BBA14A7D051608E90DEE0553679E4A5CD7B9A90500322BAF4CF3B87E910B1528EFC688F179339F0941A149C450C473CA7F8E989BFD8F75F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojqJaWtPsRtykKPnsc/eB6Cg== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458D861D9E19F9FA10FCFE9FA76EDA5B4B7DCF86A2BFAF5E0CFD456BAC543C219BE645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Fix unsinking of IR_FSTORE for NULL metatable. 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 Bronnikov via Tarantool-patches Reply-To: Sergey Bronnikov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi, Sergey thanks for the patch! LGTM On 1/31/24 15:18, Sergey Kaplun wrote: > From: Mike Pall > > Reported by pwnhacker0x18. > > (cherry picked from commit 85b4fed0b0353dd78c8c875c2f562d522a2b310f) > > The `FSTORE` restoring of a sunk table from a snapshot for > `IRFL_TAB_META` misses the case when the second argument of > `setmetatable()` is `nil` (so, the `FSTORE` second operand is `NULL`). > This may lead to the corresponding assertion failure in the > `snap_replay_const()` or the crash. > > This patch handles the aforementioned case. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9595 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/lj-1147-fstore-null-meta > Tarantool PR: https://github.com/tarantool/tarantool/pull/9635 > Related issues: > * https://github.com/tarantool/tarantool/issues/9595 > * https://github.com/LuaJIT/LuaJIT/issues/1147 > > src/lj_snap.c | 11 +++-- > .../lj-1147-fstore-null-meta.test.lua | 41 +++++++++++++++++++ > 2 files changed, 49 insertions(+), 3 deletions(-) > create mode 100644 test/tarantool-tests/lj-1147-fstore-null-meta.test.lua > > diff --git a/src/lj_snap.c b/src/lj_snap.c > index 73e18e69..26352080 100644 > --- a/src/lj_snap.c > +++ b/src/lj_snap.c > @@ -414,6 +414,7 @@ static TRef snap_replay_const(jit_State *J, IRIns *ir) > case IR_KNUM: case IR_KINT64: > return lj_ir_k64(J, (IROp)ir->o, ir_k64(ir)->u64); > case IR_KPTR: return lj_ir_kptr(J, ir_kptr(ir)); /* Continuation. */ > + case IR_KNULL: return lj_ir_knull(J, irt_type(ir->t)); > default: lj_assertJ(0, "bad IR constant op %d", ir->o); return TREF_NIL; > } > } > @@ -857,9 +858,13 @@ static void snap_unsink(jit_State *J, GCtrace *T, ExitState *ex, > if (irk->o == IR_FREF) { > switch (irk->op2) { > case IRFL_TAB_META: > - snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp); > - /* NOBARRIER: The table is new (marked white). */ > - setgcref(t->metatable, obj2gco(tabV(&tmp))); > + if (T->ir[irs->op2].o == IR_KNULL) { > + setgcrefnull(t->metatable); > + } else { > + snap_restoreval(J, T, ex, snapno, rfilt, irs->op2, &tmp); > + /* NOBARRIER: The table is new (marked white). */ > + setgcref(t->metatable, obj2gco(tabV(&tmp))); > + } > break; > case IRFL_TAB_NOMM: > /* Negative metamethod cache invalidated by lj_tab_set() below. */ > diff --git a/test/tarantool-tests/lj-1147-fstore-null-meta.test.lua b/test/tarantool-tests/lj-1147-fstore-null-meta.test.lua > new file mode 100644 > index 00000000..bdf60a26 > --- /dev/null > +++ b/test/tarantool-tests/lj-1147-fstore-null-meta.test.lua > @@ -0,0 +1,41 @@ > +local tap = require('tap') > + > +-- Test file to demonstrate LuaJIT's incorrect restoration of a > +-- table from a snapshot when the `setmetatable()` gets `nil` as > +-- the second argument. > +-- See also: https://github.com/LuaJIT/LuaJIT/issues/1147. > + > +local test = tap.test('lj-1147-fstore-null-meta'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(2) > + > +jit.opt.start('hotloop=1') > + > +local counter = 0 > +local tab > +-- XXX: The loop is limited to 3 iterations to compile a trace and > +-- start to execute it. Use the loop format to see > +-- the side effects on the restoration from the snapshot. > +local LOOP_LIMIT = 2 > +while true do > + counter = counter + 1 > + -- Use counter for the content check. > + tab = {counter} > + -- This emits the following IRs necessary for the assertion > + -- failure: > + -- | 0003 }+ tab TNEW #3 #0 > + -- | ... > + -- | 0015 p64 FREF 0003 tab.meta > + -- | 0016 } tab FSTORE 0015 NULL > + setmetatable(tab, nil) > + -- Emit exit here to be sure that the table will be restored > + -- from the snapshot. > + if counter > LOOP_LIMIT then break end > +end > + > +test:is(tab[1], LOOP_LIMIT + 1, 'correct table content') > +test:ok(debug.getmetatable(tab) == nil, 'no metatable on the restored table') > + > +test:done(true)