procfs: Push down the bkl from ioctl
[safe/jmp/linux-2.6] / net / x25 / af_x25.c
index 39ce03e..9796f3e 100644 (file)
@@ -55,6 +55,7 @@
 #include <linux/notifier.h>
 #include <linux/init.h>
 #include <linux/compat.h>
+#include <linux/ctype.h>
 
 #include <net/x25.h>
 #include <net/compat.h>
@@ -512,15 +513,20 @@ static int x25_create(struct net *net, struct socket *sock, int protocol,
 {
        struct sock *sk;
        struct x25_sock *x25;
-       int rc = -ESOCKTNOSUPPORT;
+       int rc = -EAFNOSUPPORT;
 
-       if (net != &init_net)
-               return -EAFNOSUPPORT;
+       if (!net_eq(net, &init_net))
+               goto out;
+
+       rc = -ESOCKTNOSUPPORT;
+       if (sock->type != SOCK_SEQPACKET)
+               goto out;
 
-       if (sock->type != SOCK_SEQPACKET || protocol)
+       rc = -EINVAL;
+       if (protocol)
                goto out;
 
-       rc = -ENOMEM;
+       rc = -ENOBUFS;
        if ((sk = x25_alloc_socket(net)) == NULL)
                goto out;
 
@@ -643,7 +649,7 @@ static int x25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
 {
        struct sock *sk = sock->sk;
        struct sockaddr_x25 *addr = (struct sockaddr_x25 *)uaddr;
-       int rc = 0;
+       int len, i, rc = 0;
 
        lock_kernel();
        if (!sock_flag(sk, SOCK_ZAPPED) ||
@@ -653,6 +659,14 @@ static int x25_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
                goto out;
        }
 
+       len = strlen(addr->sx25_addr.x25_addr);
+       for (i = 0; i < len; i++) {
+               if (!isdigit(addr->sx25_addr.x25_addr[i])) {
+                       rc = -EINVAL;
+                       goto out;
+               }
+       }
+
        x25_sk(sk)->source_addr = addr->sx25_addr;
        x25_insert_socket(sk);
        sock_reset_flag(sk, SOCK_ZAPPED);
@@ -1471,6 +1485,17 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
                        break;
                }
 
+               case SIOCX25SCAUSEDIAG: {
+                       struct x25_causediag causediag;
+                       rc = -EFAULT;
+                       if (copy_from_user(&causediag, argp, sizeof(causediag)))
+                               break;
+                       x25->causediag = causediag;
+                       rc = 0;
+                       break;
+
+               }
+
                case SIOCX25SCUDMATCHLEN: {
                        struct x25_subaddr sub_addr;
                        rc = -EINVAL;
@@ -1639,6 +1664,7 @@ static int compat_x25_ioctl(struct socket *sock, unsigned int cmd,
        case SIOCX25GCALLUSERDATA:
        case SIOCX25SCALLUSERDATA:
        case SIOCX25GCAUSEDIAG:
+       case SIOCX25SCAUSEDIAG:
        case SIOCX25SCUDMATCHLEN:
        case SIOCX25CALLACCPTAPPRV:
        case SIOCX25SENDCALLACCPT:
@@ -1709,20 +1735,31 @@ static int __init x25_init(void)
        if (rc != 0)
                goto out;
 
-       sock_register(&x25_family_ops);
+       rc = sock_register(&x25_family_ops);
+       if (rc != 0)
+               goto out_proto;
 
        dev_add_pack(&x25_packet_type);
 
-       register_netdevice_notifier(&x25_dev_notifier);
+       rc = register_netdevice_notifier(&x25_dev_notifier);
+       if (rc != 0)
+               goto out_sock;
 
        printk(KERN_INFO "X.25 for Linux Version 0.2\n");
 
-#ifdef CONFIG_SYSCTL
        x25_register_sysctl();
-#endif
-       x25_proc_init();
+       rc = x25_proc_init();
+       if (rc != 0)
+               goto out_dev;
 out:
        return rc;
+out_dev:
+       unregister_netdevice_notifier(&x25_dev_notifier);
+out_sock:
+       sock_unregister(AF_X25);
+out_proto:
+       proto_unregister(&x25_proto);
+       goto out;
 }
 module_init(x25_init);
 
@@ -1732,9 +1769,7 @@ static void __exit x25_exit(void)
        x25_link_free();
        x25_route_free();
 
-#ifdef CONFIG_SYSCTL
        x25_unregister_sysctl();
-#endif
 
        unregister_netdevice_notifier(&x25_dev_notifier);