Bug 1513 - CIDR address/masklen matching support for permitopen=
Summary: CIDR address/masklen matching support for permitopen=
Status: NEW
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: sshd (show other bugs)
Version: 5.1p1
Hardware: All All
: P2 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-27 21:46 AEST by 238749328749
Modified: 2019-09-25 19:46 AEST (History)
6 users (show)

See Also:


Attachments
Feature enhancement patch for permitopen - needs code review/testing/cleanup (16.78 KB, patch)
2011-03-29 08:49 AEDT, RyanC
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description 238749328749 2008-08-27 21:46:23 AEST
In OpenSSH 5.1 you introduced CIDR address/masklen matching for "Match address" blocks in sshd_config as well as supporting CIDR matching in ~/.ssh/authorized_keys from="..." restrictions in sshd.

I wonder whether CIDR address/masklen matching will be implemented for permitopen="host:port" restrictions in sshd as well, that would be quite beneficially (at least for me, maybe others,too;-) (There was already a request for a feature like that incl a patch back in 2005)

--> permitopen="net/mask:port(s)"
--> permitopen="net/mask:port_range"

You suggested to look into it by myself (and perhaps contribute a patch...) - I definitively would do that if I'd only speak C...


Thank you - kind regards,

Bert
Comment 1 Damien Miller 2010-08-03 15:41:07 AEST
We are freezing for the OpenSSH 5.6 release. Retargetting these bugs to the next release.
Comment 2 Damien Miller 2011-01-24 12:30:54 AEDT
Retarget unclosed bugs from 5.7=>5.8
Comment 3 RyanC 2011-03-29 08:49:02 AEDT
Created attachment 2025 [details]
Feature enhancement patch for permitopen - needs code review/testing/cleanup

This patch changes permitopen to use the same access logic as is available for 'from='

That is:

* CIDR matches - 192.168.0.0/16
* Wildcard matches - *.example.com
* Negated matches !10.0.0.0/8

Support for port ranges has been added, e.g.

127.0.0.1:* or 127.0.0.1:1-65535

The checking logic has been moved to a function which is called from connect_next which happens after DNS resolution but before the actual connect call.  This is in order to allow a permitopen to www.example.com to still work when the forwarding request is made using the ip address and vice versa.

Negations take precedence over other matches, so one can do something like this:
PermitOpen 0.0.0.0/0:*
PermitOpen !127.0.0.0/8:*

Other things:

Get rid of permitopen any?

NOTES:

I've only tested this with PermitOpen in the config file, it should work with permitopen= from an authorized_key file, but I haven't verified.

I'm not great with C, and someone needs to doublecheck my work to ensure that I haven't introduced any possible buffer overflows.  I understand the gotchas in general regarding buffer overflows and I think I've done everything correctly, but I lack enough experience to be confident.

Some minor changes have been made to return codes given by functions in match.c and code referencing these functions has been updated.  Stuff relying on those functions should be tested.

channel_connect_to has been changed to simply call connect_to.  It could probably be aliased with a #define but I'm not quite clear on static vs non-static functions in C.

I've attempted to follow coding style, but in a few cases this has lead me to do things which seem weird.  In particular multi-purposing variables seems questionable to me.

I've used hpdelim to split out CIDR/port mappings, but it doesn't distinguish : from /, so if you permitopen 192.168.0.0/16 it will be parsed as 192.168.0.0, port 16, which is a bit dubious.
Comment 4 VP 2011-03-30 00:07:32 AEDT
It would be nice if coma separated lists of hosts and ports were also supported:
Ex:

PermitOpen 10.5.100.34:22,443 10.5.100.2,10.5.100.20:22

Thanks.
Comment 5 RyanC 2011-03-30 06:51:29 AEDT
> It would be nice if coma separated lists of hosts and ports were also
> supported:
> Ex:
> PermitOpen 10.5.100.34:22,443 10.5.100.2,10.5.100.20:22

Space delimited lists are handled in the sshd config file already.

Writing a parser that would handle the situation you suggest would be rather annoying.  Additionally, handling lists of ports instead of just a port range requires significantly more complicated handling, both in data structures and access checking.  I don't care about it enough to bother doing it.
Comment 6 Damien Miller 2011-09-06 10:34:23 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 7 Damien Miller 2011-09-06 10:36:35 AEST
Retarget unresolved bugs/features to 6.0 release
Comment 8 Damien Miller 2011-09-06 10:39:11 AEST
Retarget unresolved bugs/features to 6.0 release

(try again - bugzilla's "change several" isn't)
Comment 9 VP 2011-12-02 02:06:14 AEDT
did some tests, run it for a few months. works fine. thanks a lot, RyanC
Comment 10 RyanC 2011-12-02 03:59:54 AEDT
Damien,

Is there anything I can do to increase the likelyhood of this getting looked at and maybe included in the next release?

Thanks,
Ryan
Comment 11 RyanC 2011-12-02 05:02:08 AEDT
The current snapshot breaks my patch.  I'm working on a fix.
Comment 12 Damien Miller 2012-02-24 10:34:33 AEDT
Retarget from 6.0 to 6.1
Comment 13 Damien Miller 2012-02-24 10:38:13 AEDT
Retarget 6.0 => 6.1
Comment 14 VP 2012-04-26 00:16:22 AEST
Ryan,
do you plan to create a patch for 6.0 any time soon?

Thanks.
Comment 15 RyanC 2012-04-26 04:45:49 AEST
Vladimir,

I'm not currently using OpenSSH 6.0 or higher anywhere that I need this functionality, so forward-porting the patch (which, due to some structural changes in the code, will be non-trivial) is low on my list of priorities - between work, various personal projects and social obligations I don't have a lot of free time.

However, if I could get some feedback from Damien as to what I would need to do to get this patch merged, I would be happy to make the time to spend a weekend forward-porting the patch. I don't want to have to maintain it as a separate patch, and I don't like having to apply custom patches and repackage software that I use.

Damien?

-Ryan
Comment 16 Damien Miller 2012-09-07 11:38:29 AEST
Retarget uncompleted bugs from 6.1 => 6.2
Comment 17 Damien Miller 2012-09-07 11:40:51 AEST
Retarget bugs from 6.1 => 6.2
Comment 18 Damien Miller 2013-03-08 10:24:25 AEDT
retarget to openssh-6.3
Comment 19 Damien Miller 2013-07-25 12:18:22 AEST
Retarget to openssh-6.4
Comment 20 Damien Miller 2013-07-25 12:21:25 AEST
Retarget 6.3 -> 6.4
Comment 21 Damien Miller 2014-02-06 10:18:25 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 22 Damien Miller 2014-02-06 10:20:39 AEDT
Retarget incomplete bugs / feature requests to 6.6 release
Comment 23 Damien Miller 2014-04-12 14:49:50 AEST
Retarget to 6.7 release, since 6.6 was mostly bugfixing.
Comment 24 Damien Miller 2014-04-12 14:54:56 AEST
Remove from 6.6 tracking bug
Comment 25 Damien Miller 2014-08-30 04:38:50 AEST
Retarget incomplete bugs to 6.8 release.
Comment 26 Damien Miller 2014-08-30 04:39:40 AEST
These bugs are no longer targeted at the imminent 6.7 release
Comment 27 VP 2014-11-26 03:14:43 AEDT
Ryan, have you looked at patching version 6? :)
Comment 28 Damien Miller 2015-03-03 07:59:29 AEDT
OpenSSH 6.8 is approaching release and closed for major work. Retarget these bugs for the next release.
Comment 29 Damien Miller 2015-03-03 08:01:38 AEDT
Retarget to 6.9
Comment 30 Damien Miller 2015-08-11 22:59:21 AEST
Retarget pending bugs to openssh-7.1
Comment 31 Damien Miller 2016-02-05 13:55:32 AEDT
Pull this off list for 7.2
Comment 32 AG 2016-06-11 06:01:07 AEST
FWIW I have a rather compact and simple libcidr that I use in a PAM module if it's useful, just ping me.