aboutsummaryrefslogtreecommitdiffstats
path: root/net/unix/af_unix.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-01-06 19:15:03 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-06 19:15:03 -0500
commit51cb67c0b0fcb91581b15bd2e85f29af4d4b2df6 (patch)
tree2696e99342df5dedaa2226d7d72c4ff1668ee120 /net/unix/af_unix.c
parentee9a7d2cb0cf1a1498478bc923d911f3d9c910ac (diff)
parent8b8a321ff72c785ed5e8b4cf6eda20b35d427390 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
Pull networking fixes from David Miller: "As usual, there are a couple straggler bug fixes: 1) qlcnic_alloc_mbx_args() error returns are not checked in qlcnic driver. Fix from Insu Yun. 2) SKB refcounting bug in connector, from Florian Westphal. 3) vrf_get_saddr() has to propagate fib_lookup() errors to it's callers, from David Ahern. 4) Fix AF_UNIX splice/bind deadlock, from Rainer Weikusat. 5) qdisc_rcu_free() fails to free the per-cpu qstats. Fix from John Fastabend. 6) vmxnet3 driver passes wrong page to dma_map_page(), fix from Shrikrishna Khare. 7) Don't allow zero cwnd in tcp_cwnd_reduction(), from Yuchung Cheng" * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net: tcp: fix zero cwnd in tcp_cwnd_reduction Driver: Vmxnet3: Fix regression caused by 5738a09 net: qmi_wwan: Add WeTelecom-WPD600N mkiss: fix scribble on freed memory net: possible use after free in dst_release net: sched: fix missing free per cpu on qstats ARM: net: bpf: fix zero right shift 6pack: fix free memory scribbles net: filter: make JITs zero A for SKF_AD_ALU_XOR_X bridge: Only call /sbin/bridge-stp for the initial network namespace af_unix: Fix splice-bind deadlock net: Propagate lookup failure in l3mdev_get_saddr to caller r8152: add reset_resume function connector: bump skb->users before callback invocation cxgb4: correctly handling failed allocation qlcnic: correctly handle qlcnic_alloc_mbx_args
Diffstat (limited to 'net/unix/af_unix.c')
-rw-r--r--net/unix/af_unix.c66
1 files changed, 40 insertions, 26 deletions
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index a4631477cedf..ef05cd9403d4 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -953,32 +953,20 @@ fail:
953 return NULL; 953 return NULL;
954} 954}
955 955
956static int unix_mknod(const char *sun_path, umode_t mode, struct path *res) 956static int unix_mknod(struct dentry *dentry, struct path *path, umode_t mode,
957 struct path *res)
957{ 958{
958 struct dentry *dentry; 959 int err;
959 struct path path;
960 int err = 0;
961 /*
962 * Get the parent directory, calculate the hash for last
963 * component.
964 */
965 dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0);
966 err = PTR_ERR(dentry);
967 if (IS_ERR(dentry))
968 return err;
969 960
970 /* 961 err = security_path_mknod(path, dentry, mode, 0);
971 * All right, let's create it.
972 */
973 err = security_path_mknod(&path, dentry, mode, 0);
974 if (!err) { 962 if (!err) {
975 err = vfs_mknod(d_inode(path.dentry), dentry, mode, 0); 963 err = vfs_mknod(d_inode(path->dentry), dentry, mode, 0);
976 if (!err) { 964 if (!err) {
977 res->mnt = mntget(path.mnt); 965 res->mnt = mntget(path->mnt);
978 res->dentry = dget(dentry); 966 res->dentry = dget(dentry);
979 } 967 }
980 } 968 }
981 done_path_create(&path, dentry); 969
982 return err; 970 return err;
983} 971}
984 972
@@ -989,10 +977,12 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
989 struct unix_sock *u = unix_sk(sk); 977 struct unix_sock *u = unix_sk(sk);
990 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr; 978 struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
991 char *sun_path = sunaddr->sun_path; 979 char *sun_path = sunaddr->sun_path;
992 int err; 980 int err, name_err;
993 unsigned int hash; 981 unsigned int hash;
994 struct unix_address *addr; 982 struct unix_address *addr;
995 struct hlist_head *list; 983 struct hlist_head *list;
984 struct path path;
985 struct dentry *dentry;
996 986
997 err = -EINVAL; 987 err = -EINVAL;
998 if (sunaddr->sun_family != AF_UNIX) 988 if (sunaddr->sun_family != AF_UNIX)
@@ -1008,14 +998,34 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1008 goto out; 998 goto out;
1009 addr_len = err; 999 addr_len = err;
1010 1000
1001 name_err = 0;
1002 dentry = NULL;
1003 if (sun_path[0]) {
1004 /* Get the parent directory, calculate the hash for last
1005 * component.
1006 */
1007 dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0);
1008
1009 if (IS_ERR(dentry)) {
1010 /* delay report until after 'already bound' check */
1011 name_err = PTR_ERR(dentry);
1012 dentry = NULL;
1013 }
1014 }
1015
1011 err = mutex_lock_interruptible(&u->readlock); 1016 err = mutex_lock_interruptible(&u->readlock);
1012 if (err) 1017 if (err)
1013 goto out; 1018 goto out_path;
1014 1019
1015 err = -EINVAL; 1020 err = -EINVAL;
1016 if (u->addr) 1021 if (u->addr)
1017 goto out_up; 1022 goto out_up;
1018 1023
1024 if (name_err) {
1025 err = name_err == -EEXIST ? -EADDRINUSE : name_err;
1026 goto out_up;
1027 }
1028
1019 err = -ENOMEM; 1029 err = -ENOMEM;
1020 addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL); 1030 addr = kmalloc(sizeof(*addr)+addr_len, GFP_KERNEL);
1021 if (!addr) 1031 if (!addr)
@@ -1026,11 +1036,11 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1026 addr->hash = hash ^ sk->sk_type; 1036 addr->hash = hash ^ sk->sk_type;
1027 atomic_set(&addr->refcnt, 1); 1037 atomic_set(&addr->refcnt, 1);
1028 1038
1029 if (sun_path[0]) { 1039 if (dentry) {
1030 struct path path; 1040 struct path u_path;
1031 umode_t mode = S_IFSOCK | 1041 umode_t mode = S_IFSOCK |
1032 (SOCK_INODE(sock)->i_mode & ~current_umask()); 1042 (SOCK_INODE(sock)->i_mode & ~current_umask());
1033 err = unix_mknod(sun_path, mode, &path); 1043 err = unix_mknod(dentry, &path, mode, &u_path);
1034 if (err) { 1044 if (err) {
1035 if (err == -EEXIST) 1045 if (err == -EEXIST)
1036 err = -EADDRINUSE; 1046 err = -EADDRINUSE;
@@ -1038,9 +1048,9 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1038 goto out_up; 1048 goto out_up;
1039 } 1049 }
1040 addr->hash = UNIX_HASH_SIZE; 1050 addr->hash = UNIX_HASH_SIZE;
1041 hash = d_backing_inode(path.dentry)->i_ino & (UNIX_HASH_SIZE-1); 1051 hash = d_backing_inode(dentry)->i_ino & (UNIX_HASH_SIZE - 1);
1042 spin_lock(&unix_table_lock); 1052 spin_lock(&unix_table_lock);
1043 u->path = path; 1053 u->path = u_path;
1044 list = &unix_socket_table[hash]; 1054 list = &unix_socket_table[hash];
1045 } else { 1055 } else {
1046 spin_lock(&unix_table_lock); 1056 spin_lock(&unix_table_lock);
@@ -1063,6 +1073,10 @@ out_unlock:
1063 spin_unlock(&unix_table_lock); 1073 spin_unlock(&unix_table_lock);
1064out_up: 1074out_up:
1065 mutex_unlock(&u->readlock); 1075 mutex_unlock(&u->readlock);
1076out_path:
1077 if (dentry)
1078 done_path_create(&path, dentry);
1079
1066out: 1080out:
1067 return err; 1081 return err;
1068} 1082}