linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: llc: add lock_sock in llc_ui_bind to avoid a race condition
@ 2017-05-25  6:07 Lin Zhang
  2017-05-26 18:24 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Lin Zhang @ 2017-05-25  6:07 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, Lin Zhang

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>
---
 net/llc/af_llc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 8364fe5..c38d16f 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -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;
@@ -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;
 }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: llc: add lock_sock in llc_ui_bind to avoid a race condition
  2017-05-25  6:07 [PATCH] net: llc: add lock_sock in llc_ui_bind to avoid a race condition Lin Zhang
@ 2017-05-26 18:24 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2017-05-26 18:24 UTC (permalink / raw)
  To: xiaolou4617; +Cc: netdev, linux-kernel

From: Lin Zhang <xiaolou4617@gmail.com>
Date: Thu, 25 May 2017 14:07:18 +0800

> 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>

Applied, thank you.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-05-26 18:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-25  6:07 [PATCH] net: llc: add lock_sock in llc_ui_bind to avoid a race condition Lin Zhang
2017-05-26 18:24 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).