Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7e25-0001si-4k for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Aug 2020 12:14:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1k7e23-0000u4-Tq for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Aug 2020 12:14:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7e23-0000tx-N6 for pgsql-hackers@lists.postgresql.org; Mon, 17 Aug 2020 12:14:31 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k7e20-00065o-Ni for pgsql-hackers@postgresql.org; Mon, 17 Aug 2020 12:14:31 +0000 Received: from hnk.local (p12054-ipngn2901funabasi.chiba.ocn.ne.jp [153.212.171.54]) by oss.nttdata.com (Postfix) with ESMTPSA id 4206F602BA; Mon, 17 Aug 2020 21:14:23 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: Creating a function for exposing memory usage of backend process To: torikoshia , PostgreSQL-development Cc: Robert Haas , Kasahara Tatsuhito , Andres Freund , Michael Paquier References: <805313b5f7dc2e6c19b209ff930a7a61@oss.nttdata.com> <9ee242b1-9e70-18f5-0033-6a086e71164d@oss.nttdata.com> <3548926512ddfaedfb5eaf967bf2f196@oss.nttdata.com> <20200708170348.rsqry4b4k5mrsu7y@alap3.anarazel.de> <24ea05d7bbdb652feef50caee6fcfbf8@oss.nttdata.com> <20200808014409.GA1600@paquier.xyz> <66c9d45297ad820cd092b125aa91ce2c@oss.nttdata.com> From: Fujii Masao Message-ID: <98e53274-253f-6bd1-b542-489ecbda8753@oss.nttdata.com> Date: Mon, 17 Aug 2020 21:14:22 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <66c9d45297ad820cd092b125aa91ce2c@oss.nttdata.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/08/11 15:24, torikoshia wrote: > On 2020-08-08 10:44, Michael Paquier wrote: >> On Fri, Jul 31, 2020 at 03:23:52PM -0400, Robert Haas wrote: >>> On Fri, Jul 31, 2020 at 4:25 AM torikoshia wrote: >>>> And as Fujii-san told me in person, exposing memory address seems >>>> not preferable considering there are security techniques like >>>> address space layout randomization. >>> >>> Yeah, exactly. ASLR wouldn't do anything to improve security if there >>> were no other security bugs, but there are, and some of those bugs are >>> harder to exploit if you don't know the precise memory addresses of >>> certain data structures. Similarly, exposing the addresses of our >>> internal data structures is harmless if we have no other security >>> bugs, but if we do, it might make those bugs easier to exploit. I >>> don't think this information is useful enough to justify taking that >>> risk. >> >> FWIW, this is the class of issues where it is possible to print some >> areas of memory, or even manipulate the stack so as it was possible to >> pass down a custom pointer, so exposing the pointer locations is a >> real risk, and this has happened in the past.  Anyway, it seems to me >> that if this part is done, we could just make it superuser-only with >> restrictive REVOKE privileges, but I am not sure that we have enough >> user cases to justify this addition. > > > Thanks for your comments! > > I convinced that exposing pointer locations introduce security risks > and it seems better not to do so. > > And I now feel identifying exact memory context by exposing memory > address or other means seems overkill. > Showing just the context name of the parent would be sufficient and > 0007 pattch takes this way. Agreed. > > > On 2020-08-07 16:38, Kasahara Tatsuhito wrote: >> The following review has been posted through the commitfest application: >> make installcheck-world:  tested, passed >> Implements feature:       tested, passed >> Spec compliant:           not tested >> Documentation:            tested, passed >> >> I tested the latest >> patch(0007-Adding-a-function-exposing-memory-usage-of-local-backend.patch) >> with the latest PG-version (199cec9779504c08aaa8159c6308283156547409) >> and test was passed. >> It looks good to me. >> >> The new status of this patch is: Ready for Committer > > Thanks for your testing! Thanks for updating the patch! Here are the review comments. + + pg_backend_memory_contexts + backend memory contexts + The above is located just after pg_matviews entry. But it should be located just after pg_available_extension_versions entry. Because the rows in the table "System Views" should be located in alphabetical order. + + <structname>pg_backend_memory_contexts</structname> Same as above. + The view pg_backend_memory_contexts displays all + the local backend memory contexts. This description seems a bit confusing because maybe we can interpret this as "... displays the memory contexts of all the local backends" wrongly. Thought? What about the following description, instead? The view pg_backend_memory_contexts displays all the memory contexts of the server process attached to the current session. + const char *name = context->name; + const char *ident = context->ident; + + if (context == NULL) + return; The above check "context == NULL" is useless? If "context" is actually NULL, "context->name" would cause segmentation fault, so ISTM that the check will never be performed. If "context" can be NULL, the check should be performed before accessing to "contect". OTOH, if "context" must not be NULL per the specification of PutMemoryContextStatsTupleStore(), assertion test checking "context != NULL" should be used here, instead? Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION