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 2154242 - [Regression] Executing bash from a system cronjob ends up executing as rpm_script_t
Summary: [Regression] Executing bash from a system cronjob ends up executing as rpm_sc...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: selinux-policy
Version: 8.7
Hardware: All
OS: Linux
high
urgent
Target Milestone: rc
: 8.8
Assignee: Zdenek Pytela
QA Contact: Milos Malik
Petr Hybl
URL:
Whiteboard:
Depends On:
Blocks: 2173685
TreeView+ depends on / blocked
 
Reported: 2022-12-16 10:50 UTC by Renaud Métrich
Modified: 2023-05-16 11:02 UTC (History)
9 users (show)

Fixed In Version: selinux-policy-3.14.3-117.el8
Doc Type: Bug Fix
Doc Text:
.`crontab` bash scripts no longer execute in incorrect context Previously, a bug fix published in erratum link:https://access.redhat.com/errata/RHBA-2022:7691[RHBA-2022:7691] used too general transition rule. Consequently, a bash script executed from the `crontab` file was executed in the `rpm_script_t` context instead of the `system_cronjob_t` context. With this update, bash scripts are now executed in the correct context.
Clone Of:
: 2173685 (view as bug list)
Environment:
Last Closed: 2023-05-16 09:04:19 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-142695 0 None None None 2022-12-16 10:54:25 UTC
Red Hat Product Errata RHBA-2023:2965 0 None None None 2023-05-16 09:04:37 UTC

Description Renaud Métrich 2022-12-16 10:50:55 UTC
Description of problem:

Since fixing BZ #2118362, we can observe that executing bash from a system cronjob leads to executing in rpm_script_t context, which is not really appropriate.

See below simple reproducer using *runcon* to emulate a system cronjob:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
# runcon system_u:system_r:system_cronjob_t:s0 /bin/bash -c "/bin/bash -c 'sleep 1234'"
^Z

# ps -eafZ | grep sleep
system_u:system_r:rpm_script_t:s0 root      2059    1931  0 11:09 pts/0    00:00:00 sleep 1234
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

The root cause for this is the following (new) transition rule:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
$ sesearch -T -s system_cronjob_t | grep rpm_script_t
type_transition system_cronjob_t shell_exec_t:process rpm_script_t;
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

Faulty Fedora commit is:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
commit cb33da5ae004343f679e5db4e254061291664046
Author: Zdenek Pytela <zpytela>
Date:   Thu Aug 25 20:31:54 2022 +0200

    Allow system_cronjob_t domtrans to rpm_script_t
    
    This permission is required for rpm-like programs executed from system
    cronjobs, e. g. /etc/crontab.
    
    Resolves: rhbz#2118362
---
 policy/modules/contrib/cron.te | 1 +
 1 file changed, 1 insertion(+)

diff --git a/policy/modules/contrib/cron.te b/policy/modules/contrib/cron.te
index c8349c7aa..73d1245df 100644
--- a/policy/modules/contrib/cron.te
+++ b/policy/modules/contrib/cron.te
@@ -544,6 +544,7 @@ ifdef(`distro_redhat',`
 
        # via redirection of standard out.
        optional_policy(`
+               rpm_domtrans_script(system_cronjob_t)
                rpm_manage_log(system_cronjob_t)
        ')
 ')
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

The policy (including Fedora policy) contains the following snippets leading to the issue:
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------
interface(`rpm_domtrans_script',`
        [...]
        # transition to rpm script:
        corecmd_shell_domtrans($1, rpm_script_t)
        [...]
')

interface(`corecmd_shell_domtrans',`
        [...]
        type_transition $1 shell_exec_t:process $2;
')
-------- 8< ---------------- 8< ---------------- 8< ---------------- 8< --------

These interfaces, when applied to `system_cronjob_t`, make all `shell_exec_t` processes (typically shells, including `bash`), to transition to `rpm_script_t` if process was executing as `system_cronjob_t`, which is your case here.

This is hence clearly a bug, the rule `rpm_domtrans_script(system_cronjob_t)` is wrong, it should likely be `rpm_domtrans(system_cronjob_t)`, which tells to transition when `/usr/bin/rpm` binary (`rpm_exec_t`) is executed from a system cron.


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

selinux-policy-3.14.3-108.el8.noarch

How reproducible:

Always, see above.

Comment 1 Renaud Métrich 2022-12-16 12:03:36 UTC
I've created the BZ as Urgent because there is no workaround: it's not possible to add another transition rule to force staying as system_cronjob_t.

Comment 20 errata-xmlrpc 2023-05-16 09:04:19 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 (selinux-policy 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-2023:2965


Note You need to log in before you can comment on or make changes to this bug.