Skip to content

Commit 8d9107e

Browse files
author
Linus Torvalds
committed
Revert "SELinux: use SECINITSID_NETMSG instead of SECINITSID_UNLABELED for NetLabel"
This reverts commit 9faf65f. It bit people like Michal Piotrowski: "My system is too secure, I can not login :)" because it changed how CONFIG_NETLABEL worked, and broke older SElinux policies. As a result, quoth James Morris: "Can you please revert this patch? We thought it only affected people running MLS, but it will affect others. Sorry for the hassle." Cc: James Morris <[email protected]> Cc: Stephen Smalley <[email protected]> Cc: Michal Piotrowski <[email protected]> Cc: Paul Moore <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 16cefa8 commit 8d9107e

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

security/selinux/hooks.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -3129,29 +3129,28 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,
31293129
/**
31303130
* selinux_skb_extlbl_sid - Determine the external label of a packet
31313131
* @skb: the packet
3132+
* @base_sid: the SELinux SID to use as a context for MLS only external labels
31323133
* @sid: the packet's SID
31333134
*
31343135
* Description:
31353136
* Check the various different forms of external packet labeling and determine
3136-
* the external SID for the packet. If only one form of external labeling is
3137-
* present then it is used, if both labeled IPsec and NetLabel labels are
3138-
* present then the SELinux type information is taken from the labeled IPsec
3139-
* SA and the MLS sensitivity label information is taken from the NetLabel
3140-
* security attributes. This bit of "magic" is done in the call to
3141-
* selinux_netlbl_skbuff_getsid().
3137+
* the external SID for the packet.
31423138
*
31433139
*/
3144-
static void selinux_skb_extlbl_sid(struct sk_buff *skb, u32 *sid)
3140+
static void selinux_skb_extlbl_sid(struct sk_buff *skb,
3141+
u32 base_sid,
3142+
u32 *sid)
31453143
{
31463144
u32 xfrm_sid;
31473145
u32 nlbl_sid;
31483146

31493147
selinux_skb_xfrm_sid(skb, &xfrm_sid);
31503148
if (selinux_netlbl_skbuff_getsid(skb,
31513149
(xfrm_sid == SECSID_NULL ?
3152-
SECINITSID_NETMSG : xfrm_sid),
3150+
base_sid : xfrm_sid),
31533151
&nlbl_sid) != 0)
31543152
nlbl_sid = SECSID_NULL;
3153+
31553154
*sid = (nlbl_sid == SECSID_NULL ? xfrm_sid : nlbl_sid);
31563155
}
31573156

@@ -3696,7 +3695,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
36963695
if (sock && sock->sk->sk_family == PF_UNIX)
36973696
selinux_get_inode_sid(SOCK_INODE(sock), &peer_secid);
36983697
else if (skb)
3699-
selinux_skb_extlbl_sid(skb, &peer_secid);
3698+
selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &peer_secid);
37003699

37013700
if (peer_secid == SECSID_NULL)
37023701
err = -EINVAL;
@@ -3757,7 +3756,7 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
37573756
u32 newsid;
37583757
u32 peersid;
37593758

3760-
selinux_skb_extlbl_sid(skb, &peersid);
3759+
selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &peersid);
37613760
if (peersid == SECSID_NULL) {
37623761
req->secid = sksec->sid;
37633762
req->peer_secid = SECSID_NULL;
@@ -3795,7 +3794,7 @@ static void selinux_inet_conn_established(struct sock *sk,
37953794
{
37963795
struct sk_security_struct *sksec = sk->sk_security;
37973796

3798-
selinux_skb_extlbl_sid(skb, &sksec->peer_sid);
3797+
selinux_skb_extlbl_sid(skb, SECINITSID_UNLABELED, &sksec->peer_sid);
37993798
}
38003799

38013800
static void selinux_req_classify_flow(const struct request_sock *req,

security/selinux/netlabel.c

+21-13
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ int selinux_netlbl_skbuff_getsid(struct sk_buff *skb, u32 base_sid, u32 *sid)
158158
netlbl_secattr_init(&secattr);
159159
rc = netlbl_skbuff_getattr(skb, &secattr);
160160
if (rc == 0 && secattr.flags != NETLBL_SECATTR_NONE)
161-
rc = security_netlbl_secattr_to_sid(&secattr, base_sid, sid);
161+
rc = security_netlbl_secattr_to_sid(&secattr,
162+
base_sid,
163+
sid);
162164
else
163165
*sid = SECSID_NULL;
164166
netlbl_secattr_destroy(&secattr);
@@ -196,7 +198,7 @@ void selinux_netlbl_sock_graft(struct sock *sk, struct socket *sock)
196198
if (netlbl_sock_getattr(sk, &secattr) == 0 &&
197199
secattr.flags != NETLBL_SECATTR_NONE &&
198200
security_netlbl_secattr_to_sid(&secattr,
199-
SECINITSID_NETMSG,
201+
SECINITSID_UNLABELED,
200202
&nlbl_peer_sid) == 0)
201203
sksec->peer_sid = nlbl_peer_sid;
202204
netlbl_secattr_destroy(&secattr);
@@ -293,32 +295,38 @@ int selinux_netlbl_sock_rcv_skb(struct sk_security_struct *sksec,
293295
struct avc_audit_data *ad)
294296
{
295297
int rc;
296-
u32 nlbl_sid;
297-
u32 perm;
298+
u32 netlbl_sid;
299+
u32 recv_perm;
298300

299-
rc = selinux_netlbl_skbuff_getsid(skb, SECINITSID_NETMSG, &nlbl_sid);
301+
rc = selinux_netlbl_skbuff_getsid(skb,
302+
SECINITSID_UNLABELED,
303+
&netlbl_sid);
300304
if (rc != 0)
301305
return rc;
302-
if (nlbl_sid == SECSID_NULL)
303-
nlbl_sid = SECINITSID_UNLABELED;
306+
307+
if (netlbl_sid == SECSID_NULL)
308+
return 0;
304309

305310
switch (sksec->sclass) {
306311
case SECCLASS_UDP_SOCKET:
307-
perm = UDP_SOCKET__RECVFROM;
312+
recv_perm = UDP_SOCKET__RECVFROM;
308313
break;
309314
case SECCLASS_TCP_SOCKET:
310-
perm = TCP_SOCKET__RECVFROM;
315+
recv_perm = TCP_SOCKET__RECVFROM;
311316
break;
312317
default:
313-
perm = RAWIP_SOCKET__RECVFROM;
318+
recv_perm = RAWIP_SOCKET__RECVFROM;
314319
}
315320

316-
rc = avc_has_perm(sksec->sid, nlbl_sid, sksec->sclass, perm, ad);
321+
rc = avc_has_perm(sksec->sid,
322+
netlbl_sid,
323+
sksec->sclass,
324+
recv_perm,
325+
ad);
317326
if (rc == 0)
318327
return 0;
319328

320-
if (nlbl_sid != SECINITSID_UNLABELED)
321-
netlbl_skbuff_err(skb, rc);
329+
netlbl_skbuff_err(skb, rc);
322330
return rc;
323331
}
324332

0 commit comments

Comments
 (0)