Skip to content

Commit f1acf1a

Browse files
allisonhendersonPaolo Abeni
authored andcommitted
net:rds: Fix possible deadlock in rds_message_put
Functions rds_still_queued and rds_clear_recv_queue lock a given socket in order to safely iterate over the incoming rds messages. However calling rds_inc_put while under this lock creates a potential deadlock. rds_inc_put may eventually call rds_message_purge, which will lock m_rs_lock. This is the incorrect locking order since m_rs_lock is meant to be locked before the socket. To fix this, we move the message item to a local list or variable that wont need rs_recv_lock protection. Then we can safely call rds_inc_put on any item stored locally after rs_recv_lock is released. Fixes: bdbe6fb ("RDS: recv.c") Reported-by: syzbot+f9db6ff27b9bfdcfeca0@syzkaller.appspotmail.com Reported-by: syzbot+dcd73ff9291e6d34b3ab@syzkaller.appspotmail.com Signed-off-by: Allison Henderson <allison.henderson@oracle.com> Link: https://lore.kernel.org/r/20240209022854.200292-1-allison.henderson@oracle.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 9f30831 commit f1acf1a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

net/rds/recv.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ static int rds_still_queued(struct rds_sock *rs, struct rds_incoming *inc,
425425
struct sock *sk = rds_rs_to_sk(rs);
426426
int ret = 0;
427427
unsigned long flags;
428+
struct rds_incoming *to_drop = NULL;
428429

429430
write_lock_irqsave(&rs->rs_recv_lock, flags);
430431
if (!list_empty(&inc->i_item)) {
@@ -435,11 +436,14 @@ static int rds_still_queued(struct rds_sock *rs, struct rds_incoming *inc,
435436
-be32_to_cpu(inc->i_hdr.h_len),
436437
inc->i_hdr.h_dport);
437438
list_del_init(&inc->i_item);
438-
rds_inc_put(inc);
439+
to_drop = inc;
439440
}
440441
}
441442
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
442443

444+
if (to_drop)
445+
rds_inc_put(to_drop);
446+
443447
rdsdebug("inc %p rs %p still %d dropped %d\n", inc, rs, ret, drop);
444448
return ret;
445449
}
@@ -758,16 +762,21 @@ void rds_clear_recv_queue(struct rds_sock *rs)
758762
struct sock *sk = rds_rs_to_sk(rs);
759763
struct rds_incoming *inc, *tmp;
760764
unsigned long flags;
765+
LIST_HEAD(to_drop);
761766

762767
write_lock_irqsave(&rs->rs_recv_lock, flags);
763768
list_for_each_entry_safe(inc, tmp, &rs->rs_recv_queue, i_item) {
764769
rds_recv_rcvbuf_delta(rs, sk, inc->i_conn->c_lcong,
765770
-be32_to_cpu(inc->i_hdr.h_len),
766771
inc->i_hdr.h_dport);
772+
list_move(&inc->i_item, &to_drop);
773+
}
774+
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
775+
776+
list_for_each_entry_safe(inc, tmp, &to_drop, i_item) {
767777
list_del_init(&inc->i_item);
768778
rds_inc_put(inc);
769779
}
770-
write_unlock_irqrestore(&rs->rs_recv_lock, flags);
771780
}
772781

773782
/*

0 commit comments

Comments
 (0)