提交 13d02b4d 编写于 作者: H Hoang Le 提交者: Zheng Zengkai

tipc: fix sleeping in tipc accept routine

stable inclusion
from stable-5.10.56
commit a41282e82a1d13ad2cca0f07879d7042780d8e78
bugzilla: 176004 https://gitee.com/openeuler/kernel/issues/I4DYZ4

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a41282e82a1d13ad2cca0f07879d7042780d8e78

--------------------------------

[ Upstream commit d237a7f1 ]

The release_sock() is blocking function, it would change the state
after sleeping. In order to evaluate the stated condition outside
the socket lock context, switch to use wait_woken() instead.

Fixes: 6398e23c ("tipc: standardize accept routine")
Acked-by: NJon Maloy <jmaloy@redhat.com>
Signed-off-by: NHoang Le <hoang.h.le@dektech.com.au>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 9301aa60
...@@ -2650,7 +2650,7 @@ static int tipc_listen(struct socket *sock, int len) ...@@ -2650,7 +2650,7 @@ static int tipc_listen(struct socket *sock, int len)
static int tipc_wait_for_accept(struct socket *sock, long timeo) static int tipc_wait_for_accept(struct socket *sock, long timeo)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
DEFINE_WAIT(wait); DEFINE_WAIT_FUNC(wait, woken_wake_function);
int err; int err;
/* True wake-one mechanism for incoming connections: only /* True wake-one mechanism for incoming connections: only
...@@ -2659,12 +2659,12 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) ...@@ -2659,12 +2659,12 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
* anymore, the common case will execute the loop only once. * anymore, the common case will execute the loop only once.
*/ */
for (;;) { for (;;) {
prepare_to_wait_exclusive(sk_sleep(sk), &wait,
TASK_INTERRUPTIBLE);
if (timeo && skb_queue_empty(&sk->sk_receive_queue)) { if (timeo && skb_queue_empty(&sk->sk_receive_queue)) {
add_wait_queue(sk_sleep(sk), &wait);
release_sock(sk); release_sock(sk);
timeo = schedule_timeout(timeo); timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, timeo);
lock_sock(sk); lock_sock(sk);
remove_wait_queue(sk_sleep(sk), &wait);
} }
err = 0; err = 0;
if (!skb_queue_empty(&sk->sk_receive_queue)) if (!skb_queue_empty(&sk->sk_receive_queue))
...@@ -2676,7 +2676,6 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo) ...@@ -2676,7 +2676,6 @@ static int tipc_wait_for_accept(struct socket *sock, long timeo)
if (signal_pending(current)) if (signal_pending(current))
break; break;
} }
finish_wait(sk_sleep(sk), &wait);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册