Bug 2341 - XQuartz X11 forwarding not working in OS X 10.10 Yosemite
Summary: XQuartz X11 forwarding not working in OS X 10.10 Yosemite
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 6.7p1
Hardware: All Mac OS X
: P5 normal
Assignee: Assigned to nobody
URL:
Keywords: low-hanging-fruit
Depends on:
Blocks: V_7_5
  Show dependency treegraph
 
Reported: 2015-01-23 21:12 AEDT by Jakob Schlyter
Modified: 2021-04-23 15:02 AEST (History)
3 users (show)

See Also:


Attachments
OSX X11: if using launchd socket, remove the screen number (2.74 KB, patch)
2015-04-15 15:56 AEST, Darren Tucker
no flags Details | Diff
OSX X11: if using launchd socket, remove the screen number (1002 bytes, patch)
2016-09-07 10:29 AEST, Darren Tucker
djm: ok+
Details | Diff
OSX X11: if using launchd socket, remove the screen number (1.55 KB, patch)
2016-12-15 11:01 AEDT, Darren Tucker
djm: ok+
Details | Diff
OSX X11: if using launchd socket, remove the screen number (1.53 KB, patch)
2016-12-15 11:50 AEDT, Darren Tucker
djm: ok+
Details | Diff
OSX X11: if using launchd socket, remove the screen number (1.52 KB, patch)
2016-12-15 11:59 AEDT, Darren Tucker
djm: ok+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakob Schlyter 2015-01-23 21:12:24 AEDT
bug report in: http://xquartz.macosforge.org/trac/ticket/1451
patch in https://trac.macports.org/export/121205/trunk/dports/net/openssh/files/launchd.patch

I've tested the patch and it works.
Comment 1 Jakob Schlyter 2015-03-18 18:14:45 AEDT
Patch applies to 6.8p1 as well (just tested).
Comment 2 Darren Tucker 2015-04-15 15:56:58 AEST
Created attachment 2585 [details]
OSX X11: if using launchd socket, remove the screen number

patch added for commenting.  I think we can make this less invasive, though.
Comment 3 Jakob Schlyter 2015-07-02 01:46:35 AEST
Any chance we can get this into 7.0?
Comment 4 Damien Miller 2015-08-12 11:00:49 AEST
Move unfinished bugs from 6.9 (how did I miss these?) to 7.1
Comment 5 Damien Miller 2016-02-26 14:44:29 AEDT
Retarget to openssh-7.3
Comment 6 Damien Miller 2016-02-26 14:47:18 AEDT
Retarget to openssh-7.3
Comment 7 Damien Miller 2016-07-22 14:10:55 AEST
retarget unfinished bugs to next release
Comment 8 Damien Miller 2016-07-22 14:14:59 AEST
retarget unfinished bugs to next release
Comment 9 Damien Miller 2016-07-22 14:15:42 AEST
retarget unfinished bugs to next release
Comment 10 Damien Miller 2016-07-22 14:17:10 AEST
retarget unfinished bugs to next release
Comment 11 Jakob Schlyter 2016-09-06 20:53:31 AEST
Could we please ressolve this? It's been >1.5 years now...
Comment 12 Jakob Schlyter 2016-09-07 06:07:59 AEST
Updated patch: https://github.com/openssh/openssh-portable/compare/master...jschlyter:osx, slightly less changes.
Comment 13 Darren Tucker 2016-09-07 10:29:09 AEST
Created attachment 2871 [details]
OSX X11: if using launchd socket, remove the screen number

Imported from https://github.com/openssh/openssh-portable/compare/master...jschlyter:osx

This diff is a lot more palatable since it does not change the mainline code and thus does not represent an increased maintenance burden.

What's the provenance of this diff?  I'd like to make sure it is correctly attributed.
Comment 14 Darren Tucker 2016-09-07 10:34:32 AEST
Comment on attachment 2871 [details]
OSX X11: if using launchd socket, remove the screen number


>+		if (0 == stat(path, &sbuf)) {

this is counter to the usual style (same below).

>+					is_path_to_socket=1;

needs spaces

We should fix those before committing, other than that, looks reasonable.
Comment 15 Damien Miller 2016-09-07 15:36:06 AEST
Comment on attachment 2871 [details]
OSX X11: if using launchd socket, remove the screen number

IMO this might be better off as a separate function. Also a couple of nits:

> strlcpy(path, display, sizeof(path))

should check for truncation

The tests like (0 == stat(path, &sbuf)) are a bit unidiomatically backwards-ordered

> +			if (dot) {

style(9) says (dot != NULL)
Comment 16 Jakob Schlyter 2016-09-07 17:54:53 AEST
I've made is_path_to_xsocket() a separate function now. This code originated from Apple (ref: https://opensource.apple.com/source/OpenSSH/OpenSSH-195.40.1/openssh/channels.c).

https://github.com/openssh/openssh-portable/compare/master...jschlyter:osx
Comment 17 Jakob Schlyter 2016-12-14 18:06:22 AEDT
Almost 2 years now, still not fixed. What's holding this back?
Comment 18 Darren Tucker 2016-12-15 11:01:01 AEDT
Created attachment 2915 [details]
OSX X11: if using launchd socket, remove the screen number

(In reply to Jakob Schlyter from comment #17)
> Almost 2 years now, still not fixed. What's holding this back?

Well, there was no patch that had the issues addressed and had been tested.  This takes your last patch and fixes djm's comment#15.  Could you please try it?
Comment 19 Damien Miller 2016-12-15 11:27:00 AEDT
Comment on attachment 2915 [details]
OSX X11: if using launchd socket, remove the screen number

This is ok, my comments are just nitpicks:

>+	if (stat(path, &sbuf) == 0) {
>+		return 1;

no need to wrap the remainder in and else block after return here.

>+	} else {
>+		char *dot = strrchr(path, '.');

I'd stick "char *dot" at the start of the function and do
"if ((dot = strrchr(path, '.')) != NULL {"
on one line, but that's nitpicking :)


> #ifdef __APPLE__
>-	if (strncmp(display, "/tmp/launch", 11) == 0) {
>-		sock = connect_local_xsocket_path(display);
>-		if (sock < 0)
>-			return -1;
>+	/* Check if display is a path to a socket (as set by launchd). */
>+	{
>+		char path[PATH_MAX];
> 
>-		/* OK, we now have a connection to the display. */
>-		return sock;
>+		if (is_path_to_xsocket(display, path, sizeof(path))) {
>+			debug("x11_connect_display: $DISPLAY is launchd");
>+
>+			/* Create a socket. */
>+			sock = connect_local_xsocket_path(path);
>+			if (sock < 0)
>+				return -1;
>+
>+			/* OK, we now have a connection to the display. */
>+			return sock;

also nitpicking: maybe we should move this whole lot into a separate function?
Comment 20 Darren Tucker 2016-12-15 11:50:56 AEDT
Created attachment 2916 [details]
OSX X11: if using launchd socket, remove the screen number

(In reply to Damien Miller from comment #19)
> no need to wrap the remainder in and else block after return here.

done

> I'd stick "char *dot" at the start of the function and do
> "if ((dot = strrchr(path, '.')) != NULL {"
> on one line, but that's nitpicking :)

done

[...]
> also nitpicking: maybe we should move this whole lot into a separate
> function?

left this one for now.
Comment 21 Damien Miller 2016-12-15 11:54:30 AEDT
Comment on attachment 2916 [details]
OSX X11: if using launchd socket, remove the screen number

>+	if (stat(path, &sbuf) == 0) {
>+		return 1;
>+	}

hemi-demi-nitpick: remove braces
Comment 22 Darren Tucker 2016-12-15 11:59:39 AEDT
Created attachment 2917 [details]
OSX X11: if using launchd socket, remove the screen number

(In reply to Damien Miller from comment #21)
> hemi-demi-nitpick: remove braces

done.
Comment 23 Darren Tucker 2016-12-19 16:06:04 AEDT
Comment from Ron Frederick on openssh-unix-dev@ (https://lists.mindrot.org/pipermail/openssh-unix-dev/2016-December/035584.html):

"""
Looking at this patch, it seems to me that it introduces a possible exploit. The new code calls stat() on whatever string is set as the display value, even before checking for display values that are meant to refer to remote network hosts. If “ssh” is run in a directory which happens to have a file/pipe/socket named to match one of those network display values, this new code would return that it should connect to this local socket rather than the remote host when doing the forwarding.

While checking for “/tmp/launch” as a prefix is a problem now that MacOS is putting these local sockets in paths starting with “/private/tmp/com.apple.launchd”, I think this new code should at a minimum require that the path start with a leading “/“ before treating it as a local socket and doing a stat() on it.
"""

Sorry but this is now too late for 7.4.
Comment 24 Darren Tucker 2016-12-19 16:07:50 AEDT
for the next respin of the patch: also put the new function behind #ifdef APPLE, otherwise it causes "unused function" warnings on everything else.
Comment 25 Jakob Schlyter 2016-12-19 18:07:58 AEDT
(In reply to Darren Tucker from comment #24)
> for the next respin of the patch: also put the new function behind
> #ifdef APPLE, otherwise it causes "unused function" warnings on
> everything else.

https://github.com/jschlyter/openssh-portable/commit/3100451bf5a0d2a23a0f927f603ddf0172a43763
Comment 26 Jakob Schlyter 2017-03-02 08:08:46 AEDT
Any updates? Anything I should do?
Comment 27 Darren Tucker 2017-03-10 13:28:31 AEDT
Patch applied, thanks for your patience.
Comment 28 Damien Miller 2021-04-23 15:02:25 AEST
closing resolved bugs as of 8.6p1 release