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 1542180 - rsync: fails to start if the current directory is unreachable
Summary: rsync: fails to start if the current directory is unreachable
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: rsync
Version: 7.5-Alt
Hardware: Unspecified
OS: Unspecified
high
urgent
Target Milestone: rc
: ---
Assignee: Pavel Zhukov
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks: 1534635
TreeView+ depends on / blocked
 
Reported: 2018-02-05 18:58 UTC by Florian Weimer
Modified: 2019-01-24 08:27 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-02-22 05:17:17 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
rsync patch (8.57 KB, patch)
2018-02-06 13:20 UTC, Florian Weimer
no flags Details | Diff
rsync patch (8.58 KB, patch)
2018-02-06 13:44 UTC, Florian Weimer
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Launchpad 1746995 0 None None None 2018-02-05 18:58:01 UTC
Red Hat Bugzilla 1534635 1 None None None 2021-06-10 14:12:12 UTC
Red Hat Bugzilla 1542979 0 unspecified CLOSED glibc fix for CVE-2018-1000001 breaks geo-replication 2021-02-22 00:41:40 UTC
Samba Project 6422 0 None None None 2019-04-01 00:40:07 UTC

Internal Links: 1534635 1542979

Description Florian Weimer 2018-02-05 18:58:02 UTC
After the fix for CVE-2018-1000001, getcwd returns ENOENT if the current directory is unreachable and does not have a name.

This happens because this:

	/* Initialize change_dir() here because on some old systems getcwd
	 * (implemented by forking "pwd" and reading its output) doesn't
	 * work when there are other child processes.  Also, on all systems
	 * that implement getcwd that way "pwd" can't be found after chroot. */
	change_dir(NULL, CD_NORMAL);

And this:

/* Like chdir(), but it keeps track of the current directory (in the
 * global "curr_dir"), and ensures that the path size doesn't overflow.
 * Also cleans the path using the clean_fname() function. */
int change_dir(const char *dir, int set_path_only)
{
	static int initialised, skipped_chdir;
	unsigned int len;

	if (!initialised) {
		initialised = 1;
		if (getcwd(curr_dir, sizeof curr_dir - 1) == NULL) {
			rsyserr(FERROR, errno, "getcwd()");
			exit_cleanup(RERR_FILESELECT);
		}
		curr_dir_len = strlen(curr_dir);
	}

This error is reached even if all input paths to rsync are absolute and the current directory path is never needed.

To trigger this, it is sufficient to execve rsync from a process whose current directory has a pending lazy umount (MNT_DETACH/umount -l).  The execve makes the current directory unreachable in the new process image (at least on kernel 4.14.14).

Reportedly, this break glusterfs geo-replication.

References:

https://lists.gluster.org/pipermail/gluster-users/2018-January/033293.html
https://sourceware.org/ml/libc-alpha/2018-02/msg00152.html
https://bugs.launchpad.net/bugs/1746995

Comment 1 Florian Weimer 2018-02-06 13:20:42 UTC
Created attachment 1392075 [details]
rsync patch

Posted for upstream review:

https://lists.samba.org/archive/rsync/2018-February/031476.html

Comment 2 Florian Weimer 2018-02-06 13:44:16 UTC
Created attachment 1392082 [details]
rsync patch

Got tricked by Git and submitted the wrong patch.

Comment 6 Mrten 2018-02-08 10:04:48 UTC
Glusterfs problem also reported here: bug 1542979

Comment 13 Pavel Zhukov 2018-02-21 17:41:31 UTC
I've dig into the issue a bit more.
Actually there is bug in rsync which *allowed* it to operate if directory is unavailable (i.e. getcwd() returned (unavailable)/path before the CVE fixed). It's clear from the util.c:change_dir() and [1] that it was designed to prevent this situation as it may lead undefined behavior.
IMO Gluster's code should be changed to not exec() applications from unmounted directory instead of putting all rsync users on risk of running from withing unavailable directory. 

Small reproducer is in [1] and looks like: mkdir test && cd test && rmdir ../test &&  rsync /etc/fstab /tmp/

[1] https://bugzilla.samba.org/show_bug.cgi?id=6422

Comment 14 Pavel Zhukov 2018-02-22 05:17:17 UTC
Based on #13 I'm closing this bug.
@Florian, thank you for your time and patch provided. However it's too risky to operate if current directory is not available and upper level software (in this case it's gluster) should take care of this.


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