Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gVnZA-0004hn-P0 for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2018 01:07:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gVnZ8-0003IA-1d for pgsql-bugs@arkaria.postgresql.org; Sun, 09 Dec 2018 01:07:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gVnON-0008LS-10 for pgsql-bugs@lists.postgresql.org; Sun, 09 Dec 2018 00:56:19 +0000 Received: from m12-14.163.com ([220.181.12.14]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gVnOJ-0004S7-AM for pgsql-bugs@lists.postgresql.org; Sun, 09 Dec 2018 00:56:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=1ec9i +p9v+yl53XB6ujmSXeuEQzLQAs9mtm8k/uC1qQ=; b=UapaBcX9M1V1f8mkq+bLm u0NGa6e3URupizZWHaYx+cFLzdMDO9dMFWocsM4hMIwSMWp8GeHPtlQgVXpcX/Gu J09SX0KuQQzoYVRqn6lIpRLueUmtTuW5mm9DVnaVS4QPjUh6T5qzVfS5YB1Wly8d e0aY4gNXoApD4hGajuhpMY= Received: from bp (unknown [106.120.213.96]) by smtp10 (Coremail) with SMTP id DsCowACXXtItaAxcTnfFDw--.63365S2; Sun, 09 Dec 2018 08:56:13 +0800 (CST) Date: Sun, 9 Dec 2018 08:56:17 +0800 From: PanBian To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15540: Use after release in ExecuteTruncateGuts Message-ID: <20181209005617.GA65607@bp> Reply-To: PanBian References: <15540-01078812338195c0@postgresql.org> <31125.1544198945@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <31125.1544198945@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: DsCowACXXtItaAxcTnfFDw--.63365S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7XFyUKry5tF15Gr4ftw4DXFb_yoWkJwc_WF 4kWrWfuw4DGr4DW3W3K3yayFs3WF4DAr97J3yvqF1rtrWUJw1kuryqgwn5WryxW3y7JFn8 Cr93Gw1a93sxXjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUnNyCJUUUUU== X-Originating-IP: [106.120.213.96] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/xtbBZA0YclQHC1A4uQAAsK List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Dec 07, 2018 at 11:09:05AM -0500, Tom Lane wrote: > =?utf-8?q?PG_Bug_reporting_form?= writes: > > The function ExecuteTruncateGuts drops the reference to rel via > > relation_close when toast_relid is valid. However, after that, rel is passed > > to pgstat_count_truncate. This may result in a use-after-release bug. > > ... and, even more to the point, the truncation stats count is incorrectly > applied to the toast table not its parent. > > > Maybe, > > rel should be re-declared on the branch that toast_relid is valid. > > Yeah, seems like the right way. Will fix. > > Are you using a static analyzer to find these? I'm curious how > you noticed them. Yes. I write a static analysis tool. It can find functions that release memory or other resources. Let's call them free-like functions. With such free-like functions, the tool then performs data flow analysis to find use-after-free bugs. Of course, we can feed those free-like functions to other static analyzers such as Coverity. I believe it will work too. Best regards, Pan Bian > > regards, tom lane