From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Sun, 7 Apr 2019 14:38:14 +0300 From: Vladimir Davydov Subject: Re: [PATCH] box: fix use-after-free in space_truncate Message-ID: <20190407113814.t53poaevxqilwvve@esperanza> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: To: tarantool-patches@freelists.org List-ID: On Sun, Apr 07, 2019 at 02:24:30PM +0300, Vladimir Davydov wrote: > space_truncate allocates a statement on the stack which is grossly > incorrect as the stack may be purged once the function returns while > box_process_rw expects the statement to be valid until the end of > the transaction. By happy accident, it worked fine until commit > 1f7b0d6577f4 ("Require for single statement not autocommit in case of > ddl"), which made it possible to run this function from a transaction > and hence increased the probability of hitting the use-after-free bug. > The fix is trivial: allocate a truncation statement on the region. > > Fixes commit 353bcdc5d010 ("Rework space truncation"). > > Closes #4093 > --- > https://github.com/tarantool/tarantool/issues/4093 > https://github.com/tarantool/tarantool/commits/dv/fix-use-after-free-in-space-truncate > > src/box/box.cc | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) This one is pretty obvious. Pushed to master and resurrected the box/transaction test case that triggered the use-after-free bug. Since the bus was there for two years and we were just lucky not to step on it, I also cherry-picked this commit to 2.1 and 1.10.