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 1hCQgP-0000Da-Na for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Apr 2019 15:23:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hCQgN-0002KR-75 for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Apr 2019 15:23:07 +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 1hCQgM-0002KK-Uc for pgsql-hackers@lists.postgresql.org; Fri, 05 Apr 2019 15:23:06 +0000 Received: from mx1.mailbox.org ([2001:67c:2050:104:0:1:25:1]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hCQgF-0006i1-MC for pgsql-hackers@postgresql.org; Fri, 05 Apr 2019 15:23:06 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id B80274BB5D; Fri, 5 Apr 2019 17:22:56 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id qlL-jp9pmI5k; Fri, 5 Apr 2019 17:22:44 +0200 (CEST) From: Antonin Houska To: Robert Haas cc: Tom Lane , Toshi Harada , "pgsql-hackers@postgresql.org" Subject: Re: "WIP: Data at rest encryption" patch and, PostgreSQL 11-beta3 In-reply-to: References: <5907.1534140361@localhost> <201808150211.w7F2ApMj023097@ccmail04.silk.ntt-tx.co.jp> <19039.1536933944@localhost> <14646.1552570130@localhost> <13456.1552684223@sss.pgh.pa.us> <27465.1553168779@localhost> Comments: In-reply-to Robert Haas message dated "Thu, 21 Mar 2019 16:07:15 -0400." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13530.1554477762.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 05 Apr 2019 17:22:42 +0200 Message-ID: <13531.1554477762@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Robert Haas wrote: > On Thu, Mar 21, 2019 at 7:46 AM Antonin Houska wrote: > > Nevertheless, with the current version of our patch, PG should be resi= stant > > against such a partial write anyway because we chose to align XLOG rec= ords to > > 16 bytes (as long as the encryption is enabled) for the following reas= ons: > > > > If one XLOG record ends and the following one starts in the same encry= ption > > block, both records can get corrupted during streaming replication. Th= e > > scenario looks like: 1) the first record is written on master (the unu= sed part > > of the block contains zeroes), 2) the block is encrypted and its initi= al part > > (i.e. the number of bytes occupied by the first record in the plain te= xt) is > > streamed to slave, 3) the second record is written on master, 4) the > > containing encryption block is encrypted again and the trailing part (= i.e. the > > number of bytes occupied by the second record) is streamed, 5) decrypt= ion of > > the block on slave will produce garbage and thus corrupt both records.= This is > > because the trailing part of the block was filled with zeroes during > > encryption, but it contains different data at decryption time. > = > Wouldn't Tom's proposal to use a stream cipher fix all this? Yes it would make the extra alignment unnecessary, but our solution tries = to meet specific requirements of disk encryption. Stream cipher appears to be incompatible with these requirements: https://en.wikipedia.org/wiki/Disk_encryption_theory Currently we try to use the CBC-ESSIV mode. It's worth to mention that in = this mode, if the page is encrypted twice and if the plain data in the encrypti= on block N (i.e. block of 16 bytes) changes before the 2nd encryption, the encrypted data will only change in blocks >=3D N. So the problem of losing already flushed WAL records should not happen. -- = Antonin Houska Web: https://www.cybertec-postgresql.com