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 1696449 - /usr/bin/run-parts has a fatal programming error which can cause cron to hang perpetually
Summary: /usr/bin/run-parts has a fatal programming error which can cause cron to hang...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: crontabs
Version: 8.1
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Ondřej Pohořelský
QA Contact: Jan Houska
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-04-04 21:01 UTC by Kevin Buchs
Modified: 2024-03-25 15:16 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-18 15:08:26 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2021:1699 0 None None None 2021-05-18 15:08:32 UTC

Description Kevin Buchs 2019-04-04 21:01:26 UTC
Description of problem:

/usr/bin/run-parts has a fatal programming error which can cause cron to hang perpetually. This run-parts script is part of the crontabs package. It is used to execute the cron.hourly, cron.daily, etc. actions. 


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

I have seen this reproduced on RHEL 6 and 7, CentOS and Amazon Linux too. https://bugs.centos.org/view.php?id=15977

How reproducible:

Just make use of cron.hourly, cron.daily, etc. and you might hit this problem. It is not reproducible at will because it is a race condition.

Actual results:

Cron hangs. Completes no further work.

Expected results:

Cron runs normally.

Additional info:

*_Problem:_*
run-parts is a shell script which contains this pipeline at its heart (where $i is the command from, e.g. "/etc/cron.daily/logrotate", to be executed):
{code}
$i 2>&1 | awk -v "progname=$i" \
                              'progname {
                                   print progname ":\n"
                                   progname="";
                               }
                               { print; }'
{code}

That awk script is horrendous example of programming. It defines a variable *progname* on the command line, e.g. logrotate. The script also defines a function of the same name. In that AWK function, the AWK function is deleted. That is a race condition. 

The purpose of this code is to echo the progname initially once and then from then on just echo its input. To keep it as an awk script, it should be the following:
{code}
$i 2>&1 | awk -v "progname=$i" \
                              'BEGIN { print progname ":\n" }
                               { print; }'
{code}

However, there is no need to add the additional burden of awk having to echo each line. This would work just fine:
{code}
echo -e "$i:\n"
$i
{code}

I posted this in regard to Amazon Linux in the appropriate AWS forum, but got no response. I know they should have escalated it upstream.

Here is what the processes look like when the race condition is hit:

ps axwu|grep cron
root 1793 0.0 0.0 116912 1188 ? Ss 2018 3:21 crond
root 12003 0.0 0.0 103328 860 pts/2 S+ 13:33 0:00 grep cron
root 14361 0.0 0.0 19052 948 ? Ss 2018 0:00 /usr/sbin/anacron -s
root 16875 0.0 0.0 106112 1268 ? SN 2018 0:00 /bin/bash /usr/bin/run-parts /etc/cron.daily
root 16887 0.0 0.0 105972 948 ? SN 2018 0:00 awk -v progname=/etc/cron.daily/logrotate progname {????? print progname ":\n"????? progname="";???? }???? { print; }

The awk process never finishes (it is trying to find the function it was trying to run, I guess it gets lost when the function is deleted. Today is April 2, 2019 and this has been hung since Dec 21, 2018. 

The process of running awk seems to have gotten nowhere:

# ps -p $pid H -www -o pid,cputime,state,lstart,time,etime,cmd
  PID TIME S STARTED TIME ELAPSED CMD
16887 00:00:00 S Fri Dec 21 14:13:01 2018 00:00:00 101-22:45:16 awk -v progname=/etc/cron.daily/logrotate progname {????? print progname ":\n"????? progname="";???? }???? { print; }


Previously, I think I joined the awk process with debugger and found out awk was not executing anything.

Comment 2 Petr Viktorin (pviktori) 2019-04-09 11:46:26 UTC
Hello,
This is the right place to report the bug. Thank you! And thank you again for the detailed report!

Marcel is on vacation now, and the issue doesn't look time-critical, so it will take some time before we get to it. But it's in the queue.
Please let us know if you think it should be prioritized.

Comment 3 Kevin Buchs 2019-04-09 12:35:17 UTC
Petr,

Thanks for the response. In terms of priority, since this has been a long standing issue, even an immediate fix won't result in a change seen for a while, especially in RHEL derivatives. The issue results in cron hanging, which I believe most folks would not expect to happen. The criticality certainly depends on the user, but I can imagine some serious impacts. Now, I usually factor in the level of effort required in my thinking on prioritization. Something easy to fix, as this is (cause I gave you the fix), may be done before other tasks because it is fast to do. Those are my thoughts. Waiting for Marcel to return is likely to be a good choice.

Comment 4 Marcel Plch 2019-05-28 15:09:15 UTC
I have reported this upstream with a fix, after this has been merged, or if upstream has come with a better solution, I will resolve this in RHEL too.
https://github.com/cronie-crond/crontabs/pull/1

Comment 5 Marcel Plch 2019-07-01 12:05:41 UTC
There is a slightly different behavior with the fix after all.
However, upstream has fixed this with a safer sed command to eliminate the race condition.

See: https://github.com/cronie-crond/crontabs/commit/9e74f2ddcb28ff3e2b0fbef08c7acdb9b6172e95

Comment 6 Marcel Plch 2019-08-28 10:38:03 UTC
Given that this is a long-lasting issue with no good way to reproduce, this bug has been evaluated not to be fixed in RHEL-7 as later releases generally accept less changes.
However, I am not closing this bug. It will still be considered for RHEL-8.

Comment 14 Jan Houska 2021-01-13 13:51:47 UTC
VERIFIED  as SanityOnly


version
crontabs-1.11-17.20190603git.el8


contains  changes proposed in fix (https://github.com/cronie-crond/crontabs/commit/9e74f2ddcb28ff3e2b0fbef08c7acdb9b6172e95).

Comment 16 errata-xmlrpc 2021-05-18 15:08:26 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 (crontabs 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-2021:1699


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