net: decnet: Fix sleeping inside in af_decnet

[ Upstream commit 5f119ba1d5771bbf46d57cff7417dcd84d3084ba ]

The release_sock() is blocking function, it would change the state
after sleeping. use wait_woken() instead.

Fixes: 1da177e4c3 ("Linux-2.6.12-rc2")
Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Yajun Deng 2021-07-14 17:13:20 +08:00 committed by Greg Kroah-Hartman
parent bd2b3b13aa
commit b3224bd318
1 changed files with 12 additions and 15 deletions

View File

@ -815,7 +815,7 @@ static int dn_auto_bind(struct socket *sock)
static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation) static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
{ {
struct dn_scp *scp = DN_SK(sk); struct dn_scp *scp = DN_SK(sk);
DEFINE_WAIT(wait); DEFINE_WAIT_FUNC(wait, woken_wake_function);
int err; int err;
if (scp->state != DN_CR) if (scp->state != DN_CR)
@ -825,11 +825,11 @@ static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
scp->segsize_loc = dst_metric_advmss(__sk_dst_get(sk)); scp->segsize_loc = dst_metric_advmss(__sk_dst_get(sk));
dn_send_conn_conf(sk, allocation); dn_send_conn_conf(sk, allocation);
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); add_wait_queue(sk_sleep(sk), &wait);
for(;;) { for(;;) {
release_sock(sk); release_sock(sk);
if (scp->state == DN_CC) if (scp->state == DN_CC)
*timeo = schedule_timeout(*timeo); *timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, *timeo);
lock_sock(sk); lock_sock(sk);
err = 0; err = 0;
if (scp->state == DN_RUN) if (scp->state == DN_RUN)
@ -843,9 +843,8 @@ static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
err = -EAGAIN; err = -EAGAIN;
if (!*timeo) if (!*timeo)
break; break;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
} }
finish_wait(sk_sleep(sk), &wait); remove_wait_queue(sk_sleep(sk), &wait);
if (err == 0) { if (err == 0) {
sk->sk_socket->state = SS_CONNECTED; sk->sk_socket->state = SS_CONNECTED;
} else if (scp->state != DN_CC) { } else if (scp->state != DN_CC) {
@ -857,7 +856,7 @@ static int dn_confirm_accept(struct sock *sk, long *timeo, gfp_t allocation)
static int dn_wait_run(struct sock *sk, long *timeo) static int dn_wait_run(struct sock *sk, long *timeo)
{ {
struct dn_scp *scp = DN_SK(sk); struct dn_scp *scp = DN_SK(sk);
DEFINE_WAIT(wait); DEFINE_WAIT_FUNC(wait, woken_wake_function);
int err = 0; int err = 0;
if (scp->state == DN_RUN) if (scp->state == DN_RUN)
@ -866,11 +865,11 @@ static int dn_wait_run(struct sock *sk, long *timeo)
if (!*timeo) if (!*timeo)
return -EALREADY; return -EALREADY;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); add_wait_queue(sk_sleep(sk), &wait);
for(;;) { for(;;) {
release_sock(sk); release_sock(sk);
if (scp->state == DN_CI || scp->state == DN_CC) if (scp->state == DN_CI || scp->state == DN_CC)
*timeo = schedule_timeout(*timeo); *timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, *timeo);
lock_sock(sk); lock_sock(sk);
err = 0; err = 0;
if (scp->state == DN_RUN) if (scp->state == DN_RUN)
@ -884,9 +883,8 @@ static int dn_wait_run(struct sock *sk, long *timeo)
err = -ETIMEDOUT; err = -ETIMEDOUT;
if (!*timeo) if (!*timeo)
break; break;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
} }
finish_wait(sk_sleep(sk), &wait); remove_wait_queue(sk_sleep(sk), &wait);
out: out:
if (err == 0) { if (err == 0) {
sk->sk_socket->state = SS_CONNECTED; sk->sk_socket->state = SS_CONNECTED;
@ -1031,16 +1029,16 @@ static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt)
static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo) static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
{ {
DEFINE_WAIT(wait); DEFINE_WAIT_FUNC(wait, woken_wake_function);
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
int err = 0; int err = 0;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE); add_wait_queue(sk_sleep(sk), &wait);
for(;;) { for(;;) {
release_sock(sk); release_sock(sk);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
if (skb == NULL) { if (skb == NULL) {
*timeo = schedule_timeout(*timeo); *timeo = wait_woken(&wait, TASK_INTERRUPTIBLE, *timeo);
skb = skb_dequeue(&sk->sk_receive_queue); skb = skb_dequeue(&sk->sk_receive_queue);
} }
lock_sock(sk); lock_sock(sk);
@ -1055,9 +1053,8 @@ static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
err = -EAGAIN; err = -EAGAIN;
if (!*timeo) if (!*timeo)
break; break;
prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
} }
finish_wait(sk_sleep(sk), &wait); remove_wait_queue(sk_sleep(sk), &wait);
return skb == NULL ? ERR_PTR(err) : skb; return skb == NULL ? ERR_PTR(err) : skb;
} }