Created attachment 918084 [details]
 kernel panic. Bottom of the panic screen
# Description of problem:
While using network with configured Netlabel it may lead to kernel panic on some SELinux levels.
# Version-Release number of selected component (if applicable):
kernel: Linux rhel7 3.10.0-123.el7.x86_64
Also I reproduced it on RHEL 6.3/7.0, CentOs 6.5/7.0, Fedora 20. That is what I have been tested. I think it can be reproduced on older versions/kernels too.
# How reproducible:
# Steps to Reproduce:
1. Setup NetLabel. [Assume that 192.168.56.* --- local network (VBox HostOnly, for example) ]
# netlabelctl cipsov4 add pass doi:1 tags:5
# netlabelctl map del default
# netlabelctl map add default address:0.0.0.0/0 protocol:unlbl
# netlabelctl map add default address:192.168.56.101/16 protocol:cipsov4,1
2. Give some user selinux range s0:c0.c1023. selevel not so important. All the matter in categories
# semanage user -mr s0-s0:c0.c1023 user_u
# semanage login -s user_u -mr s0-s0:c0.c1023 myuser1
# setenforce 1 (just in case)
3. Login with `myuser1`, change selinux level and ping someone in your local network
$ newrole -l s0:c255,c800
$ ping 192.168.56.1 (some another PC)
# Actual results:
It will lead to kernel panic. See screenshot 1.
If not, exit and try with another level (see Additional info).
# Expected results:
Receive ping reply (marked one, due to NetLabel configured).
# Additional info:
RHEL fails with all of this levels:
8. ... (I think, there are more of them)
CentOs and Fedora sometimes fails not with first, but with second or third one.
I used kdump to debug this crash and it looks like there are problems in netlbl_secattr_catmap_setrng() and netlbl_secattr_catmap_setbit() function, because of
"BUG: unablle to handle kernel paging request at ... from netlbl_secattr_catmap_setbit" (from logs).
Confirming that I've been able to reproduce this problem on kernel-3.10.0-131.el7.x86_64 using the instructions above.
I've identified at least one problem: the NetLabel secattr catmap functions not correctly setting bits if the new bit is less than the starting bit of the first structure instance. There may be more problems as well, but this is perhaps the most significant.
(In reply to Paul Moore from comment #3)
> I've identified at least one problem: the NetLabel secattr catmap functions
> not correctly setting bits if the new bit is less than the starting bit of
> the first structure instance.
Yup. Also, due to Cipso RFC 22.214.171.124 
"The ranges MUST be non-overlapping and be listed in
It looks like the logic is wrong, if we meet, say, c900, then c500 and then c100,
because we will stop on the wrong block. Maybe my patch will help you to find all issues.
I've already fixed the problem with the catmap correctly setting bits below the first starting bit, but there are some other issues that need to be corrected as well.
Created attachment 923017 [details]
Created attachment 923018 [details]
Created attachment 923019 [details]
Created attachment 923020 [details]
The attached four patches should resolve the problem reported by the original reporter as well as a number of other issues found in the course of fixing this problem. However, I should note that these patches have only gone through the most basic of testing and therefore are not yet suitable for submission upstream or inclusion in RHEL7. I'm posting them here in case anyone is interested in the problem and wanted to help test a potential solution.
Finally, these patches are based against Linux v3.15 and not the RHEL7 kernel so there will be some backporting needed.
Also, patch #4 is not strictly necessary but I will be including it in the patchset I publish upstream so I've included here for reference.
Upstream patchset posting:
FYI, I've merged this into the SELinux tree for 3.17 and sent another pull request. As soon as the tree is (re)pulled into the linux-security tree I'll update this BZ and start backporting.
Patch(es) available on kernel-3.10.0-183.el7
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.
For information on the advisory, and where to find the updated
files, follow the link below.
If the solution does not work for you, open a new bug report.