diff options
Diffstat (limited to 'net/unix/af_unix.c')
| -rw-r--r-- | net/unix/af_unix.c | 38 | 
1 files changed, 17 insertions, 21 deletions
| diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 0722a25a3a33..ec68e1c05b85 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
| @@ -808,8 +808,9 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
| 808 | struct net *net = sock_net(sk); | 808 | struct net *net = sock_net(sk); | 
| 809 | struct unix_sock *u = unix_sk(sk); | 809 | struct unix_sock *u = unix_sk(sk); | 
| 810 | struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; | 810 | struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; | 
| 811 | char *sun_path = sunaddr->sun_path; | ||
| 811 | struct dentry *dentry = NULL; | 812 | struct dentry *dentry = NULL; | 
| 812 | struct nameidata nd; | 813 | struct path path; | 
| 813 | int err; | 814 | int err; | 
| 814 | unsigned hash; | 815 | unsigned hash; | 
| 815 | struct unix_address *addr; | 816 | struct unix_address *addr; | 
| @@ -845,48 +846,44 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) | |||
| 845 | addr->hash = hash ^ sk->sk_type; | 846 | addr->hash = hash ^ sk->sk_type; | 
| 846 | atomic_set(&addr->refcnt, 1); | 847 | atomic_set(&addr->refcnt, 1); | 
| 847 | 848 | ||
| 848 | if (sunaddr->sun_path[0]) { | 849 | if (sun_path[0]) { | 
| 849 | unsigned int mode; | 850 | unsigned int mode; | 
| 850 | err = 0; | 851 | err = 0; | 
| 851 | /* | 852 | /* | 
| 852 | * Get the parent directory, calculate the hash for last | 853 | * Get the parent directory, calculate the hash for last | 
| 853 | * component. | 854 | * component. | 
| 854 | */ | 855 | */ | 
| 855 | err = kern_path_parent(sunaddr->sun_path, &nd); | 856 | dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0); | 
| 856 | if (err) | ||
| 857 | goto out_mknod_parent; | ||
| 858 | |||
| 859 | dentry = lookup_create(&nd, 0); | ||
| 860 | err = PTR_ERR(dentry); | 857 | err = PTR_ERR(dentry); | 
| 861 | if (IS_ERR(dentry)) | 858 | if (IS_ERR(dentry)) | 
| 862 | goto out_mknod_unlock; | 859 | goto out_mknod_parent; | 
| 863 | 860 | ||
| 864 | /* | 861 | /* | 
| 865 | * All right, let's create it. | 862 | * All right, let's create it. | 
| 866 | */ | 863 | */ | 
| 867 | mode = S_IFSOCK | | 864 | mode = S_IFSOCK | | 
| 868 | (SOCK_INODE(sock)->i_mode & ~current_umask()); | 865 | (SOCK_INODE(sock)->i_mode & ~current_umask()); | 
| 869 | err = mnt_want_write(nd.path.mnt); | 866 | err = mnt_want_write(path.mnt); | 
| 870 | if (err) | 867 | if (err) | 
| 871 | goto out_mknod_dput; | 868 | goto out_mknod_dput; | 
| 872 | err = security_path_mknod(&nd.path, dentry, mode, 0); | 869 | err = security_path_mknod(&path, dentry, mode, 0); | 
| 873 | if (err) | 870 | if (err) | 
| 874 | goto out_mknod_drop_write; | 871 | goto out_mknod_drop_write; | 
| 875 | err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0); | 872 | err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0); | 
| 876 | out_mknod_drop_write: | 873 | out_mknod_drop_write: | 
| 877 | mnt_drop_write(nd.path.mnt); | 874 | mnt_drop_write(path.mnt); | 
| 878 | if (err) | 875 | if (err) | 
| 879 | goto out_mknod_dput; | 876 | goto out_mknod_dput; | 
| 880 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); | 877 | mutex_unlock(&path.dentry->d_inode->i_mutex); | 
| 881 | dput(nd.path.dentry); | 878 | dput(path.dentry); | 
| 882 | nd.path.dentry = dentry; | 879 | path.dentry = dentry; | 
| 883 | 880 | ||
| 884 | addr->hash = UNIX_HASH_SIZE; | 881 | addr->hash = UNIX_HASH_SIZE; | 
| 885 | } | 882 | } | 
| 886 | 883 | ||
| 887 | spin_lock(&unix_table_lock); | 884 | spin_lock(&unix_table_lock); | 
| 888 | 885 | ||
| 889 | if (!sunaddr->sun_path[0]) { | 886 | if (!sun_path[0]) { | 
| 890 | err = -EADDRINUSE; | 887 | err = -EADDRINUSE; | 
| 891 | if (__unix_find_socket_byname(net, sunaddr, addr_len, | 888 | if (__unix_find_socket_byname(net, sunaddr, addr_len, | 
| 892 | sk->sk_type, hash)) { | 889 | sk->sk_type, hash)) { | 
| @@ -897,8 +894,8 @@ out_mknod_drop_write: | |||
| 897 | list = &unix_socket_table[addr->hash]; | 894 | list = &unix_socket_table[addr->hash]; | 
| 898 | } else { | 895 | } else { | 
| 899 | list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)]; | 896 | list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)]; | 
| 900 | u->dentry = nd.path.dentry; | 897 | u->dentry = path.dentry; | 
| 901 | u->mnt = nd.path.mnt; | 898 | u->mnt = path.mnt; | 
| 902 | } | 899 | } | 
| 903 | 900 | ||
| 904 | err = 0; | 901 | err = 0; | 
| @@ -915,9 +912,8 @@ out: | |||
| 915 | 912 | ||
| 916 | out_mknod_dput: | 913 | out_mknod_dput: | 
| 917 | dput(dentry); | 914 | dput(dentry); | 
| 918 | out_mknod_unlock: | 915 | mutex_unlock(&path.dentry->d_inode->i_mutex); | 
| 919 | mutex_unlock(&nd.path.dentry->d_inode->i_mutex); | 916 | path_put(&path); | 
| 920 | path_put(&nd.path); | ||
| 921 | out_mknod_parent: | 917 | out_mknod_parent: | 
| 922 | if (err == -EEXIST) | 918 | if (err == -EEXIST) | 
| 923 | err = -EADDRINUSE; | 919 | err = -EADDRINUSE; | 
