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 A6415A1C391; Thu, 8 Feb 2024 16:58:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A6415A1C391 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1707400681; bh=UqRkvY2L2rI7dnj4a978U4xJjry1D8+OAjc8M7iSVn8=; 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=sjbkMPWnM0lGSw0yBmGSemt2sXVpVpHzE2Y44a5wpO8bRd/4KYq/RotZ3QP17ai6x m5gXexquZ1wWJvakY1h+FhdSkPAmib3kjfl/b4vbMg/1Iby46lzaFSgrFhsm28dyph erIGivgW3Up7vlp6evVALzUVH9rj6fsYhfgAox6E= Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [95.163.41.89]) (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 8278DA1C380 for ; Thu, 8 Feb 2024 16:58:00 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8278DA1C380 Received: by smtp54.i.mail.ru with esmtpa (envelope-from ) id 1rY4uc-00000004IcC-3nLV; Thu, 08 Feb 2024 16:57:59 +0300 Message-ID: <9f4c3bce-343d-4bab-b65d-dd7d2fb7d746@tarantool.org> Date: Thu, 8 Feb 2024 16:57:57 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sergey Kaplun , Maxim Kokryashkin Cc: tarantool-patches@dev.tarantool.org References: <20240207120648.12416-1-skaplun@tarantool.org> In-Reply-To: <20240207120648.12416-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: 4F1203BC0FB41BD91FEFD63CE1B09916A78EFF0F01B3EABA4FDA17758BA2BC0800894C459B0CD1B9E02C074E256A01F6AB1267D1E837311802580ACCEE8741C505E6D57BFE225C9752B81C99D67B1670 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7DC4D3EB6E237C32AEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006377A2EA98384B91C6C8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8AEB40C33F104FAB356A8C43DD3FBD1C318BA34DE1EF6E8C1CC7F00164DA146DAFE8445B8C89999728AA50765F79006370BDB19F53EE528DD389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8C2B5EEE3591E0D35F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C632EDEA9CD5989A3C0837EA9F3D197644AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C3BF1F585E929FBCC0BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CFED8438A78DFE0A9E1DD303D21008E298D5E8D9A59859A8B6D082881546D9349175ECD9A6C639B01B78DA827A17800CE7AEA1580DED4E70E3731C566533BA786AA5CC5B56E945C8DA X-C1DE0DAB: 0D63561A33F958A5A236E818E4475B2A5002B1117B3ED6960AA3F27340F4E4175B6221DB6D7A72AD823CB91A9FED034534781492E4B8EEAD21D4E6D365FE45D1BDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFB1714F54A4BC21ABF40D3379BFEDA3136674B95913CE8F008A361416DE0D878266401EE05C14F77D766A7423F6D95CBEB8C9145B5D02E4DA07DA359411CB848FA80CE1A34BCA77225F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojt6itc0777Zp2pqbABJgMlw== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458E9B03A5A47C99C4F7FC47A557B39A39B5F5A52BB64A0CA44E46AE3F0DD67E854645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit] Avoid out-of-range number of results when compiling select(k, ...). 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 2/7/24 15:06, Sergey Kaplun wrote: > From: Mike Pall > > The interpreter will throw and abort the trace, anyway. > > (cherry picked from commit 6ca580155b035fd369f193cdee59391b594a5028) > > The `recff_select()` sets the amount of `RecordFFData` structure even > for a negative first argument when trace is not recording (since the > interpreter will throw an error anyway). This leads to excess IR > emission and possible reads of dirty memory. > > This patch updates the `rd->nres` only in the case when a trace will be > recorded. > > Sergey Kaplun: > * added the description and the test for the problem > > Part of tarantool/tarantool#9595 > --- > > Branch: https://github.com/tarantool/luajit/tree/skaplun/fix-ff-select-recording > Tarantool PR: https://github.com/tarantool/tarantool/pull/9659 > Related issue: https://github.com/tarantool/tarantool/issues/9595 > > src/lj_ffrecord.c | 2 +- > .../fix-ff-select-recording.test.lua | 44 +++++++++++++++++++ > 2 files changed, 45 insertions(+), 1 deletion(-) > create mode 100644 test/tarantool-tests/fix-ff-select-recording.test.lua > > diff --git a/src/lj_ffrecord.c b/src/lj_ffrecord.c > index 99a6b918..cbba9524 100644 > --- a/src/lj_ffrecord.c > +++ b/src/lj_ffrecord.c > @@ -317,9 +317,9 @@ static void LJ_FASTCALL recff_select(jit_State *J, RecordFFData *rd) > ptrdiff_t n = (ptrdiff_t)J->maxslot; > if (start < 0) start += n; > else if (start > n) start = n; > - rd->nres = n - start; > if (start >= 1) { > ptrdiff_t i; > + rd->nres = n - start; > for (i = 0; i < n - start; i++) > J->base[i] = J->base[start+i]; > } /* else: Interpreter will throw. */ > diff --git a/test/tarantool-tests/fix-ff-select-recording.test.lua b/test/tarantool-tests/fix-ff-select-recording.test.lua > new file mode 100644 > index 00000000..8e0b4983 > --- /dev/null > +++ b/test/tarantool-tests/fix-ff-select-recording.test.lua > @@ -0,0 +1,44 @@ > +local tap = require('tap') > +local test = tap.test('fix-ff-select-recording'):skipcond({ > + ['Test requires JIT enabled'] = not jit.status(), > +}) > + > +test:plan(2) > + > +jit.opt.start('hotloop=1') > + > +-- XXX: simplify `jit.dump()` output. > +local select = select > + > +local recording = false > + > +-- `start` is the constant on trace, see below. > +local function varg_frame(start, ...) > + select(start, ...) > +end > + > +local LJ_MAX_JSLOTS = 250 > + > +local function varg_frame_wp() > + -- XXX: Need some constant negative value as the first argument > + -- of `select()` when recording the trace. > + -- Also, it should be huge enough to be greater than > + -- `J->maxslot`. The value on the first iteration is ignored. > + -- This will fail under ASAN due to a heap buffer overflow. > + varg_frame(recording and -(LJ_MAX_JSLOTS + 1) or 1) > +end > + > +jit.opt.start('hotloop=1') > + > +-- Make the function hot. > +varg_frame_wp() > + > +-- Try to record `select()` with a negative first argument. > +recording = true > +local res, err = pcall(varg_frame_wp) > + > +test:ok(not res, 'correct status') > +test:like(err, "bad argument #1 to 'select' %(index out of range%)", > + 'correct error message') > + > +test:done(true)