Bug 1742 - sshconnect should use port returned by getaddrinfo
Summary: sshconnect should use port returned by getaddrinfo
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 5.4p1
Hardware: All All
: P2 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-25 06:29 AEDT by Jim Rees
Modified: 2019-10-14 11:28 AEDT (History)
4 users (show)

See Also:


Attachments
use getaddrinfo for sshd port lookup (2.15 KB, patch)
2010-03-25 06:29 AEDT, Jim Rees
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Rees 2010-03-25 06:29:03 AEDT
Created attachment 1820 [details]
use getaddrinfo for sshd port lookup

Ssh, in ssh_connect(), calls getaddrinfo() to get the the server endpoint address. Getaddrinfo returns a port number but this is ignored. Ssh instead makes an unnecessary call to getservbyname() to get the port number. In most cases this makes no difference, but this makes it impossible to use DNS SRV records to find ssh services.

The attached patch eliminates the call to getservbyname and instead uses the port returned by getaddrinfo.
Comment 1 Damien Miller 2010-04-09 11:12:23 AEST
We need to be careful here, I think the port number that we obtain by getservbyname() is used to decide whether to decorate the hostname with a non default port in known_hosts.
Comment 2 Damien Miller 2010-08-03 15:40:57 AEST
We are freezing for the OpenSSH 5.6 release. Retargetting these bugs to the next release.
Comment 3 Damien Miller 2010-08-03 15:42:37 AEST
Targetting OpenSSH 5.7
Comment 4 Damien Miller 2011-09-06 10:34:18 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 5 Damien Miller 2011-09-06 10:36:31 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 6 Damien Miller 2011-09-06 10:39:06 AEST
Retarget unresolved bugs/features to 6.0 release

(try again - bugzilla's "change several" isn't)
Comment 7 Jim Rees 2011-09-06 11:03:36 AEST
I believe that if there is no SRV record, getaddrinfo will return the same port as getservbyname. I can check on this. If that's the case, the risk seems low.

The question is, if there is a SRV record, and it returns something different from what getservbyname does, what port should be used for known_hosts? If we can decide on the correct behavior, I can make sure the patch does the right thing.
Comment 8 Damien Miller 2012-02-24 10:34:26 AEDT
Retarget from 6.0 to 6.1
Comment 9 Damien Miller 2012-02-24 10:38:06 AEDT
Retarget 6.0 => 6.1
Comment 10 Damien Miller 2012-09-07 11:38:11 AEST
Retarget uncompleted bugs from 6.1 => 6.2
Comment 11 Damien Miller 2012-09-07 11:40:38 AEST
Retarget bugs from 6.1 => 6.2
Comment 12 Damien Miller 2013-03-08 10:23:53 AEDT
retarget to openssh-6.3
Comment 13 Damien Miller 2013-07-25 10:22:54 AEST
Thinking about this a little more, this patch would break hosts where "ssh" isn't in /etc/services. There are probably a few of these out there, since people like to run OpenSSH on all sorts of old things.

How about we do the getservbyname lookup but only set port (to 22) if it fails? This would preserve the current working behaviour but let SRV records work too.
Comment 14 Damien Miller 2013-07-25 12:17:50 AEST
Retarget to openssh-6.4
Comment 15 Damien Miller 2013-07-25 12:20:46 AEST
Retarget 6.3 -> 6.4
Comment 16 Damien Miller 2014-02-06 10:18:01 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 17 Damien Miller 2014-02-06 10:20:03 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 18 Damien Miller 2014-04-12 14:48:40 AEST
Retarget to 6.7 release, since 6.6 was mostly bugfixing.
Comment 19 Damien Miller 2014-04-12 14:53:48 AEST
Remove from 6.6 tracking bug
Comment 20 Damien Miller 2014-07-03 18:32:54 AEST
untarget from 6.7; this needs a concrete design in light of hostname canonicalisation changes
Comment 21 Hoff 2019-10-14 11:28:07 AEDT
I think a few lines more won't hurt nobody if it brings in any additional value. ,http://ultimatewebtraffic.com