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 1hn4T6-0000o3-8t for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jul 2019 17:08:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hn4T5-0003c5-3y for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jul 2019 17:08:51 +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 1hn4T4-0003by-NH for pgsql-hackers@lists.postgresql.org; Mon, 15 Jul 2019 17:08:50 +0000 Received: from cyclops.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hn4T2-0006xt-0B for pgsql-hackers@postgresql.org; Mon, 15 Jul 2019 17:08:50 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 167B221C04DD; Mon, 15 Jul 2019 20:08:44 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.0.108] (pool-77-222-108-183.is74.ru [77.222.108.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id D444421C022B; Mon, 15 Jul 2019 20:08:43 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1563210524; bh=ON+m/9EtMw2RBTOyYy9OQuOAq3yUJ8sh7l3PoXVjk6M=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=BDhWouGXYqWu67xBzSE/gWE0ViH4Vbk6yeJix7ASO9sNuj86yZSOa9aSCoeMnW998 EQqdddw4v5MgCdli3h8BIKUO3S+TofYTHCh1nmL7bCKCZyffBhzBeJBp9H/6QE2VXU Y/xJmCMoMXF6BgeWs6mcru75OSTZH5J6YRhs/lbA= Subject: Re: Insecure initialization of required_relids field To: Tom Lane Cc: PostgreSQL-Dev References: <5c21029d-81a2-c999-6744-6a898fcc9a19@postgrespro.ru> <29956.1563198507@sss.pgh.pa.us> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: Date: Mon, 15 Jul 2019 22:08:41 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <29956.1563198507@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 15/07/2019 18:48, Tom Lane wrote: > Andrey Lepikhov writes: >> commit a31ad27fc5d introduced required_relids field. By default, it >> links to the clause_relids. >> It works good while we do not modify clause_relids or required_relids. >> But in the case of modification such initialization demands us to >> remember, that this field is shared. And we need to do bms_copy() before >> making any changes (see [1] for example). >> Also, we make some changes of the RestrictInfo fields (see patch [2]) >> during removing of unneeded self joins. >> I propose to do more secure initialization way of required_relids (see >> patch in attachment). > > This seems fairly expensive (which is why it wasn't done like that > to start with) and you've pointed to no specific bug that it fixes. > Seeing that (a) the original commit is 14 years old, and (b) changing > either of these fields after-the-fact is at most a very niche usage, > I don't think we really have a problem here. In the patch 'Removing unneeded self joins' [1] we modify both clause_relids and required_relids. Valgrind detected a problem: during the required_relids change routine repalloc() was executed. In this case, clause_relids will point to free memory block. In accordance to your answer do you recommend me to make the bms_copy() call before changing any of clause_relids and required_relids fields? [1] https://commitfest.postgresql.org/23/1712/ -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company