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 1hSmqi-0004pf-PL for pgsql-hackers@arkaria.postgresql.org; Mon, 20 May 2019 18:17:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hSmqh-000197-AU for pgsql-hackers@arkaria.postgresql.org; Mon, 20 May 2019 18:17:23 +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 1hSmqg-00018z-Ns for pgsql-hackers@lists.postgresql.org; Mon, 20 May 2019 18:17:23 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSmqc-0000P6-Tv for pgsql-hackers@postgresql.org; Mon, 20 May 2019 18:17:21 +0000 Received: by mail-wr1-x441.google.com with SMTP id d18so15687149wrs.5 for ; Mon, 20 May 2019 11:17:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=QUxY2Ev1POmOqLZg05qZPaOOUsOGNOpPKH86CELqP8Y=; b=Prq2eUGoELP3fQVRW3jjU+b0PGYoPaXNjhsD/qLELbfdy29WD35FZSXsXmTq7VZOPp 2bhWa6v36gz4HM4fL2SFuIbjSC8dmyOOZcNmcezZS9NqMth5m3bDpTk94bb61I76sPDx OPNGYQab5GEJ21nRIh3WZX2u3jbyqxmXbFbth09esPhSNNiIVjmWhU8DSgXOdbfeHGqC rOVoHPJIqhINz/jmnHBXSL6TTElAzRsvcP9tGWYCCaT5y2u+Sbwciv+a4fMWUIqZ8Iyk Efrjjx9oBFuMkWDYdlehVnyMqoHQJkbqSByAdzz/rmjwOSoP3FivYDA1jBJDrGUonqAU 1bKQ== 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=QUxY2Ev1POmOqLZg05qZPaOOUsOGNOpPKH86CELqP8Y=; b=Cpbnos7RLQfesHE02f41wYRgjZimD2+P1HWIq5mpYdAJkvIZs6C3fMC/7/UdsXffI6 GJ5giIIAwkLJDPKJe6akJBw2cptePzCgm4uJW8QThtZ1wNejbnGWWPxw/bRez1q4tQdy wweDNHIfRIi5j0lJuiCE7R+/PU570B2QNPr7ZRg+31RD6O5/uv6EzXoX1kK1IH4R75Do nWiD/D6X7HhwNCqLa35m8u9wCe8KYTgW1RtOAW6rh0gtL+FhK/CRLc4gIX69SSw2LES4 jPmYmQFJ75jtzfIx8/dIbNILXH5tLozQjSFMOShMqT6tn3WNG/RV1GhDjl/bazGMVz8d gQvg== X-Gm-Message-State: APjAAAXtdH2I+mvmJAExhxZ+yWprHS467ATflKubtbUOgC8oOJGKysVc TlpRb2xm6SkmpYW0hxxSmxzHUw== X-Google-Smtp-Source: APXvYqxzul4heTX3pAteGM/0UxizJuxA/qfmfsLC785DyCKBP02YbKAfcA/11Mn4LSEIqB91nByXQw== X-Received: by 2002:a5d:440a:: with SMTP id z10mr5792275wrq.157.1558376237495; Mon, 20 May 2019 11:17:17 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id t7sm23306946wrq.76.2019.05.20.11.17.16 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 20 May 2019 11:17:16 -0700 (PDT) Date: Mon, 20 May 2019 20:17:14 +0200 From: Tomas Vondra To: Dean Rasheed Cc: Tom Lane , Stephen Frost , Andres Freund , PostgreSQL Hackers Subject: Re: Multivariate MCV stats can leak data to unprivileged users Message-ID: <20190520181714.fm4a4yjtgffh6kst@development> References: <20190518234841.GE6197@tamriel.snowman.net> <23229.1558275148@sss.pgh.pa.us> <23772.1558276123@sss.pgh.pa.us> <20190519173845.tgf7ku3vigwgndn5@development> <2509.1558289694@sss.pgh.pa.us> <20190519224459.7dsdnv5gsfmnm4em@development> <23581.1558359144@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, May 20, 2019 at 04:09:24PM +0100, Dean Rasheed wrote: >On Mon, 20 May 2019 at 14:32, Tom Lane wrote: >> >> Dean Rasheed writes: >> > On Sun, 19 May 2019 at 23:45, Tomas Vondra wrote: >> >> Oh, right. It still has the disadvantage that it obfuscates the actual >> >> data stored in the pg_stats_ext_data (or whatever would it be called), >> >> so e.g. functions would have to do additional checks to make sure it >> >> actually is the right statistic type. For example pg_mcv_list_items() >> >> could not rely on receiving pg_mcv_list values, as per the signature, >> >> but would have to check the value. >> >> > Yes. In fact, since the user-accessible view would want to expose >> > datatypes specific to the stats kinds rather than bytea or cstring >> > values, we would need SQL-callable conversion functions for each kind: >> >> It seems like people are willfully misunderstanding my suggestion. > >I'm more than capable of inadvertently misunderstanding, without the >need to willfully do so :-) > >> You'd only need *one* conversion function, which would look at the >> embedded ID field and then emit the appropriate text representation. >> I don't see a reason why we'd have the separate pg_ndistinct etc. types >> any more at all. > >Hmm, OK. So then would you also make the user-accessible view agnostic >about the kinds of stats supported in the same way, returning zero or >more rows per STATISTICS object, depending on how many kinds of stats >have been built? That would have the advantage of never needing to >change the view definition again, as more stats kinds are supported. > If I got Tom's proposal right, there'd be only one statistic value in each pg_stats_ext_data value. It'd be a very thin wrapper, essentially just the value itself + type flag. So for example if you did CREATE STATISTICS s (ndistinct, mcv, dependencies) ... you'd get three rows in pg_statistic_ext_data (assuming all the stats get actually built). >We'd need to change pg_mcv_list_items() to accept a pg_stats_ext_data >value rather than a pg_mcv value, and it would be the user's >responsibility to call it if they wanted to see the contents of the >MCV list (I was originally thinking that we'd include a call to >pg_mcv_list_items() in the view definition, so that it produced >friendlier looking output, since the default textual representation of >an MCV list is completely opaque, unlike the other stats kinds). >Actually, I can see another advantage to not including >pg_mcv_list_items() in the view definition -- in the future, we may >dream up a better version of pg_mcv_list_items(), like say one that >produced JSON, and then we'd regret using the current function. > Yeah. As I said, it obfuscates the "actual" type of the stats value, so we can no longer rely on the function machinery to verify the type. All functions dealing with the "wrapper" type would have to verify it actually contains the right statistic type. >> Anyway, it was just a suggestion, and if people don't like it that's >> fine. But I don't want it to be rejected on the basis of false >> arguments. > >To be clear, I'm not intentionally rejecting your idea. I'm merely >trying to fully understand the implications. > >At this stage, perhaps it would be helpful to prototype something for >comparison. > I'll look into that. I'll try to whip something up before pgcon, but I can't guarantee that :-( regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services