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 0474CA16BA7; Thu, 8 Feb 2024 12:30:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 0474CA16BA7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1707384644; bh=HVO2uOPFyr9oeQWw6CRqpwqD6rry35QV9E5DGEPt36U=; 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=io3znUazUbFp5NFQlgcebUwVI02qsc8ViL36i3pc1mrOrF51N9hDJ4CFK6uyGC0E0 MwiMBUcFRf26Hsd7g9/UrXwvaYkbO/y4dKqitVNEjiv/hlElqMjC8vIe/Wwe8UTyi9 6n43GwY3LCNrIFpwScnZaQZORFRfo/h1Yl4DP4a8= Received: from smtp30.i.mail.ru (smtp30.i.mail.ru [95.163.41.71]) (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 D8BEAA16B95 for ; Thu, 8 Feb 2024 12:30:42 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D8BEAA16B95 Received: by smtp30.i.mail.ru with esmtpa (envelope-from ) id 1rY0jx-00000006y8I-1uWD; Thu, 08 Feb 2024 12:30:41 +0300 Message-ID: <8e9ceb71-4234-4b72-9f76-80f164ca591d@tarantool.org> Date: Thu, 8 Feb 2024 12:30:41 +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: 8bit X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD91186BE9DD66FF4271943C06C8DFE5408E6423ADC1E695FFC182A05F5380850404C228DA9ACA6FE27DB1DDBB34976E8162EB5D77EF37489D1F0CF87E236DD1CF59E601EFFEC64C65FD7B80A6ED51EB853 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE79173C6E970493712EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006373880C950E4B364568638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D84F55C58BC0DA34AE3AFC56A36A3E086B4E56EEC0395C38A8CC7F00164DA146DAFE8445B8C89999728AA50765F79006375FFD5C25497261569FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C3E97D2AE7161E217F117882F4460429728AD0CFFFB425014E868A13BD56FB6657D81D268191BDAD3DC09775C1D3CA48CF6F560EC7065075D7BA3038C0950A5D36C8A9BA7A39EFB766D91E3A1F190DE8FDBA3038C0950A5D36D5E8D9A59859A8B618DD0AD7861BC86C76E601842F6C81A1F004C906525384303E02D724532EE2C3F43C7A68FF6260569E8FC8737B5C2249957A4DEDD2346B42E827F84554CEF50127C277FBC8AE2E8BF1175FABE1C0F9B6AAAE862A0553A39223F8577A6DFFEA7CEB8BE9EE02D59E2D43847C11F186F3C59DAA53EE0834AAEE X-C1DE0DAB: 0D63561A33F958A5F80BAD967055D4005002B1117B3ED6968A36A7116A0437CF3E67C18142C611B7823CB91A9FED034534781492E4B8EEAD01200A96CB7104FFBDAD6C7F3747799A X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CF0B98ABBD01CC3F571152BCED8D6717C44316090FA63A5F9395BE50EEF11E6BD025059624982F7461766A7423F6D95CBE8D68164D1148FFE563D5A03EA3AEC35AD34AD723E930F5475F4332CA8FE04980913E6812662D5F2AB9AF64DB4688768036DF5FE9C0001AF333F2C28C22F508233FCF178C6DD14203 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojlN/n4z3iVuQEoGGyG/L7/w== X-Mailru-Sender: C4F68CFF4024C8867DFDF7C7F2588458DE440A5D98CE0C36BC5A20191D90C84F94CDC7551E86406E133F8D14414CA7C0645D15D82EE4B272BD6E4642A116CA93524AA66B5ACBE6721EF430B9A63E2A504198E0F3ECE9B5443453F38A29522196 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 couldn't reproduce a problem by provided test. What compilation options I've used: 1st attempt: cmake -S . -B build -DLUA_USE_ASSERT=ON -DLUA_USE_APICHECK=ON 2nd attempt: CMAKE_BUILD_TYPE="Debug" CMAKE_C_COMPILER="clang" CMAKE_EXPORT_COMPILE_COMMANDS:BOOL="TRUE" LUAJIT_ENABLE_COVERAGE:BOOL="FALSE" LUAJIT_ENABLE_GC64:BOOL="TRUE" LUAJIT_USE_ASAN:BOOL="FALSE" LUAJIT_USE_SYSMALLOC:BOOL="FALSE" LUA_USE_APICHECK:BOOL="TRUE"   LUA_USE_ASSERT:BOOL="TRUE" Sergey 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)