Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2081688

Summary: Refresh of OSPP SCAP rules that disable core dumps
Product: Red Hat Enterprise Linux 9 Reporter: Jan Pazdziora (Red Hat) <jpazdziora>
Component: scap-security-guideAssignee: Vojtech Polasek <vpolasek>
Status: CLOSED ERRATA QA Contact: Milan Lysonek <mlysonek>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.0CC: ggasparb, jjaburek, jpazdziora, matyc, mhaicman, mlysonek, mmarhefk, openscap-maint, vpolasek
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: scap-security-guide-0.1.63-5.el9 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 2117612 (view as bug list) Environment:
Last Closed: 2022-11-15 10:25:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2117612    

Description Jan Pazdziora (Red Hat) 2022-05-04 11:38:33 UTC
Description of problem:

The current rules in the OSPP SCAP profile that deal with disabling core dumps are:

    - disable_users_coredumps
    - sysctl_kernel_core_pattern
    - coredump_disable_storage
    - coredump_disable_backtraces
    - service_systemd-coredump_disabled

They all head in the direction of making sure core dumps do not land on disk as they can contain sensitive data of the application being terminated.

However, they seem to be rather redundant, so should admin have a need to at least temporarily enable core dumps again for example for debugging purposes, it might be harder than necessary.

In addition, the current sysctl_kernel_core_pattern sets kernel.core_pattern to |/bin/false. That however means that the WCOREDUMP bit that waitpid gets from kernel gets always set because kernel does not wait for exit status of the dumping process to indicate if core file was created or not.

The net effect is that for example shell will emit message

  Segmentation fault (core dumped)

even if no core was in fact dumped.

The core(5) man page says:

    There are various circumstances in which a core dump file is not produced:
    [...]

    * /proc/sys/kernel/core_pattern is empty and /proc/sys/kernel/core_uses_pid
      contains the value 0. (These files are  described below.) Note that if
      /proc/sys/kernel/core_pattern is empty and /proc/sys/kernel/core_uses_pid
      contains the value 1, core dump files will have names of the form .pid,
      and such files are hidden unless one uses the ls(1) -a option.

The kernel.core_pattern='' + kernel.core_uses_pid=0 is the mechanism that we'd
like to be used by the RHEL 9 OSPP SCAP profile.

Version-Release number of selected component (if applicable):

scap-security-guide-0.1.60-6.el9_0

How reproducible:

Deterministic.

Steps to Reproduce:
1. Start with stock unremediated RHEL 9 installation.
2. Run the following commands to check we start with the default values:
   # grep 'hard.*core' /etc/security/limits.conf
   # cat /proc/sys/kernel/core_pattern
   # cat /proc/sys/kernel/core_uses_pid
   # grep Storage /etc/systemd/coredump.conf
   # grep ProcessSizeMax /etc/systemd/coredump.conf
   # systemctl is-enabled systemd-coredump.socket
3. Remediate with the OSPP SCAP profile:
   # oscap xccdf eval --remediate --profile xccdf_org.ssgproject.content_profile_ospp /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml
4. Rerun commands from 2 to see what the OSPP SCAP profile changed.

Actual results:

2.
# grep 'hard.*core' /etc/security/limits.conf

# cat /proc/sys/kernel/core_pattern
|/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h

# cat /proc/sys/kernel/core_uses_pid
1

# grep Storage /etc/systemd/coredump.conf
#Storage=external

# grep ProcessSizeMax /etc/systemd/coredump.conf
#ProcessSizeMax=2G

# systemctl is-enabled systemd-coredump.socket
static

3. Some rules passed, some failed, some errored.

4.
# grep 'hard.*core' /etc/security/limits.conf
*     hard   core    0

# cat /proc/sys/kernel/core_pattern
|/bin/false

# cat /proc/sys/kernel/core_uses_pid
1

# grep Storage /etc/systemd/coredump.conf
#Storage=external
Storage=none

# grep ProcessSizeMax /etc/systemd/coredump.conf
#ProcessSizeMax=2G
ProcessSizeMax=0

# systemctl is-enabled systemd-coredump.socket
masked

Expected results:

2. the same.

3. Slightly different set of rules run.

4.
# grep 'hard.*core' /etc/security/limits.conf

# cat /proc/sys/kernel/core_pattern


# cat /proc/sys/kernel/core_uses_pid
0

# grep Storage /etc/systemd/coredump.conf
#Storage=external

# grep ProcessSizeMax /etc/systemd/coredump.conf
#ProcessSizeMax=2G

# systemctl is-enabled systemd-coredump.socket
masked

Additional info:

Of the current five SCAP coredump related rules, we'd like the following changes to be done to RHEL 9 OSPP SCAP profile:

Remove disable_users_coredumps as there is no need to set the hard limit if we are then stopping the core files from being created anyway by other means.

Remove coredump_disable_storage and coredump_disable_backtraces as systemd-coredump is not used anyway.

Either change behaviour of sysctl_kernel_core_pattern or create different rule to set kernel.core_pattern to empty string, rather than |/bin/false.

When setting kernel.core_pattern to empty string, it is important to also set kernel.core_uses_pid to value 0. Otherwise kernel would be creating core files .<pid> in current directories of terminated processes. One possibility would be to add this to the sysctl_kernel_core_pattern when setting kernel.core_pattern to empty string. Another possibility would be a separate rule but we really want to make sure this is always set to 0 when kernel.core_pattern is set to empty -- can one rule require other rule to be always checked / remediated?

The service_systemd-coredump_disabled should stay as is since disabling |/usr/lib/systemd/systemd-coredump makes that .socket and .service not needed.

The benefit of using kernel.core_pattern='' + kernel.core_uses_pid=0 is that kernel correctly reports in the WCOREDUMP bit that the core file was not created, so bash does not confuse people with that "(core dumped)" message.

Comment 3 Vojtech Polasek 2022-08-03 09:24:38 UTC
Hello Jan,
just one question concerning the need to check and remediate rules syscl_kernel_core_pattern and sysctl_kernel_core_uses_pid together. We can specifya requirement stating that the rule X requires rule Y to be selected, othervise the rule X will not be evaluated. We will of course put both rules into the OSPP profile. So if we state that sysctl_kernel_core_pattern requires sysctl_kernel_core_uses_pid and someone uses tailoring to remove sysctl_kernel_core_uses_pid, none of the rules will be evaluated. Is this acceptable?

Comment 4 Jan Pazdziora (Red Hat) 2022-08-03 09:36:20 UTC
That sounds perfect.

Comment 5 Vojtech Polasek 2022-08-04 07:39:13 UTC
For the record, after further discussions, it was decided not to enforce the requirement between syscl_kernel_core_uses_pid and syscl_kernel_core_pattern. syscl_kernel_core_pattern might be in some cases used without syscl_kernel_core_uses_pid and requirement can't be specified on profile base.

Comment 6 Vojtech Polasek 2022-08-05 11:38:24 UTC
So, here is the final state. Due to problems encountered, the final state is:
- there is a new rule sysctl_kernel_core_pattern_empty_string which replaces sysctl:kernel_core_pattern in RHEL9 OSPP. This rule sets kernel.core_pattern to ''.
- there is another new rule sysctl_kernel_core_uses_pid, added to RHEL9 OSPP profile as well. The rule sysctl_kernel_core_pattern_empty_string requires rule sysctl_kernel_core_uses_pid. Moreover, sysctl_kernel_core_pattern_empty_string conflicts with sysctl_kernel_core_pattern and vice versa, since both rules modify the same config option.

Comment 7 Jan Pazdziora (Red Hat) 2022-08-05 11:54:20 UTC
Sounds like a good plan. Thank you.

Comment 8 Vojtech Polasek 2022-08-10 06:40:09 UTC
Fixed upstream: https://github.com/ComplianceAsCode/content/pull/9285

Comment 18 Jiri Jaburek 2022-08-17 16:21:01 UTC
This this is still ON_QA, I'm adding it here instead of filing a new BZ.

The

    sysctl_kernel_core_pattern_empty_string

rule does what it sets out to do, ensuring that /proc/sys/kernel/core_pattern has '' :

    {{{ ocil_sysctl_option_value(sysctl="kernel.core_pattern", value="''") }}}


This, however, does not disable coredumps:

# ulimit -c unlimited

# ls
segfault  segfault.c

# grep '' /proc/sys/kernel/core_*
/proc/sys/kernel/core_pattern:''
/proc/sys/kernel/core_pipe_limit:16
/proc/sys/kernel/core_uses_pid:0

# ./segfault 
Segmentation fault (core dumped)

# ls
"''"   segfault   segfault.c


(The coredump is written to a file named '' )

For the disablement to work, /proc/sys/kernel/core_pattern needs to actually be empty, as in - zero bytes of text, plus a newline.

A.k.a. the equivalent of

echo > /proc/sys/kernel/core_pattern

Comment 19 Jan Pazdziora (Red Hat) 2022-08-18 13:51:57 UTC
Matus, per comment 18 this bugzilla FAILS_QA. Would you like to update the status accordingly to bring this to engineering's radar, or should I  move it back to ASSIGNED?

Comment 20 Matus Marhefka 2022-08-18 13:57:46 UTC
Yes, we are already looking into it.

Comment 22 Jiri Jaburek 2022-08-18 14:04:55 UTC
For the record, we had a chat with Gabriel Gaspar Becker on gchat where we discovered that sysctl (procps-ng) doesn't support setting empty values on RHEL-9.0 (and older), but does on RHEL-9.1+

# sysctl -p
sysctl: /etc/sysctl.conf(11): invalid syntax, continuing...

So if ComplianceAsCode upstream maintains only one version for RHEL-9 overall, we have to either

 * go back to |/bin/false

 * unify the implementation details under a rule that simply disables kernel coredumps,
   checking for multiple approaches, and where the remediation may change across RHEL-9 minors

Comment 24 Vojtech Polasek 2022-08-23 15:14:52 UTC
In the end, it was decided to go back to the |/bin/false approach, effectively switching back to the rule syscl_kernel_core_pattern.
https://github.com/ComplianceAsCode/content/pull/9384

Comment 25 Jan Pazdziora (Red Hat) 2022-08-24 08:46:04 UTC
I object to the decision in comment 24.

In RHEL 9.1, sysctl -p and sysctl --system work just fine:

# sysctl kernel.core_pattern
kernel.core_pattern = /usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
# echo kernel.core_pattern= > /etc/sysctl.d/core_pattern.conf
# sysctl --system
[...]
# sysctl kernel.core_pattern
kernel.core_pattern = 

So there isn't any reason not to go with the empty core_pattern (and empty string) on RHEL 9.1+.

For RHEL 9.0 (bug 2117612), the same will work if fix for bug 2052536 gets backported to RHEL 9.0.z, which I talked about to procps-ng maintainer already.

In general, the question is if the SCAP rules should use and promote sysctl --system rather than invoking /usr/lib/systemd/systemd-sysctl. After all, ExecStart=/usr/lib/systemd/systemd-sysctl is what /usr/lib/systemd/system/systemd-sysctl.service defines on RHEL 8+ so that's the mechanism which will be used after reboot to set the kernel values.

Comment 26 Jan Pazdziora (Red Hat) 2022-08-24 09:52:10 UTC
Vojta mentioned that the command used to actually set the value in runtime is

 /sbin/sysctl -q -n -w

which I see in https://github.com/ComplianceAsCode/content/blob/master/shared/templates/sysctl/bash.template.

But if that's the case, there's actually no problem with the empty value at all because it seems to be accepted even on RHEL 9.0 just fine:

# sysctl kernel.core_pattern
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
# sysctl -q -n -w kernel.core_pattern=
# sysctl kernel.core_pattern
kernel.core_pattern = 
#

So can we go back to the question of -- what would

    {{{ ocil_sysctl_option_value(sysctl="kernel.core_pattern", value="") }}}

instead of the current

    {{{ ocil_sysctl_option_value(sysctl="kernel.core_pattern", value="''") }}}

actually break, on RHEL 9.1 and on RHEL 9.0?

Comment 27 Jiri Jaburek 2022-08-24 11:19:52 UTC
(In reply to Jan Pazdziora from comment #26)
> Vojta mentioned that the command used to actually set the value in runtime is
> 
>  /sbin/sysctl -q -n -w
> 
> which I see in
> https://github.com/ComplianceAsCode/content/blob/master/shared/templates/
> sysctl/bash.template.
> 
> But if that's the case, there's actually no problem with the empty value at
> all because it seems to be accepted even on RHEL 9.0 just fine:
> 
> # sysctl kernel.core_pattern
> kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h
> # sysctl -q -n -w kernel.core_pattern=
> # sysctl kernel.core_pattern
> kernel.core_pattern = 
> #
> 
> So can we go back to the question of -- what would
> 
>     {{{ ocil_sysctl_option_value(sysctl="kernel.core_pattern", value="") }}}
> 
> instead of the current
> 
>     {{{ ocil_sysctl_option_value(sysctl="kernel.core_pattern", value="''")
> }}}
> 
> actually break, on RHEL 9.1 and on RHEL 9.0?


The problem isn't the runtime on-CLI setting, it's the sysctl.conf setting.

# grep -n core_pattern /etc/sysctl.conf
13:kernel.core_pattern =

# sysctl -q -n -p
sysctl: /etc/sysctl.conf(13): invalid syntax, continuing...

It's true that systemd-sysctl is its own independent implementation that *does* support empty strings, so it would /technically/ work, ... but it would also break 'sysctl -p' for any admins who would want to modify sysctl.conf during runtime.

It's true that, if the SCAP content supports it, we could use the empty-string on 9.1+ and use something else for 9.0. Actually, we could even use "''", because the default core limit is 0, even on clean RHEL, probably because systemd-coredumpd is handling it by default, so there was no reason for users to generate coredumps. However segfaulting services /could/ then generate dumps.

Pulling in (and waiting for) another 9.0.z package for a minor change like this might not be worth it if the only downside for '|/bin/false' is that it prints "(core dumped)".

Comment 36 Matěj Týč 2022-08-26 08:49:02 UTC
The PR https://github.com/ComplianceAsCode/content/pull/9396 that we believe fixes the issue has been merged.

Comment 40 errata-xmlrpc 2022-11-15 10:25:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (scap-security-guide bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:8131