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 1ge1KN-0007R9-PV for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Dec 2018 17:26:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ge1KM-0002MG-6F for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Dec 2018 17:26:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ge1KL-0002Jo-JF for pgsql-hackers@lists.postgresql.org; Mon, 31 Dec 2018 17:26:09 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ge1KI-0004Wy-4k for pgsql-hackers@lists.postgresql.org; Mon, 31 Dec 2018 17:26:07 +0000 Received: by mail-io1-xd44.google.com with SMTP id m19so21682390ioh.3 for ; Mon, 31 Dec 2018 09:26:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qjq3uk/9/W+A/jORre5dHg27GJfhg+LrXoQLE0U/utA=; b=Bp3JTTOWtC52EAAlHTZW6VkMYa91GZiYIOv9/kypQhFdiPC2nybZwY5baVSmB/OCs2 bpoTkEurZ/XIufjySP+ECDHPyv8aQL1dxcAwxQNC2oghZg6xajkIv+4SFwrZmcVScLtz wmtn9cQcX7i6brjj4LHNz08KLC9p3zAM8pBXY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qjq3uk/9/W+A/jORre5dHg27GJfhg+LrXoQLE0U/utA=; b=mas2pYoHfyZOesA8sRoL1ZfUKp4U3h0Bu+Q7+Y8BTSVCoqZUX5t5k28Oq2GkXaKykL xFBhnhDqgbLwVuI19E6dhubRe+OhIehWIyUj9Roo3IVZCf0R6ksH10QRs5GnDd7oMt1G VXL7UczArJDdIXtjxZEoda3cMhiOnkCB6dwLDZNm1Kt1FosIzqM7x2mV0DVasLI971u5 VdqTXCiImQXaylUmN7gPW9fndx6ETUHJ1nOr9LpmOi/SZX5bSo86k07kDWP8lU8CCxMr fi2QcVsAnmkvKOVsGS/cIsuFz8t+6gZ/hB1e809Y36EAKrdhYNV0yNrNVmBKb7FRAXda kIZg== X-Gm-Message-State: AJcUukfOXsZ3HeXFRbjVA5kDzfbl5qvxh9QdPbMRrUzkgeBGrFwUk+LL j00rD82X3GJ0Kj0gze9qtWmN5amhoOY= X-Google-Smtp-Source: ALg8bN4BLAFIlXEgz/IHG6wRvhwrcJycK9n1FenAP1hM8QRgJMmLUZZEyUuaqFrAxa+bW06tJBwt/A== X-Received: by 2002:a5d:9913:: with SMTP id x19mr7595554iol.99.1546277165070; Mon, 31 Dec 2018 09:26:05 -0800 (PST) Received: from gust.leadboat.com ([172.243.182.239]) by smtp.gmail.com with ESMTPSA id p132sm17124620itb.35.2018.12.31.09.25.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 31 Dec 2018 09:26:04 -0800 (PST) Date: Mon, 31 Dec 2018 12:25:51 -0500 From: Noah Misch To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org, Stephen Frost Subject: Re: Is MinMaxExpr really leakproof? Message-ID: <20181231172551.GA206480@gust.leadboat.com> References: <31042.1546194242@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <31042.1546194242@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This thread duplicates https://postgr.es/m/flat/16539.1431472961%40sss.pgh.pa.us On Sun, Dec 30, 2018 at 01:24:02PM -0500, Tom Lane wrote: > So this coding amounts to an undocumented > assumption that every non-cross-type btree comparison function is > leakproof. > select p.oid::regprocedure from pg_proc p, pg_amproc a, pg_opfamily f > where p.oid=a.amproc and f.oid=a.amprocfamily and opfmethod=403 and not proleakproof and amproclefttype=amprocrighttype and amprocnum=1; > > bpcharcmp(character,character) > btarraycmp(anyarray,anyarray) > btbpchar_pattern_cmp(character,character) > btoidvectorcmp(oidvector,oidvector) > btrecordcmp(record,record) > btrecordimagecmp(record,record) > bttext_pattern_cmp(text,text) > bttextcmp(text,text) > enum_cmp(anyenum,anyenum) > jsonb_cmp(jsonb,jsonb) > numeric_cmp(numeric,numeric) > pg_lsn_cmp(pg_lsn,pg_lsn) > range_cmp(anyrange,anyrange) > tsquery_cmp(tsquery,tsquery) > tsvector_cmp(tsvector,tsvector) > > so this assumption is, on its face, wrong. > > In practice it might be all right, because it's hard to see a reason why > a btree comparison function would ever throw an error except for internal > failures, which are probably outside the scope of leakproofness guarantees > anyway. Nonetheless, if we didn't mark these functions as leakproof, > why not? pg_lsn_cmp() and btoidvectorcmp() surely could advertise leakproofness. I'm not sure about enum_cmp(), numeric_cmp(), tsquery_cmp() or tsvector_cmp(). I can't think of a reason those would leak, though. btrecordcmp() and other polymorphic cmp functions can fail: create type boxrec as (a box); select '("(1,1),(0,0)")'::boxrec = '("(1,1),(0,0)")'::boxrec; => ERROR: could not identify an equality operator for type box The documentation says, "a function which throws an error message for some argument values but not others ... is not leakproof." I would be comfortable amending that to allow the "could not identify an equality operator" error, because that error follows from type specifics, not value specifics. bttextcmp() and other varstr_cmp() callers fall afoul of the same restriction with their "could not convert string to UTF-16" errors (https://postgr.es/m/CADyhKSXPwrUv%2B9LtqPAQ_gyZTv4hYbr2KwqBxcs6a3Vee1jBLQ%40mail.gmail.com). Leaking the binary fact that an unspecified string contains an unspecified rare Unicode character is not a serious leak, however. Also, those errors would be a substantial usability impediment if they happened much in practice; you couldn't index affected values. > I think that we should either change contain_leaked_vars_walker to > explicitly verify leakproofness of the comparison function, or decide > that it's project policy that btree comparison functions are leakproof, > and change the markings on those (and their associated operators). Either of those solutions sounds fine. Like last time, I'll vote for explicitly verifying leakproofness.