Bug 1542180 - rsync: fails to start if the current directory is unreachable
Summary: rsync: fails to start if the current directory is unreachable
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: rsync
Version: 7.5-Alt
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: ---
Assignee: Pavel Zhukov
QA Contact: BaseOS QE Security Team
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:
Last Closed: 2018-02-22 05:17:17 UTC
Target Upstream Version:

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

System ID Priority Status Summary Last Updated
Launchpad 1746995 None None None 2018-02-05 18:58:01 UTC
Red Hat Bugzilla 1534635 None None None 2019-09-25 13:43:40 UTC
Red Hat Bugzilla 1542979 None CLOSED glibc fix for CVE-2018-1000001 breaks geo-replication 2019-09-25 13:43:40 UTC
Samba Project 6422 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()");
		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.



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

Posted for upstream review:


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.