From ee0449fd7a5d4755d133cf0ddba8ddadc07f057e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 May 2018 16:59:21 +0200 Subject: [PATCH 1/2] coredump: properly treat Storage=none as disabled storage Also don't attempt to create /var/lib/systemd/coredump if storage limit is set to 0 and coredump processing is disabled. --- src/coredump/coredump.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 423a1c21a4..c1f396b1ac 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -141,7 +141,12 @@ static int parse_config(void) { } static inline uint64_t storage_size_max(void) { - return arg_storage == COREDUMP_STORAGE_EXTERNAL ? arg_external_size_max : arg_journal_size_max; + if (arg_storage == COREDUMP_STORAGE_EXTERNAL) + return arg_external_size_max; + if (arg_storage == COREDUMP_STORAGE_JOURNAL) + return arg_journal_size_max; + assert(arg_storage == COREDUMP_STORAGE_NONE); + return 0; } static int fix_acl(int fd, uid_t uid) { @@ -323,7 +328,7 @@ static int save_external_coredump( _cleanup_free_ char *fn = NULL, *tmp = NULL; _cleanup_close_ int fd = -1; - uint64_t rlimit, max_size; + uint64_t rlimit, process_limit, max_size; struct stat st; uid_t uid; int r; @@ -350,8 +355,14 @@ static int save_external_coredump( return -EBADSLT; } + process_limit = MAX(arg_process_size_max, storage_size_max()); + if (process_limit == 0) { + log_debug("Limits for coredump processing and storage are both 0, not dumping core."); + return -EBADSLT; + } + /* Never store more than the process configured, or than we actually shall keep or process */ - max_size = MIN(rlimit, MAX(arg_process_size_max, storage_size_max())); + max_size = MIN(rlimit, process_limit); r = make_filename(context, &fn); if (r < 0) From c8e053fbe4e7182d88e25477dced2c717f33fdfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 17 May 2018 17:08:31 +0200 Subject: [PATCH 2/2] man: fix ProcessSizeMax= description, describe how to disable coredumps What the man page said was different than what the code did. save_external_coredump() will store the core temporarily for backtrace generation, and will delete if afterwards if it is too large. So to disable processing, it's necessary to both set Storage=none/Storage=journal+JournalSizeMax=0/Storage=external+ExternalSizeMax=0 and ProcessSizeMax=0. This updates the man page to reflect the code. The man pages are extended to describe that Storage=none + ProcessSizeMax=0 is the simplest way to disable coredump processing. All the storage and processing options make this quite complicated, so let's add a copy-and-pasteable example of how to disable coredump. Doing it through coredump.conf has the advantage that we still log, and the effect is immediate, unlike masking the sysconf file. Fixes #8788. --- man/coredump.conf.xml | 10 +++++++--- man/systemd-coredump.xml | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/man/coredump.conf.xml b/man/coredump.conf.xml index 048bbc3637..49debb219a 100644 --- a/man/coredump.conf.xml +++ b/man/coredump.conf.xml @@ -74,7 +74,7 @@ Controls where to store cores. One of none, external, and journal. When - none, the core dumps will be logged (including the backtrace if + none, the core dumps may be logged (including the backtrace if possible), but not stored permanently. When external (the default), cores will be stored in /var/lib/systemd/coredump/. When journal, cores will be stored in the journal and rotated @@ -101,8 +101,12 @@ The maximum size in bytes of a core which will be processed. Core dumps exceeding this size - will be logged, but the backtrace will not be generated - and the core will not be stored. + may be stored, but the backtrace will not be generated. + + + Setting Storage=none and ProcessSizeMax=0 + disables all coredump handling except for a log entry. + diff --git a/man/systemd-coredump.xml b/man/systemd-coredump.xml index 6c3078143f..6fba19c223 100644 --- a/man/systemd-coredump.xml +++ b/man/systemd-coredump.xml @@ -128,6 +128,16 @@ core dumps and files can be set in files /etc/systemd/coredump.conf and snippets mentioned above. In addition the storage time of core dump files is restricted by systemd-tmpfiles, corresponding settings are by default in /usr/lib/tmpfiles.d/systemd.conf. + + + Disabling coredump processing + + To disable potentially resource-intensive processing by systemd-coredump, + set Storage=none +ProcessSizeMax=0 in + coredump.conf5. + +