OSDN Git Service

net: llc: add lock_sock in llc_ui_bind to avoid a race condition
authorlinzhang <xiaolou4617@gmail.com>
Thu, 25 May 2017 06:07:18 +0000 (14:07 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Apr 2018 17:50:12 +0000 (19:50 +0200)
commit7b3e13e2444a2602a30a3d3a09c793c26aa124b0
tree45c81f8742f42857efa75b71b8ed432b75291742
parent2967094c22ee46a5c7e316cdd4e6f1556c06ef99
net: llc: add lock_sock in llc_ui_bind to avoid a race condition

[ Upstream commit 0908cf4dfef35fc6ac12329007052ebe93ff1081 ]

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 <xiaolou4617@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/llc/af_llc.c