Skip to content

Commit

Permalink
net: llc: add lock_sock in llc_ui_bind to avoid a race condition
Browse files Browse the repository at this point in the history
There is a race condition in llc_ui_bind if two or more processes/threads
try to bind a same socket.

If more processes/threads bind a same socket success that will lead to
two problems, one is this action is not what we expected, another is
will lead to kernel in unstable status or oops(in my simple test case,
cause llc2.ko can't unload).

The current code is test SOCK_ZAPPED bit to avoid a process to
bind a same socket twice but that is can't avoid more processes/threads
try to bind a same socket at the same time.

So, add lock_sock in llc_ui_bind like others, such as llc_ui_connect.

Signed-off-by: Lin Zhang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
linzhang authored and davem330 committed May 26, 2017
1 parent 797a936 commit 0908cf4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
int rc = -EINVAL;

dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);

lock_sock(sk);
if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
goto out;
rc = -EAFNOSUPPORT;
Expand Down Expand Up @@ -382,6 +384,7 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
out_put:
llc_sap_put(sap);
out:
release_sock(sk);
return rc;
}

Expand Down

0 comments on commit 0908cf4

Please sign in to comment.