Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlYLs-003Ioa-4w for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 17:29:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qlYLq-001amf-6K for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 17:29:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlYLp-001amI-S3 for pgsql-hackers@lists.postgresql.org; Wed, 27 Sep 2023 17:29:30 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlYLn-006xzh-IS for pgsql-hackers@postgresql.org; Wed, 27 Sep 2023 17:29:29 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D972B5C2823; Wed, 27 Sep 2023 13:29:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Wed, 27 Sep 2023 13:29:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1695835766; x=1695922166; bh=d+ XszRuoFRtcCEY47KlS0FeRddLUgcwt/vvfLq2rUrM=; b=BOQ4e6D1XfveTXpX1L NsP5BPmoaZN+FiMOwK+pdGbDej5z0rA0fWMdgQOT70E7wv0PAtVPetbzI4aCQy34 S2b2DyZ+EVavZLDfU5+6rmBEonr6l9s5Lnbczn0P2GaKEnzwLC4hKg2IYgtP4TcD avhdhG44XXDsevTGa0wQL4skiC1T64fIuaVW7FjCrtB8vjFlsE/ZpuVMbuq6Kf5m CKZrcbMPOa2fii28sY0LMTIs3eTEqHLCSJDw/1+ojx70AyQ15cnmuOjdvQVjbLvl pCEg1yhQ/ptxVINnA84doWtH1rw2gXh/6RfeiaT7owp5G5DAZWvRtZSZ+btcAyFR qlhA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1695835766; x=1695922166; bh=d+XszRuoFRtcC EY47KlS0FeRddLUgcwt/vvfLq2rUrM=; b=S5D2BI+rfrj/4D+jXJh7UblaNEaPy XpSxOgtBIzHcDkatnYT2MDxnRgPg6cfrQhLxW+W+wleOQeuGHgsXcBLcxe6BaDnx A9aYhXbEGQl5MBZj6vatsBK7m6qquhIWJf822zhV5JtmJHtTMa+PynnDS14TI/8r ZBvhEhC5C14f593CCsPVBFM9/vOCOt4LVPk+2+corWWmeSmgE7ll55b12N+zjBO7 nvJfCqwv/wiYaW6Qpbbn2Z+TA0rApv8//R/TzIA+R86urCNV8o2q0JBrS1Sm09e+ ChVWS8yn06t5ECubsyfu30jizfAvuoyhqGOPfzyUJWfQ7CPguKtIICayA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvjedrtdeggdehtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteevudei tedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Sep 2023 13:29:26 -0400 (EDT) Date: Wed, 27 Sep 2023 10:29:25 -0700 From: Andres Freund To: Peter Eisentraut Cc: Michael Paquier , Jakub Wartak , PostgreSQL Hackers , Robert Haas Subject: Re: pg_stat_get_activity(): integer overflow due to (int) * (int) for MemoryContextAllocHuge() Message-ID: <20230927172925.xmyoardgxoifdpgu@alap3.anarazel.de> References: <45ba068b-66ea-b74c-5a92-6c2127d63e28@eisentraut.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45ba068b-66ea-b74c-5a92-6c2127d63e28@eisentraut.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2023-09-27 15:42:15 +0100, Peter Eisentraut wrote: > On 27.09.23 09:08, Michael Paquier wrote: > > On Wed, Sep 27, 2023 at 08:41:55AM +0200, Jakub Wartak wrote: > > > Attached patch adjusts pgstat_track_activity_query_size to be of > > > size_t from int and fixes the issue. > > > > This cannot be backpatched, and using size_t is not really needed as > > track_activity_query_size is capped at 1MB. Why don't you just tweak > > the calculation done in pgstat_read_current_status() instead, say with > > a cast? > > I think it's preferable to use the right type to begin with, rather than > fixing it up afterwards with casts. I don't think going for size_t is a viable path for fixing this. I'm pretty sure the initial patch would trigger a type mismatch from guc_tables.c - we don't have infrastructure for size_t GUCs. Nor do I think either of the patches here is a complete fix - there will still be overflows on 32bit systems. Perhaps we ought to error out (in BackendStatusShmemSize() or such) if pgstat_track_activity_query_size * MaxBackends >= 4GB? Frankly, it seems like a quite bad idea to have such a high limit for pgstat_track_activity_query_size. The overhead such a high value has will surprise people... Greetings, Andres Freund