BACKPORT: af_unix: Pass struct sock to unix_autobind().

We do not use struct socket in unix_autobind() and pass struct sock to
unix_bind_bsd() and unix_bind_abstract().  Let's pass it to unix_autobind()
as well.

Also, this patch fixes these errors by checkpatch.pl.

  ERROR: do not use assignment in if condition
  #1795: FILE: net/unix/af_unix.c:1795:
  +	if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr

  CHECK: Logical continuations should be on the previous line
  #1796: FILE: net/unix/af_unix.c:1796:
  +	if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr
  +	    && (err = unix_autobind(sock)) != 0)

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
[cyberknight777: backport to 4.14]
Signed-off-by: Cyber Knight <cyberknight755@gmail.com>
Signed-off-by: azrim <mirzaspc@gmail.com>
This commit is contained in:
Kuniyuki Iwashima 2021-11-24 11:14:20 +09:00 committed by azrim
parent 22f18e1dff
commit 15c720d53f
No known key found for this signature in database
GPG Key ID: 497F8FB059B45D1C

View File

@ -924,15 +924,13 @@ static int unix_release(struct socket *sock)
return 0;
}
static int unix_autobind(struct socket *sock)
static int unix_autobind(struct sock *sk)
{
struct sock *sk = sock->sk;
struct net *net = sock_net(sk);
struct unix_sock *u = unix_sk(sk);
static u32 ordernum = 1;
struct unix_address *addr;
int err;
unsigned int retries = 0;
static u32 ordernum = 1;
int err;
err = mutex_lock_interruptible(&u->bindlock);
if (err)
@ -959,7 +957,8 @@ retry:
spin_lock(&unix_table_lock);
ordernum = (ordernum+1)&0xFFFFF;
if (__unix_find_socket_byname(net, addr->name, addr->len, addr->hash)) {
if (__unix_find_socket_byname(sock_net(sk), addr->name, addr->len,
addr->hash)) {
spin_unlock(&unix_table_lock);
/*
* __unix_find_socket_byname() may take long time if many names
@ -1143,7 +1142,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
return -EINVAL;
if (addr_len == offsetof(struct sockaddr_un, sun_path))
return unix_autobind(sock);
return unix_autobind(sk);
err = unix_mkname(sunaddr, addr_len, &hash);
if (err < 0)
@ -1213,8 +1212,11 @@ static int unix_dgram_connect(struct socket *sock, struct sockaddr *addr,
alen = err;
if (test_bit(SOCK_PASSCRED, &sock->flags) &&
!unix_sk(sk)->addr && (err = unix_autobind(sock)) != 0)
goto out;
!unix_sk(sk)->addr) {
err = unix_autobind(sk);
if (err)
goto out;
}
restart:
other = unix_find_other(net, sunaddr, alen, sock->type, hash, &err);
@ -1319,9 +1321,11 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr,
goto out;
addr_len = err;
if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr &&
(err = unix_autobind(sock)) != 0)
goto out;
if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr) {
err = unix_autobind(sk);
if (err)
goto out;
}
timeo = sock_sndtimeo(sk, flags & O_NONBLOCK);
@ -1770,9 +1774,11 @@ static int unix_dgram_sendmsg(struct socket *sock, struct msghdr *msg,
goto out;
}
if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr
&& (err = unix_autobind(sock)) != 0)
goto out;
if (test_bit(SOCK_PASSCRED, &sock->flags) && !u->addr) {
err = unix_autobind(sk);
if (err)
goto out;
}
err = -EMSGSIZE;
if (len > sk->sk_sndbuf - 32)