Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process title is too much short #215

Closed
fluca1978 opened this issue Feb 25, 2022 · 4 comments
Closed

process title is too much short #215

fluca1978 opened this issue Feb 25, 2022 · 4 comments
Labels
enhancement Improvement to an existing feature

Comments

@fluca1978
Copy link
Collaborator

Version 1.4 (HEAD):

% pgagroal -d       
% ps -auxw | grep pgagr
luca       16998  0.0  0.3  69316  2656 ?        Ss   05:59   0:00 pgagroal: ma

the process title should be pgagroal: main, according to https://github.com/agroal/pgagroal/blob/master/src/libpgagroal/utils.c#L774 but it is truncated at https://github.com/agroal/pgagroal/blob/master/src/libpgagroal/utils.c#L777 because max_process_title_size is lower. The problem appears to be here https://github.com/agroal/pgagroal/blob/master/src/libpgagroal/utils.c#L762 because the max_process_title is computed on the basis of argv and therefore it depends on the length of the command line.
In other words, invoking pgagroal will result in max_process_title_suze to be 9, invoking pgagroal -d will make max_process-title_size to be 12, and /usr/local/bin/pgagroal -d will make max_process_title_size bigger.

I don't know if we should care about argv at such level, I don't know if there's a way to get a safe length for the process title and then to use such as max_process_title_size default value.

@fluca1978 fluca1978 added the bug Something isn't working label Feb 25, 2022
@jesperpedersen
Copy link
Collaborator

Note, that this is a PITA area to deal with - see the numerous updates to the function in question.

Make sure that you verify any patches on a harden OS like RHEL 8 or Rocky8 - as they are likely to give you a different result; especially if the string is larger than argv.

@fluca1978
Copy link
Collaborator Author

I'm not expert in this area, but as far as I can tell, there's no way to update the process title in Linux without overwriting environment, while other platforms provide functions (.e.g, BSD setproctitle). I suspect that you are referring to the fact that the hardened systems will complain about a process title changing over its initial size.
I will investigate on this as soon as I've time.

@jesperpedersen
Copy link
Collaborator

Yeah, having setproctitle on Linux would be much easier... Don't break too many keyboards on this though

@jesperpedersen jesperpedersen added enhancement Improvement to an existing feature and removed bug Something isn't working labels Feb 25, 2022
@fluca1978
Copy link
Collaborator Author

Seems however to work on Rocky Linux 8.5. I'm trying to figure out when it is not working.

fluca1978 added a commit to fluca1978/pgagroal that referenced this issue Jun 28, 2022
This is a brute force approach to set the process title with the
appropriate length.
The idea is to compute the size of the process title as it has been
requested, and set it to the computed size.

This works on Rocky Linux release 8.6 (Green Obsidian).

It could break some aggressive security-enforced environments.

See agroal#215
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue Jun 28, 2022
This is a brute force approach to set the process title with the
appropriate length.
The idea is to compute the size of the process title as it has been
requested, and set it to the computed size.

This works on Rocky Linux release 8.6 (Green Obsidian).

It could break some aggressive security-enforced environments.

See agroal#215
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue Jun 29, 2022
This is a brute force approach to set the process title with the
appropriate length.
The idea is to compute the size of the process title as it has been
requested, and set it to the computed size.

This works on Rocky Linux release 8.6 (Green Obsidian).

It could break some aggressive security-enforced environments.

See agroal#215
fluca1978 added a commit to fluca1978/pgagroal that referenced this issue Jun 29, 2022
This commit introduces the function
`pgagroal_set_connection_proc_title()` that builds a process title
with the form:

      user@host:port/database

using in turn the `pgagroal_set_proc_title` function.
The `pgagroal_set_connection_proc_title` function is used only by the
`worker` process stuff and required to identify the primary server (to
get the hostname and port).

Related to agroal#215.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants