net: Replace AID_NET_RAW checks with capable(CAP_NET_RAW).
authorChia-chi Yeh <chiachi@android.com>
Tue, 30 Jun 2009 03:23:04 +0000 (11:23 +0800)
committerJohn Stultz <john.stultz@linaro.org>
Tue, 16 Feb 2016 21:51:14 +0000 (13:51 -0800)
Signed-off-by: Chia-chi Yeh <chiachi@android.com>
net/ipv4/af_inet.c
net/ipv6/af_inet6.c

index ac822c7bd55d01ef0e2539657169ae564e62991f..eb12bd0ff9d336c801c89197989ed75ce6c38b9b 100644 (file)
 
 #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
@@ -245,29 +255,6 @@ out:
 }
 EXPORT_SYMBOL(inet_listen);
 
-#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.
  */
@@ -337,8 +324,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;
index b6d7882fbb660ec17143bf5d1c723eab2b189541..9dbfacb6e0d9266ff358bad85ad7e061e16d9e8b 100644 (file)
 
 #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");
@@ -101,29 +111,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)
 {
@@ -188,8 +175,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;