Skip to contentSkip to conversation

SELinux system configuration using CIPSO

DISCUSSION Casey Schaufler 5 participants 14 messages Nov 15, 2016 – Nov 22, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

#1 lore raw
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

#2 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

#3 lore raw
Quoted 13 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

#4 lore raw
Quoted 20 lines · Stephen Smalley
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 5 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

Yeah, the cross machine MLS only encoding is one of the things that I'm most interested in examining carefully. I can't help but think that that is something that could be somewhat tricky to set up, which is why I'm hoping that there's an example I can look at and play with.

maintainer
#5 lore raw

I'm somewhat limited the next few days with just my phone for network access, but the link below has some basic examples. The netlabelctl manpage may also be helpful. Finally, as Stephen already pointed out, the LSPP/audit-test project has some inter-machine CIPSO tests, but you will have to do some digging to get at the configuration examples.

* http://www.paul-moore.com/blog/d/2009/02/netlabel-address-selectors.html

--
paul moore
www.paul-moore.com

Quoted 38 lines · Casey Schaufler
Quoted 20 lines · Stephen Smalley
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 5 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

Yeah, the cross machine MLS only encoding is one of the things that I'm most interested in examining carefully. I can't help but think that that is something that could be somewhat tricky to set up, which is why I'm hoping that there's an example I can look at and play with.

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

#6 lore raw
In reply to Stephen Smalley
Quoted 22 lines · On Tue, 15 Nov 2016 13:43:28 -0500 Stephen Smalley <[email protected]> wrote:
Quoted 13 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 7 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

In addition to the user:role:type information, there are other limits to what you can pass over the wire via netlabel due to the way the CIPSO information is encoded in the packet.

You can only encode a single sensitivity because the CIPSO spec only stores it in a single integer. s0:c0.c1023 passes fine, but s0-s2:c0.c1023 will get reduced to s0:c0.c1023.

Unlike the sensitivity it is possible to pass some
fairly complex sets of categories. When you create a DOI,
you can specify how the categories will be encoded using a tag of 1, 2, or 5. ( these are bitmap, enumerated and range types respectively ) What categories can be passed via netlabel is dependent on the limits of these types.

The bottom line is that it's entirely possible to have a valid context that netlabel will not be able to fully preserve. Netlabel is still very useful, but you have to remain mindful of its limitations.

The above is based on my reading of the CIPSO spec and my experience with netlabel. It's entirely possible my understanding is incomplete and/or out of date. Somone like Paul Moore can speak with much greater authority.

HW

#7 lore raw
Quoted 47 lines · Harry Waddell
Quoted 20 lines · On Tue, 15 Nov 2016 13:43:28 -0500 Stephen Smalley <[email protected]> wrote:
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 7 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

In addition to the user:role:type information, there are other limits to what you can pass over the wire via netlabel due to the way the CIPSO information is encoded in the packet.

You can only encode a single sensitivity because the CIPSO spec only stores it in a single integer. s0:c0.c1023 passes fine, but s0-s2:c0.c1023 will get reduced to s0:c0.c1023.

Unlike the sensitivity it is possible to pass some
fairly complex sets of categories. When you create a DOI,
you can specify how the categories will be encoded using a tag of 1, 2, or 5. ( these are bitmap, enumerated and range types respectively ) What categories can be passed via netlabel is dependent on the limits of these types.

The bottom line is that it's entirely possible to have a valid context that netlabel will not be able to fully preserve. Netlabel is still very useful, but you have to remain mindful of its limitations.

Quoted 5 lines

The above is based on my reading of the CIPSO spec and my experience with netlabel. It's entirely possible my understanding is incomplete and/or out of date. Somone like Paul Moore can speak with much greater authority.

HW

I understand CIPSO reasonably well, having been involved in its development back in the late 80's and early 90's*. What I'm looking for is a way to set up an SELinux system that uses CIPSO without having to learn all the gnarly details of SELinux network administration. A sample configuration would be a big help.

---
* I was working at Sun, Silicon Graphics and Cray on B1 Unix systems. They used CIPSO long before the RFC was published.

#8 lore raw
Quoted 61 lines · On Tue, 15 Nov 2016 15:07:34 -0800 Casey Schaufler <[email protected]>…
Quoted 47 lines · Harry Waddell
Quoted 20 lines · On Tue, 15 Nov 2016 13:43:28 -0500 Stephen Smalley <[email protected]> wrote:
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 7 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

In addition to the user:role:type information, there are other limits to what you can pass over the wire via netlabel due to the way the CIPSO information is encoded in the packet.

You can only encode a single sensitivity because the CIPSO spec only stores it in a single integer. s0:c0.c1023 passes fine, but s0-s2:c0.c1023 will get reduced to s0:c0.c1023.

Unlike the sensitivity it is possible to pass some
fairly complex sets of categories. When you create a DOI,
you can specify how the categories will be encoded using a tag of 1, 2, or 5. ( these are bitmap, enumerated and range types respectively ) What categories can be passed via netlabel is dependent on the limits of these types.

The bottom line is that it's entirely possible to have a valid context that netlabel will not be able to fully preserve. Netlabel is still very useful, but you have to remain mindful of its limitations.

Quoted 5 lines

The above is based on my reading of the CIPSO spec and my experience with netlabel. It's entirely possible my understanding is incomplete and/or out of date. Somone like Paul Moore can speak with much greater authority.

HW

I understand CIPSO reasonably well, having been involved in its development back in the late 80's and early 90's*. What I'm looking for is a way to set up an SELinux system that uses CIPSO without having to learn all the gnarly details of SELinux network administration. A sample configuration would be a big help.

Quoted 4 lines

---
* I was working at Sun, Silicon Graphics and Cray on B1 Unix systems. They used CIPSO long before the RFC was published.

It depends entirely on what you mean by "uses" and I totally get what you mean when you say you don't want to learn about selinux net admin, but depending on what you want to do, I'm not sure you can get out of it. Paul Moore's blog posts are the best thing I know of but they break everything up into pieces, so AFAIK, there's no single example that is comprehensive. It certainly wasn't easy going for me as there are a lot of parts that need to be set up. I now have what I need in a working state,
but I'm pretty sure at least some of what I've done would have been redundant and unnecessary if I'd just taken the time to define my nodes, booleans, etc... correctly.

For example, I have this intended to allow ping to work:

#============= ping_t ==============
allow ping_t netlabel_peer_t:netif egress;

I did what I expect most people do which is to set it up and see what breaks. My work is definitely not good enough to be an example for others just yet.

HW

#9 lore raw
Quoted 63 lines · Harry Waddell
Quoted 60 lines · On Tue, 15 Nov 2016 15:07:34 -0800 Casey Schaufler <[email protected]>…
Quoted 47 lines · Harry Waddell
Quoted 20 lines · On Tue, 15 Nov 2016 13:43:28 -0500 Stephen Smalley <[email protected]> wrote:
Quoted 12 lines · Casey Schaufler
Quoted 11 lines · Stephen Smalley
Quoted 5 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Can you clarify what you mean? There is a sample NetLabel configuration in the selinux-testsuite (in tests/inet_socket/netlabel-load) that configures full SELinux labeling over loopback connections, used by the inet_socket tests. And the corresponding SELinux policy rules for those tests can be found in policy/test_inet_socket.te within the testsuite.

Quoted 7 lines

That will probably get me started. I'll have a look at the test documentation. I am also looking for a configuration that I can use for exploring a "real" CIPSO environment, where two or more machines are talking to each other using CIPSO. I think that I understand how that is supposed to work, but there's nothing like seeing the packets fly. Is there a case for that in the test suite? Thank you.

Quoted 7 lines

Not in the selinux-testsuite, since it doesn't presently require/expect you to set up two different systems. Probably the lspp testsuite or Paul Moore's blog or maybe the SELinux Notebook for samples of that kind of configuration. Note that in that cross-machine case, CIPSO only passes an encoding of the MLS label, not the user:role:type information.

In addition to the user:role:type information, there are other limits to what you can pass over the wire via netlabel due to the way the CIPSO information is encoded in the packet.

You can only encode a single sensitivity because the CIPSO spec only stores it in a single integer. s0:c0.c1023 passes fine, but s0-s2:c0.c1023 will get reduced to s0:c0.c1023.

Unlike the sensitivity it is possible to pass some
fairly complex sets of categories. When you create a DOI,
you can specify how the categories will be encoded using a tag of 1, 2, or 5. ( these are bitmap, enumerated and range types respectively ) What categories can be passed via netlabel is dependent on the limits of these types.

The bottom line is that it's entirely possible to have a valid context that netlabel will not be able to fully preserve. Netlabel is still very useful, but you have to remain mindful of its limitations.

Quoted 5 lines

The above is based on my reading of the CIPSO spec and my experience with netlabel. It's entirely possible my understanding is incomplete and/or out of date. Somone like Paul Moore can speak with much greater authority.

HW

I understand CIPSO reasonably well, having been involved in its development back in the late 80's and early 90's*. What I'm looking for is a way to set up an SELinux system that uses CIPSO without having to learn all the gnarly details of SELinux network administration. A sample configuration would be a big help.

Quoted 5 lines
Quoted 4 lines

---
* I was working at Sun, Silicon Graphics and Cray on B1 Unix systems. They used CIPSO long before the RFC was published.

It depends entirely on what you mean by "uses"

I'd be happy with any sort of demo that shows you can preserve separation across the network. It could be as simple as having two services on machine A and two clients on machine B where client B1 can talk to service A1 but not A2 and client B2 can talk to service A2 but not A1. I'm not planning to implement anything in particular, I really just want to see that it can be done. Then I'm going to use it to ensure that changes I make don't break it.

Quoted 20 lines

and I totally get what you mean
when you say you don't want to learn about selinux net admin, but depending on what you want to do, I'm not sure you can get out of it. Paul Moore's blog posts are the best thing I know of but they break everything up into pieces, so AFAIK, there's no single example that is comprehensive. It certainly wasn't easy going for me as there are a lot of parts that need to be set up. I now have what I need in a working state,
but I'm pretty sure at least some of what I've done would have been redundant and unnecessary if I'd just taken the time to define my nodes, booleans, etc... correctly.

For example, I have this intended to allow ping to work:

#============= ping_t ==============
allow ping_t netlabel_peer_t:netif egress;

I did what I expect most people do which is to set it up and see what breaks. My work is definitely not good enough to be an example for others just yet.

HW

#10 lore raw
In reply to Casey Schaufler
Quoted 6 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

I put this together out of idle curiosity using the targeted policy as no policy updates are required only netlabelctl commands. If you need something else like policy config let me know and I'll see what I can do.

Quoted 6 lines

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to Selinux-request@tycho .nsa.gov.

This is a simple CIPSO demo showing that separation across the network is possible where there are two services on machine A and two clients on machine B where client B1 can talk to service A1 but not A2 and client B2 can talk to service A2 but not A1.

The demo shown requires:
1) Two systems with the NETLABEL kernel config and the "targeted" SELinux policy. Used Fedora 24 for demo as this does not require any additional configuration.

2) netlabel_tools and tcpdump installed on each system.

3) Machine "A" requires a server app installed and Machine "B" a client app. I've added the code below that can be copied and built/installed on each machine. Note that the binaries must be labeled bin_t so these were installed in /usr/local/bin.

4) The demo network used:

           ----------  Ethernet         193.168.1.65 ----------
           | A1, A2 | <----------------------------> | B1, B2 |
           ---------- 193.168.1.78                   ----------

Basically the demo configures the network for CIPSO using netlabelctl(8) and then runs the client / server apps using runcon(1) with different levels. Because the targeted policy is being used there is only the single s0 sensitivity with 1024 categories, however I think it does show the basics.

Demo 1 - Just prove the system works
-------------------------------------

On Machine A run a server from a terminal session:
server 9999

On Machine B run a client from a terminal session:
client 193.168.1.78 9999

There should be output from each app with an example client:

client 193.168.1.78 9999
open socket - Peer Context: system_u:object_r:unlabeled_t:s0 connect - No Peer Context Available
recv - No Peer Context Available

Information from Server in RED:
This is Message-1 from the server listening on port: 9999 Client source port: 40152
Server Context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 Server Peer Context: No Peer Context Available

Client Information in GREEN:
Client Context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 Client Peer Context: No Peer Context Available

#### Now exit the server session. ####

Demo 2 - Add cipso config
--------------------------

On Machine A run the following to set up cipso:
netlabelctl cipsov4 add pass doi:15 tags:5
netlabelctl map add domain:unconfined_t address:0.0.0.0/0 protocol:unlbl netlabelctl map add domain:unconfined_t address:193.168.1.65 protocol:cipsov4,15 netlabelctl -p map list

On Machine B run:
netlabelctl cipsov4 add pass doi:15 tags:5
netlabelctl map add domain:unconfined_t address:0.0.0.0/0 protocol:unlbl netlabelctl map add domain:unconfined_t address:193.168.1.78 protocol:cipsov4,15 netlabelctl -p map list

The output from the "netlabelctl -p map list" command should be like:
netlabelctl -p map list
Configured NetLabel domain mappings (2)
domain: "unconfined_t"
address: 193.168.1.78/32
protocol: CIPSOv4, DOI = 15
address: 0.0.0.0/0
protocol: UNLABELED
domain: DEFAULT
protocol: UNLABELED

If okay then run the sessions shown in Demo 3 using "tcpdump -x -i <interface>" to monitor the sessions. There is an example client tcpdump session showing the relevant info after the demos.

Demo 3 - Check cipso network separation.
-----------------------------------------

On Machine A run two servers from separate terminal sessions:
A1
runcon -l s0:c10,c40.c50 server 9999
A2
runcon -l s0:c20,c100.c200 server 1111

On Machine B run two clients from separate terminal sessions:
B1 -> A1
runcon -l s0:c10,c40.c45 client 193.168.1.78 9999 B2 -> A2
runcon -l s0:c20,c100.c200 client 193.168.1.78 1111

There should be valid output from each session, for example:

runcon -l s0:c10,c40.c45 client 193.168.1.78 9999
open socket - Peer Context: system_u:object_r:unlabeled_t:s0 connect - Peer Context: system_u:object_r:netlabel_peer_t:s0:c10,c40.c45 recv - Peer Context: system_u:object_r:netlabel_peer_t:s0:c10,c40.c45

Information from Server in RED:
This is Message-1 from the server listening on port: 9999 Client source port: 40250
Server Context: unconfined_u:unconfined_r:unconfined_t:s0:c10,c40.c50 Server Peer Context: system_u:object_r:netlabel_peer_t:s0:c10,c40.c45

Client Information in GREEN:
Client Context: unconfined_u:unconfined_r:unconfined_t:s0:c10,c40.c45 Client Peer Context: system_u:object_r:netlabel_peer_t:s0:c10,c40.c45

Note that because the client requested cats "c10,c40.c45" that is its process and the client/server netlabel context.

Now try connecting client "B2" client to server "A1" (B2 -> A1):

runcon -l s0:c20,c100.c200 client 193.168.1.78 9999 open socket - Peer Context: system_u:object_r:unlabeled_t:s0 Client connect: No route to host

As can be seen the connection failed. The relevant tcpdump CIPSO info from client B2 in the trace is (see
https://tools.ietf.org/html/draft-ietf-cipso-ipsecurity-01 for details):

x0010: xxxx xxxx 8612 0000 000f 050c 0000 00c8 0064 0014 0014 0000 9cec 270f e7d8 92ff That expands as follows:
86 = Option 134, 12 = Len, 0000 000f = DOI 15, 05 = Tag type, 0c = Tag Len, 00 = Aligment, 00 = Sensitivity s0, 00c8 0064 0014 0014 0000 = category info 200 100 20 20

tcpdump -x -i enp9s0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp9s0, link-type EN10MB (Ethernet), capture size 262144 bytes
12:42:55.302882 IP localhost.localdomain.40172 > 193.168.1.78.distinct: Flags [S], seq 3889730303, win 29200, options [mss 1460,sackOK,TS val 11171752 ecr 0,nop,wscale 7], length 0

	0x0000:  4a00 0050 e557 4000 4006 3def c1a8 0141
	0x0010:  c1a8 014e 8612 0000 000f 050c 0000 00c8
	0x0020:  0064 0014 0014 0000 9cec 270f e7d8 92ff
	0x0030:  0000 0000 a002 7210 860e 0000 0204 05b4
	0x0040:  0402 080a 00aa 77a8 0000 0000 0103 0307
12:42:55.303463 IP 193.168.1.78 > localhost.localdomain: ICMP host 193.168.1.78 unreachable - admin prohibited, length 88
	0x0000:  45c0 006c 39eb 0000 4001 ba06 c1a8 014e
	0x0010:  c1a8 0141 030a 8304 0000 0000 4a00 0050
	0x0020:  e557 4000 4006 3def c1a8 0141 c1a8 014e
	0x0030:  8612 0000 000f 050c 0000 00c8 0064 0014
	0x0040:  0014 0000 9cec 270f e7d8 92ff 0000 0000
	0x0050:  a002 7210 98e9 0000 0204 05b4 0402 080a
	0x0060:  00aa 77a8 0000 0000 0103 0307
12:43:00.307311 ARP, Request who-has localhost.localdomain tell 193.168.1.78, length 46
	0x0000:  0001 0800 0604 0001 74e6 e22b 7789 c1a8
	0x0010:  014e 0000 0000 0000 c1a8 0141 0000 0000
	0x0020:  0000 0000 0000 0000 0000 0000 0000
12:43:00.307340 ARP, Reply localhost.localdomain is-at f0:4d:a2:b5:bc:1d (oui Unknown), length 28
	0x0000:  0001 0800 0604 0002 f04d a2b5 bc1d c1a8
	0x0010:  0141 74e6 e22b 7789 c1a8 014e

Now you can use "runcon -l" to start sessions using different categories to see the effect. However if you try something like:

runcon -l s0:c20,c100.c500 server 1111 runcon -l s0:c20,c100.c500 client 193.168.1.78 1111

The sessions will not talk. I guess it is something to do with the range (need to ask an expert !!!).

#
############################ CLIENT CODE ##################################### #
/* gcc -o client -lselinux client.c
* install -m 0755 client /usr/local/bin/client
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <selinux/selinux.h>

#define MAXBUFFERSIZE 256
#define ENFORCING 1

#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define RESET "\x1b[0m"

int main(int argc, char *argv[])

{
	int sock_fd, bytes_received;
	char buffer[MAXBUFFERSIZE];
	struct hostent *server_info;
	struct sockaddr_in server_addr;
	short client_port;
	char *context, *peer_context, *peer_context_str;

	if (argc != 3) {
		fprintf(stderr, "usage: %s <address> <port>\n", argv[0]);
		exit(1);
	}

	client_port = atoi(argv[2]);

	server_info = gethostbyname(argv[1]);
	if (!server_info) {
		herror("Client gethostbyname");
		exit(1);
	}

	if (security_getenforce() != ENFORCING)
		printf("Should be in enforcing mode for valid testing\n");

	sock_fd = socket(PF_INET, SOCK_STREAM, 0);
	if (sock_fd == -1) {
		perror("Client Socket");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("open socket - No Peer Context Available\n");
	} else {
		printf("open socket - Peer Context: %s\n", peer_context);
		freecon(peer_context);
	}

	bzero((char *) &server_addr, sizeof(server_addr));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(client_port);
	server_addr.sin_addr = *((struct in_addr *)server_info->h_addr);

	if (connect(sock_fd, (struct sockaddr *)&server_addr,
		     sizeof(struct sockaddr)) == -1) {
		perror("Client connect");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("connect - No Peer Context Available\n");
	} else {
		printf("connect - Peer Context: %s\n", peer_context);
		freecon(peer_context);
	}

	memset(buffer, 0, sizeof(buffer));
	bytes_received = recv(sock_fd, buffer, MAXBUFFERSIZE-1, 0);
	if (bytes_received == -1) {
		perror("Client recv");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("recv - No Peer Context Available\n");
	} else {
		printf("recv - Peer Context: %s\n", peer_context);
		freecon(peer_context);
	}

	buffer[bytes_received] = '\0'; /* Add null at end of line. */
	printf("\n%sInformation from Server in RED:\n%s%s\n",
		RED, buffer, RESET);

	/* Print the Clients context information */
	if (getcon(&context) < 0) {
		perror("Client context");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		peer_context_str = strdup("No Peer Context Available");
	} else {
		peer_context_str = strdup(peer_context);
		freecon(peer_context);
	}
	printf("%sClient Information in GREEN:\n", GREEN);
	printf("Client Context: %s\nClient Peer Context: %s%s\n",
		context, peer_context_str, RESET);
	freecon(context);
	close(sock_fd);
	exit(0);
}

#
############################ SERVER CODE #################################### #

/* gcc -o server -lselinux server.c
* install -m 0755 server /usr/local/bin/server
*/

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/types.h>
#include <sys/param.h>
#include <dirent.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <selinux/selinux.h>

#define MAXBUFFERSIZE 256

int main(int argc, char *argv[])

{
	short server_port;
	int sock_fd, new_sock_fd, message_id = 1;
	struct sockaddr_in server_addr;
	struct sockaddr_in client_addr;
	socklen_t sin_size;
	char buffer[MAXBUFFERSIZE];
	char *context, *peer_context;
	char *peer_context_str = NULL;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s <port>\n", argv[0]);
		exit(1);
	}

	server_port = atoi(argv[1]);
	if (server_port == 0) {
		fprintf(stderr, "Usage: %s <port>\n", argv[0]);
		exit(1);
	}

	/* Add port info to send buffer and also display */
	sprintf(buffer, "Listening on port %d", server_port);
	printf("%s\n", buffer);

	sock_fd = socket(PF_INET, SOCK_STREAM, 0);
	if (sock_fd == -1) {
		perror("Server socket");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("open socket - No Peer Context Available\n");
	} else {
		printf("open socket - Peer Context: %s\n", peer_context);
		free(peer_context);
	}

	bzero((char *) &server_addr, sizeof(server_addr));
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(server_port);
	server_addr.sin_addr.s_addr = INADDR_ANY;

	if (bind(sock_fd, (struct sockaddr *)&server_addr,
			    sizeof(struct sockaddr)) == -1) {
		perror("Server bind");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("bind - No Peer Context Available\n");
	} else {
		printf("bind - Peer Context: %s\n", peer_context);
		free(peer_context);
	}

	if (listen(sock_fd, 5) == -1) {
		perror("Server listen");
		exit(1);
	}

	if (getpeercon(sock_fd, &peer_context) < 0) {
		printf("listen - No Peer Context Available\n");
	} else {
		printf("listen - Peer Context: %s\n", peer_context);
		free(peer_context);
	}

	while (1) {
		sin_size = sizeof(struct sockaddr_in);

		new_sock_fd = accept(sock_fd, (struct sockaddr *)&client_addr,
				     &sin_size);
		if (new_sock_fd == -1) {
			perror("Server accept");
			continue;
		}

		/* Get context assigned to the new socket */
		if (fgetfilecon_raw(new_sock_fd, &context) == -1) {
			perror("fgetfilecon_raw - FAILED");
			exit(1);
		}
		printf("accept on new socket - context assigned to new ");
		printf("socket is (using  fgetfilecon):\n\t%s\n", context);
		free(context);

		/* Then check if peer context is assigned to this new socket */
		if (getpeercon(new_sock_fd, &peer_context) < 0) {
			printf("accept new socket - No Peer Context Available\n");
		} else {
			printf("accept new socket - Peer Context: %s\n",
				peer_context);
			free(peer_context);
		}

		/* Get Server context information */
		if (getcon(&context) < 0) {
			perror("Server context");
			exit(1);
		}

		if (getpeercon(new_sock_fd, &peer_context) < 0) {
			peer_context_str = strdup("No Peer Context Available");
		} else {
			peer_context_str = strdup(peer_context);
			free(peer_context);
		}
		/* Clear the buffer of rubbish */
		memset(buffer, 0, sizeof(buffer));

		/* Print Server network information */
		printf("Server has connection from client: host = %s "
			"destination port = %d source port = %d\n",
			inet_ntoa(client_addr.sin_addr),
			ntohs(server_addr.sin_port),
			ntohs(client_addr.sin_port));

		printf("Server Context: %s\nServer Peer Context: %s\n",
			context, peer_context_str);

		/* Now send the buffer. */
		sprintf(buffer, "This is Message-%d from the server listening "
			"on port: %d\nClient source port: %d\n"
			"Server Context: %s\nServer Peer Context: %s\n",
			message_id, ntohs(server_addr.sin_port),
			ntohs(client_addr.sin_port),
			context, peer_context_str);

		if (send(new_sock_fd, buffer, strlen(buffer), 0) == -1)
			perror("Server send");

		message_id++;
		free(context);
		free(peer_context_str);
		close(new_sock_fd);
	}
	return 0;
}
#11 lore raw
Quoted 11 lines · Richard Haines
Quoted 6 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

I put this together out of idle curiosity using the targeted policy as no policy updates are required only netlabelctl commands. If you need something else like policy config let me know and I'll see what I can do.

Hmm...wondering how hard it would be to add this to the selinux-testsuite, possibly run via a new Makefile target separate from the rest of the tests since it requires setting up two machines.

maintainer
#12 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 7 lines · Richard Haines
Quoted 6 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Quoted 8 lines
Quoted 4 lines

I put this together out of idle curiosity using the targeted policy as no policy updates are required only netlabelctl commands. If you need something else like policy config let me know and I'll see what I can do.

Hmm...wondering how hard it would be to add this to the selinux-testsuite, possibly run via a new Makefile target separate from the rest of the tests since it requires setting up two machines.

Thanks for putting that together Richard.

I'm all for inclusion into the selinux-testsuite so long as the default remains single host. However, for the record there is almost *zero* difference between loopback and remote CIPSO communication so long as the standard tags are used; if you use the "local" configuration the code paths are the same, we just do some nasty tricks to pass the full SELinux label (yes, the user:role:type info as well as a ranged MLS label) and intentionally munge the checksum in case the packets ever finds itself on the wire.

I also hope to merge the CALIPSO support into the netlabel_tools package soon, I just need to finish sorting out some completely unrelated audit multicast and queue problems first ...

Signature · 2 lines
paul moore
www.paul-moore.com
#13 lore raw
Quoted 9 lines · Paul Moore
Quoted 8 lines · Stephen Smalley
Quoted 7 lines · Richard Haines
Quoted 6 lines · Casey Schaufler

I am looking for an SELinux configuration that uses CIPSO. Ideally, it would be based on a readily available distro, but I'm willing to perform semi-heroic acts if I have too. I'm not in a position to develop it myself, nor would that really suit my nefarious purposes. Thank you.

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines

I put this together out of idle curiosity using the targeted policy as no policy updates are required only netlabelctl commands. If you need something else like policy config let me know and I'll see what I can do.

Hmm...wondering how hard it would be to add this to the selinux-testsuite, possibly run via a new Makefile target separate from the rest of the tests since it requires setting up two machines.

Thanks for putting that together Richard.

Indeed. I have attached a tarball containing:

- A Makefile for compiling and running the demos
- The programs, in their respective files
- The original message

The programs and Makefile need copyrights and licenses. I've changed the program names so they're less generic. I execute the programs from the current directory rather than installing them in a public place. I have made no effort to make this work anywhere but on Fedora. A cool enhancement would be to auto-detect whether you're running on MachineA or MachineB. Maybe in the next round. I am also thinking about a "one-shot" option in the server and remote execution.'

In any case, this is very helpful. Thank you.

(Bwah Hah Hah)

Quoted 13 lines

I'm all for inclusion into the selinux-testsuite so long as the default remains single host. However, for the record there is almost *zero* difference between loopback and remote CIPSO communication so long as the standard tags are used; if you use the "local" configuration the code paths are the same, we just do some nasty tricks to pass the full SELinux label (yes, the user:role:type info as well as a ranged MLS label) and intentionally munge the checksum in case the packets ever finds itself on the wire.

I also hope to merge the CALIPSO support into the netlabel_tools package soon, I just need to finish sorting out some completely unrelated audit multicast and queue problems first ...