Skip to content

Commit 2ee92d4

Browse files
xjamesmorrisDavid S. Miller
authored andcommitted
[SELinux]: Add support for DCCP
This patch implements SELinux kernel support for DCCP (http://linux-net.osdl.org/index.php/DCCP), which is similar in operation to TCP in terms of connected state between peers. The SELinux support for DCCP is thus modeled on existing handling of TCP. A new DCCP socket class is introduced, to allow protocol differentation. The permissions for this class inherit all of the socket permissions, as well as the current TCP permissions (node_bind, name_bind etc). IPv4 and IPv6 are supported, although labeled networking is not, at this stage. Patches for SELinux userspace are at: http://people.redhat.com/jmorris/selinux/dccp/user/ I've performed some basic testing, and it seems to be working as expected. Adding policy support is similar to TCP, the only real difference being that it's a different protocol. Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: James Morris <jmorris@namei.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 90833aa commit 2ee92d4

6 files changed

Lines changed: 103 additions & 8 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <linux/netlink.h>
5959
#include <linux/tcp.h>
6060
#include <linux/udp.h>
61+
#include <linux/dccp.h>
6162
#include <linux/quota.h>
6263
#include <linux/un.h> /* for Unix socket types */
6364
#include <net/af_unix.h> /* for Unix socket types */
@@ -751,6 +752,8 @@ static inline u16 socket_type_to_security_class(int family, int type, int protoc
751752
return SECCLASS_UDP_SOCKET;
752753
else
753754
return SECCLASS_RAWIP_SOCKET;
755+
case SOCK_DCCP:
756+
return SECCLASS_DCCP_SOCKET;
754757
default:
755758
return SECCLASS_RAWIP_SOCKET;
756759
}
@@ -2944,6 +2947,22 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
29442947
break;
29452948
}
29462949

2950+
case IPPROTO_DCCP: {
2951+
struct dccp_hdr _dccph, *dh;
2952+
2953+
if (ntohs(ih->frag_off) & IP_OFFSET)
2954+
break;
2955+
2956+
offset += ihlen;
2957+
dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
2958+
if (dh == NULL)
2959+
break;
2960+
2961+
ad->u.net.sport = dh->dccph_sport;
2962+
ad->u.net.dport = dh->dccph_dport;
2963+
break;
2964+
}
2965+
29472966
default:
29482967
break;
29492968
}
@@ -3004,6 +3023,18 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
30043023
break;
30053024
}
30063025

3026+
case IPPROTO_DCCP: {
3027+
struct dccp_hdr _dccph, *dh;
3028+
3029+
dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
3030+
if (dh == NULL)
3031+
break;
3032+
3033+
ad->u.net.sport = dh->dccph_sport;
3034+
ad->u.net.dport = dh->dccph_dport;
3035+
break;
3036+
}
3037+
30073038
/* includes fragments */
30083039
default:
30093040
break;
@@ -3188,7 +3219,11 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
31883219
case SECCLASS_UDP_SOCKET:
31893220
node_perm = UDP_SOCKET__NODE_BIND;
31903221
break;
3191-
3222+
3223+
case SECCLASS_DCCP_SOCKET:
3224+
node_perm = DCCP_SOCKET__NODE_BIND;
3225+
break;
3226+
31923227
default:
31933228
node_perm = RAWIP_SOCKET__NODE_BIND;
31943229
break;
@@ -3226,16 +3261,17 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
32263261
return err;
32273262

32283263
/*
3229-
* If a TCP socket, check name_connect permission for the port.
3264+
* If a TCP or DCCP socket, check name_connect permission for the port.
32303265
*/
32313266
isec = SOCK_INODE(sock)->i_security;
3232-
if (isec->sclass == SECCLASS_TCP_SOCKET) {
3267+
if (isec->sclass == SECCLASS_TCP_SOCKET ||
3268+
isec->sclass == SECCLASS_DCCP_SOCKET) {
32333269
struct sock *sk = sock->sk;
32343270
struct avc_audit_data ad;
32353271
struct sockaddr_in *addr4 = NULL;
32363272
struct sockaddr_in6 *addr6 = NULL;
32373273
unsigned short snum;
3238-
u32 sid;
3274+
u32 sid, perm;
32393275

32403276
if (sk->sk_family == PF_INET) {
32413277
addr4 = (struct sockaddr_in *)address;
@@ -3254,11 +3290,13 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
32543290
if (err)
32553291
goto out;
32563292

3293+
perm = (isec->sclass == SECCLASS_TCP_SOCKET) ?
3294+
TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
3295+
32573296
AVC_AUDIT_DATA_INIT(&ad,NET);
32583297
ad.u.net.dport = htons(snum);
32593298
ad.u.net.family = sk->sk_family;
3260-
err = avc_has_perm(isec->sid, sid, isec->sclass,
3261-
TCP_SOCKET__NAME_CONNECT, &ad);
3299+
err = avc_has_perm(isec->sid, sid, isec->sclass, perm, &ad);
32623300
if (err)
32633301
goto out;
32643302
}
@@ -3446,7 +3484,13 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
34463484
node_perm = NODE__TCP_RECV;
34473485
recv_perm = TCP_SOCKET__RECV_MSG;
34483486
break;
3449-
3487+
3488+
case SECCLASS_DCCP_SOCKET:
3489+
netif_perm = NETIF__DCCP_RECV;
3490+
node_perm = NODE__DCCP_RECV;
3491+
recv_perm = DCCP_SOCKET__RECV_MSG;
3492+
break;
3493+
34503494
default:
34513495
netif_perm = NETIF__RAWIP_RECV;
34523496
node_perm = NODE__RAWIP_RECV;
@@ -3777,7 +3821,13 @@ static int selinux_ip_postroute_last_compat(struct sock *sk, struct net_device *
37773821
node_perm = NODE__TCP_SEND;
37783822
send_perm = TCP_SOCKET__SEND_MSG;
37793823
break;
3780-
3824+
3825+
case SECCLASS_DCCP_SOCKET:
3826+
netif_perm = NETIF__DCCP_SEND;
3827+
node_perm = NODE__DCCP_SEND;
3828+
send_perm = DCCP_SOCKET__SEND_MSG;
3829+
break;
3830+
37813831
default:
37823832
netif_perm = NETIF__RAWIP_SEND;
37833833
node_perm = NODE__RAWIP_SEND;

‎security/selinux/include/av_inherit.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
S_(SECCLASS_NETLINK_DNRT_SOCKET, socket, 0x00400000UL)
3131
S_(SECCLASS_NETLINK_KOBJECT_UEVENT_SOCKET, socket, 0x00400000UL)
3232
S_(SECCLASS_APPLETALK_SOCKET, socket, 0x00400000UL)
33+
S_(SECCLASS_DCCP_SOCKET, socket, 0x00400000UL)

‎security/selinux/include/av_perm_to_string.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@
3535
S_(SECCLASS_NODE, NODE__RAWIP_RECV, "rawip_recv")
3636
S_(SECCLASS_NODE, NODE__RAWIP_SEND, "rawip_send")
3737
S_(SECCLASS_NODE, NODE__ENFORCE_DEST, "enforce_dest")
38+
S_(SECCLASS_NODE, NODE__DCCP_RECV, "dccp_recv")
39+
S_(SECCLASS_NODE, NODE__DCCP_SEND, "dccp_send")
3840
S_(SECCLASS_NETIF, NETIF__TCP_RECV, "tcp_recv")
3941
S_(SECCLASS_NETIF, NETIF__TCP_SEND, "tcp_send")
4042
S_(SECCLASS_NETIF, NETIF__UDP_RECV, "udp_recv")
4143
S_(SECCLASS_NETIF, NETIF__UDP_SEND, "udp_send")
4244
S_(SECCLASS_NETIF, NETIF__RAWIP_RECV, "rawip_recv")
4345
S_(SECCLASS_NETIF, NETIF__RAWIP_SEND, "rawip_send")
46+
S_(SECCLASS_NETIF, NETIF__DCCP_RECV, "dccp_recv")
47+
S_(SECCLASS_NETIF, NETIF__DCCP_SEND, "dccp_send")
4448
S_(SECCLASS_UNIX_STREAM_SOCKET, UNIX_STREAM_SOCKET__CONNECTTO, "connectto")
4549
S_(SECCLASS_UNIX_STREAM_SOCKET, UNIX_STREAM_SOCKET__NEWCONN, "newconn")
4650
S_(SECCLASS_UNIX_STREAM_SOCKET, UNIX_STREAM_SOCKET__ACCEPTFROM, "acceptfrom")
@@ -252,3 +256,7 @@
252256
S_(SECCLASS_KEY, KEY__LINK, "link")
253257
S_(SECCLASS_KEY, KEY__SETATTR, "setattr")
254258
S_(SECCLASS_KEY, KEY__CREATE, "create")
259+
S_(SECCLASS_CONTEXT, CONTEXT__TRANSLATE, "translate")
260+
S_(SECCLASS_CONTEXT, CONTEXT__CONTAINS, "contains")
261+
S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NODE_BIND, "node_bind")
262+
S_(SECCLASS_DCCP_SOCKET, DCCP_SOCKET__NAME_CONNECT, "name_connect")

‎security/selinux/include/av_permissions.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,17 @@
312312
#define NODE__RAWIP_RECV 0x00000010UL
313313
#define NODE__RAWIP_SEND 0x00000020UL
314314
#define NODE__ENFORCE_DEST 0x00000040UL
315+
#define NODE__DCCP_RECV 0x00000080UL
316+
#define NODE__DCCP_SEND 0x00000100UL
315317

316318
#define NETIF__TCP_RECV 0x00000001UL
317319
#define NETIF__TCP_SEND 0x00000002UL
318320
#define NETIF__UDP_RECV 0x00000004UL
319321
#define NETIF__UDP_SEND 0x00000008UL
320322
#define NETIF__RAWIP_RECV 0x00000010UL
321323
#define NETIF__RAWIP_SEND 0x00000020UL
324+
#define NETIF__DCCP_RECV 0x00000040UL
325+
#define NETIF__DCCP_SEND 0x00000080UL
322326

323327
#define NETLINK_SOCKET__IOCTL 0x00000001UL
324328
#define NETLINK_SOCKET__READ 0x00000002UL
@@ -970,3 +974,31 @@
970974
#define KEY__LINK 0x00000010UL
971975
#define KEY__SETATTR 0x00000020UL
972976
#define KEY__CREATE 0x00000040UL
977+
978+
#define CONTEXT__TRANSLATE 0x00000001UL
979+
#define CONTEXT__CONTAINS 0x00000002UL
980+
981+
#define DCCP_SOCKET__IOCTL 0x00000001UL
982+
#define DCCP_SOCKET__READ 0x00000002UL
983+
#define DCCP_SOCKET__WRITE 0x00000004UL
984+
#define DCCP_SOCKET__CREATE 0x00000008UL
985+
#define DCCP_SOCKET__GETATTR 0x00000010UL
986+
#define DCCP_SOCKET__SETATTR 0x00000020UL
987+
#define DCCP_SOCKET__LOCK 0x00000040UL
988+
#define DCCP_SOCKET__RELABELFROM 0x00000080UL
989+
#define DCCP_SOCKET__RELABELTO 0x00000100UL
990+
#define DCCP_SOCKET__APPEND 0x00000200UL
991+
#define DCCP_SOCKET__BIND 0x00000400UL
992+
#define DCCP_SOCKET__CONNECT 0x00000800UL
993+
#define DCCP_SOCKET__LISTEN 0x00001000UL
994+
#define DCCP_SOCKET__ACCEPT 0x00002000UL
995+
#define DCCP_SOCKET__GETOPT 0x00004000UL
996+
#define DCCP_SOCKET__SETOPT 0x00008000UL
997+
#define DCCP_SOCKET__SHUTDOWN 0x00010000UL
998+
#define DCCP_SOCKET__RECVFROM 0x00020000UL
999+
#define DCCP_SOCKET__SENDTO 0x00040000UL
1000+
#define DCCP_SOCKET__RECV_MSG 0x00080000UL
1001+
#define DCCP_SOCKET__SEND_MSG 0x00100000UL
1002+
#define DCCP_SOCKET__NAME_BIND 0x00200000UL
1003+
#define DCCP_SOCKET__NODE_BIND 0x00400000UL
1004+
#define DCCP_SOCKET__NAME_CONNECT 0x00800000UL

‎security/selinux/include/class_to_string.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@
6161
S_("appletalk_socket")
6262
S_("packet")
6363
S_("key")
64+
S_("context")
65+
S_("dccp_socket")

‎security/selinux/include/flask.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#define SECCLASS_APPLETALK_SOCKET 56
6464
#define SECCLASS_PACKET 57
6565
#define SECCLASS_KEY 58
66+
#define SECCLASS_CONTEXT 59
67+
#define SECCLASS_DCCP_SOCKET 60
6668

6769
/*
6870
* Security identifier indices for initial entities

0 commit comments

Comments
 (0)