Skip to contentSkip to conversation

iptables

DISCUSSION Russell Coker 2 participants 2 messages Jun 18, 2002 – Jun 20, 2002 SELinux security module

lore
Share & tools
lore
#0 lore raw

It appears that when netfilter reject rules cause an ICMP message, that message has an unlabelled source type...

--
You have received this message because you are subscribed to the selinux list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
Quoted 2 lines · Russell Coker

It appears that when netfilter reject rules cause an ICMP message, that message has an unlabelled source type...

Try the attached patches for lsm-2.4 and selinux and see whether they address your problems with unlabeled IGMP and unlabeled ICMP messages. You will need to install the updated initial_sids file into /usr/lib/selinux prior to rebuilding your policy.

--
Stephen D. Smalley, NAI Labs
[email protected]

Index: security/selinux/hooks.c
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/hooks.c,v retrieving revision 1.9

selinux/hooks.c +61 -3
diff -u -r1.9 hooks.c
@@ -3018,6 +3018,31 @@
 		return NF_DROP;
 	ssec = skb->lsm_security;
 
+	if (ssec->ssid == SECINITSID_UNLABELED) {
+		const struct iphdr *ip = skb->nh.iph;
+
+		if (!skb->sk && ip->protocol == IPPROTO_IGMP) {
+			ssec->ssid = ssec->msid = SECINITSID_IGMP_PACKET;
+		} else if (!skb->sk && ip->protocol == IPPROTO_ICMP) {
+			ssec->ssid = ssec->msid = SECINITSID_ICMP_SOCKET;
+		} else if (net_ratelimit()) {
+			__u16 src_port = 0, dst_port = 0;
+
+			if (ip->protocol == IPPROTO_TCP
+			    || ip->protocol == IPPROTO_UDP) {
+				struct tcphdr *tcp=(struct tcphdr *)((__u32 *)ip+ip->ihl);
+				src_port = ntohs(tcp->source);
+				dst_port = ntohs(tcp->dest);
+			}
+
+			printk(__FUNCTION__ ":  Unlabeled outbound packet\n");
+			printk(__FUNCTION__ ":  PROTO=%d %u.%u.%u.%u:%hu %u.%u.%u.%u:%hu\n",
+			       ip->protocol, NIPQUAD(ip->saddr),
+			       src_port, NIPQUAD(ip->daddr),
+			       dst_port);
+		}
+	}
+
 	if (ssec->invalid) {
 		printk("%s: dropping invalid skb\n", __FUNCTION__);
 		return NF_DROP;
@@ -3082,6 +3107,31 @@
 		return NF_DROP;
 	ssec = skb->lsm_security;
 
+	if (ssec->ssid == SECINITSID_UNLABELED) {
+		const struct iphdr *ip = skb->nh.iph;
+
+		if (!skb->sk && ip->protocol == IPPROTO_IGMP) {
+			ssec->ssid = ssec->msid = SECINITSID_IGMP_PACKET;
+		} else if (!skb->sk && ip->protocol == IPPROTO_ICMP) {
+			ssec->ssid = ssec->msid = SECINITSID_ICMP_SOCKET;
+		} else if (net_ratelimit()) {
+			__u16 src_port = 0, dst_port = 0;
+
+			if (ip->protocol == IPPROTO_TCP
+			    || ip->protocol == IPPROTO_UDP) {
+				struct tcphdr *tcp=(struct tcphdr *)((__u32 *)ip+ip->ihl);
+				src_port = ntohs(tcp->source);
+				dst_port = ntohs(tcp->dest);
+			}
+
+			printk(__FUNCTION__ ":  Unlabeled outbound packet\n");
+			printk(__FUNCTION__ ":  PROTO=%d %u.%u.%u.%u:%hu %u.%u.%u.%u:%hu\n",
+			       ip->protocol, NIPQUAD(ip->saddr),
+			       src_port, NIPQUAD(ip->daddr),
+			       dst_port);
+		}
+	}
+
 	switch (iph->protocol) {
 	case IPPROTO_UDP:
 		netif_perm = NETIF__UDP_SEND;
@@ -4477,16 +4527,22 @@
 			/* TCP socket that has no associated user socket. */
 			ssec->ssid = SECINITSID_TCP_SOCKET;
 			ssec->msid = ssec->ssid;
-		} 
+		} else if (sk->family == PF_INET) {
+			printk(__FUNCTION__ ":  no userspace socket (family %d, type %d, protocol %d)\n", sk->family, sk->type, sk->protocol);
+		}
 		return;
 	}
 		
-	if (!SOCK_INODE(sk->socket)) 
+	if (!SOCK_INODE(sk->socket)) {
+		printk(__FUNCTION__ ":  no inode for socket (family %d, type %d, protocol %d)\n", sk->family, sk->type, sk->protocol);
 		return;
+	}
 			
 	err = inode_precondition(SOCK_INODE(sk->socket));
-	if (err <= 0) 
+	if (err <= 0) {
+		printk(__FUNCTION__ ": inode_precondition failed, err=%d\n", err);
 		return;
+	}
 	isec = SOCK_INODE(sk->socket)->i_security;
 
 	if (isec->sid == SECINITSID_KERNEL || 
@@ -4497,6 +4553,8 @@
 			isec->sid = SECINITSID_TCP_SOCKET;
 		else if (sk->family == PF_INET && sk->protocol == IPPROTO_ICMP)
 			isec->sid = SECINITSID_ICMP_SOCKET;
+		else
+			printk(__FUNCTION__ ":  unrecognized kernel socket (family %d, protocol %d, sid %d)\n", sk->family, sk->protocol, isec->sid);
 	}
 
 	/* Initialize SIDs from the sending socket. */

Index: security/selinux/flask/initial_sids
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/flask/initial_sids,v retrieving revision 1.1.1.2

selinux/flask/initial_sids +1 -0
diff -u -r1.1.1.2 initial_sids
@@ -17,6 +17,7 @@
 sid netif
 sid netmsg
 sid node
+sid igmp_packet
 sid icmp_socket
 sid tcp_socket
 sid proc_kmsg

Index: security/selinux/include/linux/flask/flask.h
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/include/linux/flask/flask.h,v retrieving revision 1.1.1.2

selinux/include/linux/flask/flask.h +22 -21

49 lines not on this page · raw message

Index: security/selinux/include/linux/flask/initial_sid_to_string.h
===================================================================
RCS file: /cvsroot/selinux/nsa/lsm-2.4/security/selinux/include/linux/flask/initial_sid_to_string.h,v retrieving revision 1.1.1.2

selinux/include/linux/flask/initial_sid_to_string.h +1 -0
diff -u -r1.1.1.2 initial_sid_to_string.h
@@ -15,6 +15,7 @@
     "netif",
     "netmsg",
     "node",
+    "igmp_packet",
     "icmp_socket",
     "tcp_socket",
     "proc_kmsg",

Index: policy/initial_sid_contexts
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/initial_sid_contexts,v retrieving revision 1.1.1.2

initial_sid_contexts +1 -0
diff -u -r1.1.1.2 initial_sid_contexts
@@ -17,6 +17,7 @@
 sid netif	system_u:object_r:netif_t
 sid netmsg	system_u:object_r:netmsg_t
 sid node	system_u:object_r:node_t
+sid igmp_packet system_u:system_r:igmp_packet_t
 sid icmp_socket system_u:system_r:icmp_socket_t
 sid tcp_socket  system_u:system_r:tcp_socket_t
 sid proc_kmsg	system_u:object_r:proc_kmsg_t

Index: policy/types/network.te
===================================================================
RCS file: /cvsroot/selinux/nsa/selinux/policy/types/network.te,v retrieving revision 1.1.1.3

types/network.te +3 -0
diff -u -r1.1.1.3 network.te
@@ -19,11 +19,14 @@
 role system_r types any_socket_t;
 
 #
+# igmp_packet_t is the type of kernel-generated IGMP packets.
 # icmp_socket_t is the type of the kernel socket
 # used to send ICMP messages.
 # tcp_socket_t is the type of the kernel socket
 # used to send TCP resets.
 #
+type igmp_packet_t;
+role system_r types igmp_packet_t;
 type icmp_socket_t, socket_type;
 role system_r types icmp_socket_t;
 type tcp_socket_t, socket_type;