From efa0d7175f0c62dab5f51cbcc84d10a1f291534c Mon Sep 17 00:00:00 2001
From: Chia-chi Yeh <chiachi@android.com>
Date: Tue, 30 Jun 2009 11:23:04 +0800
Subject: [PATCH] net: Replace AID_NET_RAW checks with capable(CAP_NET_RAW).

Signed-off-by: Chia-chi Yeh <chiachi@android.com>
---
 net/ipv4/af_inet.c  | 36 +++++++++++-------------------------
 net/ipv6/af_inet6.c | 36 +++++++++++-------------------------
 2 files changed, 22 insertions(+), 50 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index ad3c54bb0903..109017e82266 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -121,6 +121,16 @@
 
 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
 #include <linux/android_aid.h>
+
+static inline int current_has_network(void)
+{
+	return in_egroup_p(AID_INET) || capable(CAP_NET_RAW);
+}
+#else
+static inline int current_has_network(void)
+{
+	return 1;
+}
 #endif
 
 /* The inetsw table contains everything that inet_create needs to
@@ -273,29 +283,6 @@ void build_ehash_secret(void)
 }
 EXPORT_SYMBOL(build_ehash_secret);
 
-#ifdef CONFIG_ANDROID_PARANOID_NETWORK
-static inline int current_has_network(void)
-{
-	return (!current_euid() || in_egroup_p(AID_INET) ||
-		in_egroup_p(AID_NET_RAW));
-}
-static inline int current_has_cap(struct net *net, int cap)
-{
-	if (cap == CAP_NET_RAW && in_egroup_p(AID_NET_RAW))
-		return 1;
-	return ns_capable(net->user_ns, cap);
-}
-# else
-static inline int current_has_network(void)
-{
-	return 1;
-}
-static inline int current_has_cap(struct net *net, int cap)
-{
-	return ns_capable(net->user_ns, cap);
-}
-#endif
-
 /*
  *	Create an inet socket.
  */
@@ -367,8 +354,7 @@ lookup_protocol:
 	}
 
 	err = -EPERM;
-	if (sock->type == SOCK_RAW && !kern &&
-	    !current_has_cap(net, CAP_NET_RAW))
+	if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
 		goto out_rcu_unlock;
 
 	sock->ops = answer->ops;
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 3257ab81a73f..ebf231016b1f 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -64,6 +64,16 @@
 
 #ifdef CONFIG_ANDROID_PARANOID_NETWORK
 #include <linux/android_aid.h>
+
+static inline int current_has_network(void)
+{
+	return in_egroup_p(AID_INET) || capable(CAP_NET_RAW);
+}
+#else
+static inline int current_has_network(void)
+{
+	return 1;
+}
 #endif
 
 MODULE_AUTHOR("Cast of dozens");
@@ -99,29 +109,6 @@ static __inline__ struct ipv6_pinfo *inet6_sk_generic(struct sock *sk)
 	return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
 }
 
-#ifdef CONFIG_ANDROID_PARANOID_NETWORK
-static inline int current_has_network(void)
-{
-	return (!current_euid() || in_egroup_p(AID_INET) ||
-		in_egroup_p(AID_NET_RAW));
-}
-static inline int current_has_cap(struct net *net, int cap)
-{
-	if (cap == CAP_NET_RAW && in_egroup_p(AID_NET_RAW))
-		return 1;
-	return ns_capable(net->user_ns, cap);
-}
-# else
-static inline int current_has_network(void)
-{
-	return 1;
-}
-static inline int current_has_cap(struct net *net, int cap)
-{
-	return ns_capable(net->user_ns, cap);
-}
-#endif
-
 static int inet6_create(struct net *net, struct socket *sock, int protocol,
 			int kern)
 {
@@ -189,8 +176,7 @@ lookup_protocol:
 	}
 
 	err = -EPERM;
-	if (sock->type == SOCK_RAW && !kern &&
-	    !current_has_cap(net, CAP_NET_RAW))
+	if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
 		goto out_rcu_unlock;
 
 	sock->ops = answer->ops;
-- 
2.34.1