8 Commits

Author SHA1 Message Date
Gerald Schaefer
42eba67268 mon_procd: Fix possible static buffer overflow
The command line length value is not properly checked and limited to the
documented 1024 bytes, even though a MAX_CMD_LEN is already defined but
not used.

With this, an overflow of the static char mon_record[] buffer is possible
in read_cmdline(), corrupting adjacent .bss data. The data is sanitized to
printable ASCII bytes, but in theory a crash of the mon_procd daemon could
be possible.

Fix it by adding a check and truncation similar to the other restricted
fields like e.g. ruser_len or cmd_len.

Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2026-07-20 15:25:59 +02:00
Sertonix
10d72caac0 Add missing includes
include/lib/util_sys.h: missing dev_t
ziomon/ziomon_msg_tools.h: missing time_t
zkey/keystore.c: missing open
mon_tools/mon_procd.c: missing gettimeofday

Fixes some build failures on musl libc

Github-ID: https://github.com/ibm-s390-linux/s390-tools/pull/193
Signed-off-by: Sertonix <sertonix@posteo.net>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Ingo Franzki <ifranzki@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2025-12-11 15:46:05 +01:00
Dan Horák
71b0460d11 mon_tools: drop an always-true condition
The d_name member of struct dirent is a statically allocated string,
thus it's always non-NULL.

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/137
Signed-off-by: Dan Horák <dan@danny.cz>
Acked-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-07-21 15:57:17 +02:00
Dan Horák
ff62f4d425 mon_tools: fix user counting condition
The ut_user (aka ut_name) member of struct utmp is a statically
allocated string, thus always non-NULL.

GitHub-ID: https://github.com/ibm-s390-linux/s390-tools/pull/137
Signed-off-by: Dan Horák <dan@danny.cz>
Acked-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2022-07-21 15:57:17 +02:00
Dan Horák
847f16f632 Switch to using /run directory instead of the legacy /var/run
Closes: https://github.com/ibm-s390-tools/s390-tools/pull/53
Signed-off-by: Dan Horák <dan@danny.cz>
Acked-by: Sa Liu <saliu@de.ibm.com>
Acked-by: Harald Freudenberger <freude@linux.ibm.com>
Acked-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2019-02-11 12:33:56 +01:00
Gerald Schaefer
58ecf1f363 mon_procd: fix parsing of /proc/<pid>/stat
The output of /proc/<pid>/stat will show the process name in parentheses.
The parsing code in read_stat() tries to filter out the parentheses, which
will go wrong when the process name itself also contains parentheses, e.g.
in an output like this: "2421 ((sd-pam)) S 2420 2420 2420 ..."

In this case, the first closing parentheses will be taken as end marker,
and the sscanf() on the remaining string will silently fail, leaving its
values in uninitialized state and producing wrong data.

Fix this by using strrchr() instead of strchr() to find the last closing
parentheses. Also add return value checking for sscanf() and initialize the
values to 0.

Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
2018-07-04 13:10:20 +02:00
Gerald Schaefer
780133f825 mon_tools: Improve systemctl start error handling
This fixes the same issue as in commit 82c8148983 ("cpuplugd: Improve
systemctl start error handling") for mon_tools (mon_procd and mon_fsstatd).

Currently "systemctl start mon_procd/fsstatd" does not report any errors
in case the startup fails.

Example (with mon_procd):

 (change interval in /etc/sysconfig/mon_procd to an invalid value "abc")
 # systemctl start mon_procd

The reason is that for type=simple systemd forks/execs mon_procd and if
that is successful immediately returns. There is no way to find out if the
initial startup fails.

Fix this by using type=fork and running the process in the background. In
this case systemd waits until the initial process returns.

In addition use PIDFile and ensure that the pid file is already available
when the initial process returns. To achieve this, use startup
synchronization via pipe. Without that systemd would print the following
warning:

systemd[1]: mon_procd.service: PID file /var/run/mon_procd.pid not readable
            (yet?) after start: No such file or directory

With this patch, an early startup error like in the example above, is now
reported correctly in "systemctl start":

 # systemctl start mon_procd
   Job for mon_procd.service failed because the control process exited...
   See "systemctl status mon_procd.service" and "journalctl -xe" for ...
 # journalctl -xe | grep mon_procd
   mon_procd[3184]: Error: Invalid interval (needs to be greater than 0)

Signed-off-by: Gerald Schaefer <gerald.schaefer@de.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-11-20 20:33:17 +01:00
Michael Holzheu
b627b8d8e1 Initial s390-tools-2.0.0 import
This commit is based on the s390-tools-1.39.0 version.

Changes on top of s390-tools-1.39.0:

 - Add MIT license to all source files
 - Add LICENSE file
 - Transform REAMDE to README.md (markdown)
 - Add AUTHORS.md file
 - Add CONTRIBUTING.md file
 - Move changelog from README to CHANGELOG.md file

Reviewed-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
2017-08-21 10:55:40 +02:00