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 2026289 - Crond runs into segfault when getdtablesize() returns a huge value.
Summary: Crond runs into segfault when getdtablesize() returns a huge value.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: cronie
Version: 7.9
Hardware: Unspecified
OS: Unspecified
urgent
high
Target Milestone: rc
: ---
Assignee: Jan Staněk
QA Contact: Jan Houska
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-11-24 09:52 UTC by Flos Qi Guo
Modified: 2022-01-11 17:41 UTC (History)
8 users (show)

Fixed In Version: cronie-1.4.11-24.el7_9
Doc Type: Bug Fix
Doc Text:
Cause: crond determined the amount of memory needed for some task based on the highest file descriptor number in use. In containers, this number could reach very high values. Consequence: In containers, crond attempted to sometimes allocate several gigabytes of memory that was not actually needed; when that failed due to system limits or limitations, the program crashed. Fix: An upstream change limiting the allocated memory size to sane(r) numbers was backported to this version of cronie. Result: The crond no longer tries to allocate so much memory that it crashes, even in containers.
Clone Of:
Environment:
Last Closed: 2022-01-11 17:35:52 UTC
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-103816 0 None None None 2021-11-24 09:53:45 UTC
Red Hat Product Errata RHBA-2022:0067 0 None None None 2022-01-11 17:35:54 UTC

Description Flos Qi Guo 2021-11-24 09:52:38 UTC
> Description of problem:
Crond eats memory and runs into segfault at last if getdtablesize() returns a huge value.

> Version-Release number of selected component (if applicable):
cronie-1.4.11-23.el7.x86_64

> How reproducible:
Frequently

> Steps to Reproduce:
1. On RHEL7.9
2. Set the nofile to 2147483584:

$ cat etc/security/limits.conf | grep nof | grep myuser
myuser            soft    nofile         2147483584
myuser            hard    nofile         2147483584

3. Set cron job with 'myuser'

> Actual results:
Crond runs into segfault from time to time.

> Expected results:
No segfault.

> Additional info:
Upstream fix can prevent allocating lots of memory:
-------------8< -------------8< -------------8< -------------
commit 584911514ce6aa2f16e1d79431bac816ea62cb2c
Author: Tomas Mraz <tmraz>
Date:   Mon Jul 8 10:57:52 2019 +0200

    getdtablesize() can return very high values in containers
    
    Avoid closing hundreds of millions descriptors or allocating
    huge arrays by maxing the fd number to MAX_CLOSE_FD.
    See rhbz#1723106

...
 /*
  * Because crontab/at files may be owned by their respective users we
  * take extreme care in opening them.  If the OS lacks the O_NOFOLLOW
diff --git a/src/popen.c b/src/popen.c
index badddb6..4397264 100644
--- a/src/popen.c
+++ b/src/popen.c
@@ -81,12 +81,19 @@ FILE *cron_popen(char *program, const char *type, struct passwd *pw, char **jobe
        if (!pids) {
                if ((fds = getdtablesize()) <= 0)
                        return (NULL);
+               if (fds > MAX_CLOSE_FD)
+                       fds = MAX_CLOSE_FD; /* avoid allocating too much memory */
                if (!(pids = (PID_T *) malloc((u_int) ((size_t)fds * sizeof (PID_T)))))
                        return (NULL);
                memset((char *) pids, 0, (size_t)fds * sizeof (PID_T));
        }
        if (pipe(pdes) < 0)
                return (NULL);
...
-------------8< -------------8< -------------8< -------------

Comment 19 errata-xmlrpc 2022-01-11 17:35:52 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 (cronie 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:0067


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