Bug 2440 - X11 connection will fail if user's home directory is read-only
Summary: X11 connection will fail if user's home directory is read-only
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 6.8p1
Hardware: SPARC Solaris
: P5 normal
Assignee: Damien Miller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-06 07:56 AEST by huieying.lee
Modified: 2019-10-17 04:36 AEDT (History)
3 users (show)

See Also:


Attachments
This patch is to change the location of the XAUTHORITY file from ~/.Xauthority to per session Xauh file in /tmp directory (4.79 KB, patch)
2015-08-06 07:56 AEST, huieying.lee
no flags Details | Diff
new patch file for per session xauth enhancement (4.86 KB, patch)
2016-04-26 09:59 AEST, huieying.lee
no flags Details | Diff
factor out agent socket directory creation for reuse (4.53 KB, patch)
2017-09-01 14:54 AEST, Damien Miller
djm: ok? (dtucker)
Details | Diff
create xauth file in temp directory (2.55 KB, patch)
2017-09-01 14:55 AEST, Damien Miller
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description huieying.lee 2015-08-06 07:56:26 AEST
Created attachment 2680 [details]
This patch is to change the location of the XAUTHORITY file from ~/.Xauthority to  per session Xauh file in /tmp directory

If a user's home directory is read-only, then X11 connection will be rejected because of wrong authentication.  For example, 

    $ssh  -l hylee_local a-server          
    Password: 
    Last login: Wed Aug  5 14:09:42 2015 from 10.132.148.106
    /usr/bin/xauth:  timeout in locking authority file /export/home/hylee_local/.Xauthority

    hylee_local$/usr/bin/xemacs /tmp/junk
    X11 connection rejected because of wrong authentication.
    ...

The root cause of the problem is because the xauth program (invoked by sshd) couldn't lock the non-writable the ~/.Xauthority file.

This is a serious problem on Solaris, because a writable home directory 
isn't always available for root in an immutable zone.

We have resolved this problem by changing sshd to use a distinct temporary X authority file for each session.  This temporary Xauthority file will be stored in the /tmp directory and it will be removed when the session is closed.

Attached is our bug-fix patch file, which applies to OpenSSH6.8p1.
Comment 1 Damien Miller 2016-02-26 14:44:28 AEDT
Retarget to openssh-7.3
Comment 2 Damien Miller 2016-02-26 14:47:26 AEDT
Retarget to openssh-7.3
Comment 3 huieying.lee 2016-04-26 09:59:54 AEST
Created attachment 2809 [details]
new patch file for per session xauth enhancement
Comment 4 huieying.lee 2016-04-26 10:08:23 AEST
Recently, we discovered that the original code changes for this enhancement would not work if UsePrivilegeSeparation is set to NO.  

We fixed the problem with the following code changes:

--------------------------------------------------------------------
--- old/session.c	Mon Apr 25 15:33:39 2016
+++ new/session.c	Mon Apr 25 15:37:31 2016
@@ -2241,6 +2241,7 @@
 	 * means that we won't set XAUTHORITY variable in child's environment
 	 * and xauth(1) will use the default location for the authority file.
 	 */
+	temporarily_use_uid(s->pw);
 	if (mkdtemp(xauthdir) != NULL) {
 		s->auth_file = xmalloc(MAXPATHLEN);
 		snprintf(s->auth_file, MAXPATHLEN, "%s/xauthfile",
@@ -2273,6 +2274,7 @@
 		    "authority file: %.100s; will use the default xauth file",
 		    strerror(errno));
 	}
+	restore_uid();
 #endif
 	return success;
 }
-----------------------------------------------------------------------

A new patch file was attached also, which applies to OpenSSH 7.2p2.
Comment 5 Damien Miller 2016-07-22 14:10:56 AEST
retarget unfinished bugs to next release
Comment 6 Damien Miller 2016-07-22 14:14:55 AEST
retarget unfinished bugs to next release
Comment 7 Damien Miller 2016-07-22 14:15:50 AEST
retarget unfinished bugs to next release
Comment 8 Damien Miller 2016-07-22 14:17:19 AEST
retarget unfinished bugs to next release
Comment 9 Damien Miller 2016-12-16 14:31:20 AEDT
OpenSSH 7.4 release is closing; punt the bugs to 7.5
Comment 10 Damien Miller 2017-06-30 13:43:17 AEST
Move incomplete bugs to openssh-7.6 target since 7.5 shipped a while back.

To calibrate expectations, there's little chance all of these are going to make 7.6.
Comment 11 Damien Miller 2017-06-30 13:44:23 AEST
remove 7.5 target
Comment 12 Damien Miller 2017-09-01 14:54:27 AEST
Created attachment 3047 [details]
factor out agent socket directory creation for reuse

The agent forwarding code already creates one directory, so to avoid a proliferation, this factors it out in preparation for using it for xauth files too.

Also moves the ExposeAuthInfo contents to that directory now that it is convenient.
Comment 13 Damien Miller 2017-09-01 14:55:40 AEST
Created attachment 3048 [details]
create xauth file in temp directory

This uses the previous refactoring to create a per-session xauth file. If the file is created successfully then its location is supplied via XAUTHORITY and automatically used by xauth(1).
Comment 14 Damien Miller 2018-04-06 13:12:16 AEST
Move to OpenSSH 7.8 tracking bug
Comment 15 Damien Miller 2018-07-20 14:10:46 AEST
dtucker made this observation:

> this will make it much harder to use an X display from anywhere else
> other than the session that created it.  Right now I could do
> "DISPLAY=:10.0 some_installer" on the console and it'll pick
> up the cookie from ~/.Xauthority and probably work, or at least be no
> more broken than usual.
> 
> I'm not sure if that's a down side or not but it's certainly a change
> in behaviour.
Comment 16 Damien Miller 2018-07-20 14:17:13 AEST
untarget this because we'll need to think about it a little more. Maybe we could do an access(3) check and only fall back to tmp-hosted XAUTHORITY if it failed? OTOH that seems an excessively complex solution to what is essentially a configuration problem.
Comment 17 Peter Oliver 2019-10-17 04:36:44 AEDT
(In reply to Damien Miller from comment #16)
> Maybe we could do an access(3) check and only fall back to
> tmp-hosted XAUTHORITY if it failed?

There are other reasons for putting .Xauthority outside the home directory besides the home directory being read only.  See, for example, the write-up at https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/1648107.