Skip to content

Fix heap overflow when a Unix-domain socket path is skipped as too long. - #185

Open
jirutka wants to merge 1 commit into
pgpool:masterfrom
jirutka:fix-skipped-unix-socket-path
Open

jirutka wants to merge 1 commit into
pgpool:masterfrom
jirutka:fix-skipped-unix-socket-path

Conversation

@jirutka

@jirutka jirutka commented Nov 26, 2026

Copy link
Copy Markdown

When building the lists of Unix-domain socket addresses from unix_socket_directories and pcp_socket_dir, PgpoolMain() skips an entry whose path is too long with a WARNING and continue. The address array is grown by realloc() to hold num_unix_fds + 1 (num_pcp_fds + 1) elements, but the new element was written at the index of the loop counter i. Once an entry has been skipped, i is ahead of the number of stored entries, so the write lands one or more elements past the end of the array (heap buffer overflow), and the slots in front of it are left uninitialized. The uninitialized slot is later passed to create_unix_domain_socket() as a path to unlink() and bind().

Write the new address to the first free slot, un_addrs[num_unix_fds] (pcp_un_addrs[num_pcp_fds]), instead of un_addrs[i] (pcp_un_addrs[i]), so the array stays dense when entries are skipped, and matches the indexes used by its consumers.

The problem is triggered only by a too-long directory followed by a valid one in pgpool.conf, so it needs a misconfiguration by an administrator and does not cross a privilege boundary.

When building the lists of Unix-domain socket addresses from
`unix_socket_directories` and `pcp_socket_dir`, `PgpoolMain()` skips an
entry whose path is too long with a WARNING and `continue`. The
address array is grown by `realloc()` to hold `num_unix_fds + 1`
(`num_pcp_fds + 1`) elements, but the new element was written at the
index of the loop counter `i`. Once an entry has been skipped, `i` is
ahead of the number of stored entries, so the write lands one or more
elements past the end of the array (heap buffer overflow), and the
slots in front of it are left uninitialized. The uninitialized slot
is later passed to `create_unix_domain_socket()` as a path to `unlink()`
and `bind()`.

Write the new address to the first free slot, `un_addrs[num_unix_fds]`
(`pcp_un_addrs[num_pcp_fds]`), instead of `un_addrs[i]`
(`pcp_un_addrs[i]`), so the array stays dense when entries are skipped,
and matches the indexes used by its consumers.

The problem is triggered only by a too-long directory followed by a
valid one in `pgpool.conf`, so it needs a misconfiguration by an
administrator and does not cross a privilege boundary.
@tatsuo-ishii

tatsuo-ishii commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for the report. I confirm the error and your patch fixes it.
I would like to continue the discussion on the pgpool-hackers mailing list as we do not accept pull requests (this repository is just a mirror of the original repository at: https://git.postgresql.org/gitweb/?p=pgpool2.git;a=summary)
https://www.postgresql.org/message-id/20261128.182312.305787946098028286.ishii%40postgresql.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants