Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 320952
b: refs/heads/master
c: faf0201
h: refs/heads/master
v: v3
  • Loading branch information
Al Viro committed Jul 29, 2012
1 parent f5acc41 commit f48b751
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a8104a9fcdeb82e22d7acd55fca20746581067d3
refs/heads/master: faf02010290e202e275c1bf94ca9dd808bf85607
88 changes: 43 additions & 45 deletions trunk/net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,34 @@ static struct sock *unix_find_other(struct net *net,
return NULL;
}

static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
{
struct dentry *dentry;
struct path path;
int err = 0;
/*
* Get the parent directory, calculate the hash for last
* component.
*/
dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0);
err = PTR_ERR(dentry);
if (IS_ERR(dentry))
return err;

/*
* All right, let's create it.
*/
err = security_path_mknod(&path, dentry, mode, 0);
if (!err) {
err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
if (!err) {
res->mnt = mntget(path.mnt);
res->dentry = dget(dentry);
}
}
done_path_create(&path, dentry);
return err;
}

static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
{
Expand All @@ -822,8 +850,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
struct unix_sock *u = unix_sk(sk);
struct sockaddr_un *sunaddr = (struct sockaddr_un *)uaddr;
char *sun_path = sunaddr->sun_path;
struct dentry *dentry = NULL;
struct path path;
int err;
unsigned int hash;
struct unix_address *addr;
Expand Down Expand Up @@ -860,40 +886,23 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
atomic_set(&addr->refcnt, 1);

if (sun_path[0]) {
umode_t mode;
err = 0;
/*
* Get the parent directory, calculate the hash for last
* component.
*/
dentry = kern_path_create(AT_FDCWD, sun_path, &path, 0);
err = PTR_ERR(dentry);
if (IS_ERR(dentry))
goto out_mknod_parent;

/*
* All right, let's create it.
*/
mode = S_IFSOCK |
struct path path;
umode_t mode = S_IFSOCK |
(SOCK_INODE(sock)->i_mode & ~current_umask());
err = security_path_mknod(&path, dentry, mode, 0);
if (err)
goto out_mknod_drop_write;
err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
out_mknod_drop_write:
if (err)
goto out_mknod_dput;
mntget(path.mnt);
dget(dentry);
done_path_create(&path, dentry);
path.dentry = dentry;

err = unix_mknod(sun_path, mode, &path);
if (err) {
if (err == -EEXIST)
err = -EADDRINUSE;
unix_release_addr(addr);
goto out_up;
}
addr->hash = UNIX_HASH_SIZE;
}

spin_lock(&unix_table_lock);

if (!sun_path[0]) {
hash = path.dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1);
spin_lock(&unix_table_lock);
u->path = path;
list = &unix_socket_table[hash];
} else {
spin_lock(&unix_table_lock);
err = -EADDRINUSE;
if (__unix_find_socket_byname(net, sunaddr, addr_len,
sk->sk_type, hash)) {
Expand All @@ -902,9 +911,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
}

list = &unix_socket_table[addr->hash];
} else {
list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
u->path = path;
}

err = 0;
Expand All @@ -918,14 +924,6 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
mutex_unlock(&u->readlock);
out:
return err;

out_mknod_dput:
done_path_create(&path, dentry);
out_mknod_parent:
if (err == -EEXIST)
err = -EADDRINUSE;
unix_release_addr(addr);
goto out_up;
}

static void unix_state_double_lock(struct sock *sk1, struct sock *sk2)
Expand Down

0 comments on commit f48b751

Please sign in to comment.