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 1320181

Summary: Race condition in rpm file deployment when updating an existing file
Product: Red Hat Enterprise Linux 7 Reporter: Karel Srot <ksrot>
Component: rpmAssignee: Florian Festi <ffesti>
Status: CLOSED ERRATA QA Contact: Karel Srot <ksrot>
Severity: medium Docs Contact:
Priority: high    
Version: 7.2   
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: rpm-4.11.3-18.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1264052 Environment:
Last Closed: 2016-11-04 04:38:58 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:

Description Karel Srot 2016-03-22 14:14:22 UTC
present on rhel-7 too, rpm-4.11.3-17.el7

+++ This bug was initially created as a clone of Bug #1264052 +++

Description of problem:
When rpm replaces an existing file, the new file is deployed to a temporary filename, then renamed to the correct filename, then permissions are set on the file. This leads to a moment where the old file no longer exists and the new file cannot be read as has 000 effective permissions.

this appears to have been introduced with code changes made in relation to CVE-2013-6435 in that the temporary files are now created with 000 permissions.

Version-Release number of selected component (if applicable):
rpm-4.8.0-47.el6.x86_64


How reproducible:
always


Steps to Reproduce:
upgrade an rpm which deploys a file as part of the payload. Whist the rpm is installing stat the file that will be replaced, see snipet of output below achieved using a simple bash loop ls -li on the testfile.

1442324731 140344 ---------- 1 root root 128843776 Sep 15 13:45 /etc/testfile.cdb;55f820f8
1442324731 140342 -rw-r--r-- 1 root root 130459449 Sep 14 13:02 /etc/testfile.cdb
1442324731 140344 ---------- 1 root root 129310720 Sep 15 13:45 /etc/testfile.cdb;55f820f8
1442324731 140342 -rw-r--r-- 1 root root 130459449 Sep 14 13:02 /etc/testfile.cdb
1442324731 140344 ---------- 1 root root 129826816 Sep 15 13:45 /etc/testfile.cdb;55f820f8
1442324731 140342 -rw-r--r-- 1 root root 130459449 Sep 14 13:02 /etc/testfile.cdb
1442324731 140344 ---------- 1 root root 130351104 Sep 15 13:45 /etc/testfile.cdb;55f820f8
1442324731 140344 ---------- 1 root root 130774422 Sep 15 13:45 /etc/testfile.cdb
1442324733 140344 -rw-r--r-- 1 root root 130774422 Sep 14 13:52 /etc/testfile.cdb
1442324733 140344 -rw-r--r-- 1 root root 130774422 Sep 14 13:52 /etc/testfile.cdb
1442324733 140344 -rw-r--r-- 1 root root 130774422 Sep 14 13:52 /etc/testfile.cdb


Additional info:
This has been tested on centos 6 with rpm 4.8.x and centos 7 with rpm 4.11.1 and occurs on both.

the logic behaviour was identified from examining lib/fsm.c in the rpm source code.

 /* XXX Special case /dev/log, which shouldn't be packaged anyways */
        if (!S_ISSOCK(st->st_mode) && !IS_DEV_LOG(fsm->path)) {
            /* Rename temporary to final file name. */
            if (!S_ISDIR(st->st_mode) &&
                (fsm->subdir || fsm->suffix || fsm->nsuffix))
            {
                fsm->opath = fsm->path;
                fsm->path = fsmFsPath(fsm, st, NULL, fsm->nsuffix);
                rc = fsmNext(fsm, FSM_RENAME);
                if (!rc && fsm->nsuffix) {
                    char * opath = fsmFsPath(fsm, st, NULL, NULL);
                    rpmlog(RPMLOG_WARNING, _("%s created as %s\n"),
                                (opath ? opath : ""),
                                (fsm->path ? fsm->path : ""));
                    opath = _free(opath);
                }
                fsm->opath = _constfree(fsm->opath);
            }
            /*
             * Set file security context (if not disabled).
             */
            if (!rc && !getuid()) {
                rc = fsmMapFContext(fsm);
                if (!rc) {
                    rc = fsmNext(fsm, FSM_LSETFCON);
                    freecon(fsm->fcontext);
                }
                fsm->fcontext = NULL;
            }
            if (S_ISLNK(st->st_mode)) {
                if (!rc && !getuid())
                    rc = fsmNext(fsm, FSM_LCHOWN);
            } else {
                if (!rc && !getuid())
                    rc = fsmNext(fsm, FSM_CHOWN);
                if (!rc)
                    rc = fsmNext(fsm, FSM_CHMOD);
                if (!rc) {
                    time_t mtime = st->st_mtime;
                    rpmfi fi = fsmGetFi(fsm);
                    st->st_mtime = rpmfiFMtimeIndex(fi, fsm->ix);
                    rc = fsmNext(fsm, FSM_UTIME);
                    st->st_mtime = mtime;
                }
#if WITH_CAP
                if (!rc && !S_ISDIR(st->st_mode) && !getuid()) {
                    rc = fsmMapFCaps(fsm);
                    if (!rc && fsm->fcaps) {
                        rc = fsmNext(fsm, FSM_SETCAP);
                        cap_free(fsm->fcaps);
                    }
                    fsm->fcaps = NULL;
                }
#endif /* WITH_CAP */
            }
        }

Comment 5 errata-xmlrpc 2016-11-04 04:38:58 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, 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://rhn.redhat.com/errata/RHBA-2016-2359.html