Commit c0c3b8d3 authored by Al Viro's avatar Al Viro Committed by David S. Miller

unix_bind_bsd(): unlink if we fail after successful mknod

We can do that more or less safely, since the parent is
held locked all along.  Yes, somebody might observe the
object via dcache, only to have it disappear afterwards,
but there's really no good way to prevent that.  It won't
race with other bind(2) or attempts to move the sucker
elsewhere, or put something else in its place - locked
parent prevents that.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 56c1731b
...@@ -1010,20 +1010,13 @@ static int unix_bind_bsd(struct sock *sk, struct unix_address *addr) ...@@ -1010,20 +1010,13 @@ static int unix_bind_bsd(struct sock *sk, struct unix_address *addr)
err = security_path_mknod(&parent, dentry, mode, 0); err = security_path_mknod(&parent, dentry, mode, 0);
if (!err) if (!err)
err = vfs_mknod(ns, d_inode(parent.dentry), dentry, mode, 0); err = vfs_mknod(ns, d_inode(parent.dentry), dentry, mode, 0);
if (err) { if (err)
done_path_create(&parent, dentry); goto out;
return err;
}
err = mutex_lock_interruptible(&u->bindlock); err = mutex_lock_interruptible(&u->bindlock);
if (err) { if (err)
done_path_create(&parent, dentry); goto out_unlink;
return err; if (u->addr)
} goto out_unlock;
if (u->addr) {
mutex_unlock(&u->bindlock);
done_path_create(&parent, dentry);
return -EINVAL;
}
addr->hash = UNIX_HASH_SIZE; addr->hash = UNIX_HASH_SIZE;
hash = d_backing_inode(dentry)->i_ino & (UNIX_HASH_SIZE - 1); hash = d_backing_inode(dentry)->i_ino & (UNIX_HASH_SIZE - 1);
...@@ -1035,6 +1028,16 @@ static int unix_bind_bsd(struct sock *sk, struct unix_address *addr) ...@@ -1035,6 +1028,16 @@ static int unix_bind_bsd(struct sock *sk, struct unix_address *addr)
mutex_unlock(&u->bindlock); mutex_unlock(&u->bindlock);
done_path_create(&parent, dentry); done_path_create(&parent, dentry);
return 0; return 0;
out_unlock:
mutex_unlock(&u->bindlock);
err = -EINVAL;
out_unlink:
/* failed after successful mknod? unlink what we'd created... */
vfs_unlink(ns, d_inode(parent.dentry), dentry, NULL);
out:
done_path_create(&parent, dentry);
return err;
} }
static int unix_bind_abstract(struct sock *sk, unsigned hash, static int unix_bind_abstract(struct sock *sk, unsigned hash,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment