aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2023-10-03 15:37:21 +0900
committerMichael Paquier <michael@paquier.xyz>2023-10-03 15:37:21 +0900
commitf91c87b31463d2e368189ca35aaefc07b54aeef1 (patch)
tree067b6ddb28372a80c07dedbb64b6313025782a6a
parentbaeb8542c1cc849e58c016f401687b9c4d3e7f20 (diff)
downloadpostgresql-f91c87b31463d2e368189ca35aaefc07b54aeef1.tar.gz
postgresql-f91c87b31463d2e368189ca35aaefc07b54aeef1.zip
Avoid memory size overflow when allocating backend activity buffer
The code in charge of copying the contents of PgBackendStatus to local memory could fail on memory allocation because of an overflow on the amount of memory to use. The overflow can happen when combining a high value track_activity_query_size (max at 1MB) with a large max_connections, when both multiplied get higher than INT32_MAX as both parameters treated as signed integers. This could for example trigger with the following functions, all calling pgstat_read_current_status(): - pg_stat_get_backend_subxact() - pg_stat_get_backend_idset() - pg_stat_get_progress_info() - pg_stat_get_activity() - pg_stat_get_db_numbackends() The change to use MemoryContextAllocHuge() has been introduced in 8d0ddccec636, so backpatch down to 12. Author: Jakub Wartak Discussion: https://postgr.es/m/CAKZiRmw8QSNVw2qNK-dznsatQqz+9DkCquxP0GHbbv1jMkGHMA@mail.gmail.com Backpatch-through: 12
-rw-r--r--src/backend/utils/activity/backend_status.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index 72295988226..6917ef4c4ba 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -764,7 +764,8 @@ pgstat_read_current_status(void)
NAMEDATALEN * NumBackendStatSlots);
localactivity = (char *)
MemoryContextAllocHuge(backendStatusSnapContext,
- pgstat_track_activity_query_size * NumBackendStatSlots);
+ (Size) pgstat_track_activity_query_size *
+ (Size) NumBackendStatSlots);
#ifdef USE_SSL
localsslstatus = (PgBackendSSLStatus *)
MemoryContextAlloc(backendStatusSnapContext,