Skip to content

Commit 7b3e13e

Browse files
linzhanggregkh
authored andcommitted
net: llc: add lock_sock in llc_ui_bind to avoid a race condition
[ Upstream commit 0908cf4 ] 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]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2967094 commit 7b3e13e

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/llc/af_llc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
309309
int rc = -EINVAL;
310310

311311
dprintk("%s: binding %02X\n", __func__, addr->sllc_sap);
312+
313+
lock_sock(sk);
312314
if (unlikely(!sock_flag(sk, SOCK_ZAPPED) || addrlen != sizeof(*addr)))
313315
goto out;
314316
rc = -EAFNOSUPPORT;
@@ -380,6 +382,7 @@ static int llc_ui_bind(struct socket *sock, struct sockaddr *uaddr, int addrlen)
380382
out_put:
381383
llc_sap_put(sap);
382384
out:
385+
release_sock(sk);
383386
return rc;
384387
}
385388

0 commit comments

Comments
 (0)