Skip to content

Commit febca28

Browse files
Ursula Braundavem330
authored andcommitted
[AF_IUCV]: Add lock when updating accept_q
The accept_queue of an af_iucv socket will be corrupted, if adding and deleting of entries in this queue occurs at the same time (connect request from one client, while accept call is processed for another client). Solution: add locking when updating accept_q Signed-off-by: Ursula Braun <braunu@de.ibm.com> Acked-by: Frank Pavlic <fpavlic@de.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 13fdc9a commit febca28

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎include/net/iucv/af_iucv.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct iucv_sock {
6060
char dst_user_id[8];
6161
char dst_name[8];
6262
struct list_head accept_q;
63+
spinlock_t accept_q_lock;
6364
struct sock *parent;
6465
struct iucv_path *path;
6566
struct sk_buff_head send_skb_q;

‎net/iucv/af_iucv.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ static struct sock *iucv_sock_alloc(struct socket *sock, int proto, gfp_t prio)
219219

220220
sock_init_data(sock, sk);
221221
INIT_LIST_HEAD(&iucv_sk(sk)->accept_q);
222+
spin_lock_init(&iucv_sk(sk)->accept_q_lock);
222223
skb_queue_head_init(&iucv_sk(sk)->send_skb_q);
223224
skb_queue_head_init(&iucv_sk(sk)->backlog_skb_q);
224225
iucv_sk(sk)->send_tag = 0;
@@ -274,15 +275,25 @@ void iucv_sock_unlink(struct iucv_sock_list *l, struct sock *sk)
274275

275276
void iucv_accept_enqueue(struct sock *parent, struct sock *sk)
276277
{
278+
unsigned long flags;
279+
struct iucv_sock *par = iucv_sk(parent);
280+
277281
sock_hold(sk);
278-
list_add_tail(&iucv_sk(sk)->accept_q, &iucv_sk(parent)->accept_q);
282+
spin_lock_irqsave(&par->accept_q_lock, flags);
283+
list_add_tail(&iucv_sk(sk)->accept_q, &par->accept_q);
284+
spin_unlock_irqrestore(&par->accept_q_lock, flags);
279285
iucv_sk(sk)->parent = parent;
280286
parent->sk_ack_backlog++;
281287
}
282288

283289
void iucv_accept_unlink(struct sock *sk)
284290
{
291+
unsigned long flags;
292+
struct iucv_sock *par = iucv_sk(iucv_sk(sk)->parent);
293+
294+
spin_lock_irqsave(&par->accept_q_lock, flags);
285295
list_del_init(&iucv_sk(sk)->accept_q);
296+
spin_unlock_irqrestore(&par->accept_q_lock, flags);
286297
iucv_sk(sk)->parent->sk_ack_backlog--;
287298
iucv_sk(sk)->parent = NULL;
288299
sock_put(sk);
@@ -298,8 +309,8 @@ struct sock *iucv_accept_dequeue(struct sock *parent, struct socket *newsock)
298309
lock_sock(sk);
299310

300311
if (sk->sk_state == IUCV_CLOSED) {
301-
release_sock(sk);
302312
iucv_accept_unlink(sk);
313+
release_sock(sk);
303314
continue;
304315
}
305316

@@ -879,6 +890,7 @@ static int iucv_callback_connreq(struct iucv_path *path,
879890
/* Find out if this path belongs to af_iucv. */
880891
read_lock(&iucv_sk_list.lock);
881892
iucv = NULL;
893+
sk = NULL;
882894
sk_for_each(sk, node, &iucv_sk_list.head)
883895
if (sk->sk_state == IUCV_LISTEN &&
884896
!memcmp(&iucv_sk(sk)->src_name, src_name, 8)) {

0 commit comments

Comments
 (0)