diff mbox series

net: rds: don't hold sock lock when cancelling work from rds_tcp_reset_callbacks()

Message ID 3de97b2d-1c15-5dda-4fe2-78311a91d861@I-love.SAKURA.ne.jp (mailing list archive)
State Accepted
Commit a91b750fd6629354460282bbf5146c01b05c4859
Delegated to: Netdev Maintainers
Headers show
Series net: rds: don't hold sock lock when cancelling work from rds_tcp_reset_callbacks() | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: rds-devel@oss.oracle.com kuba@kernel.org edumazet@google.com pabeni@redhat.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tetsuo Handa Sept. 28, 2022, 3:25 p.m. UTC
syzbot is reporting lockdep warning at rds_tcp_reset_callbacks() [1], for
commit ac3615e7f3cffe2a ("RDS: TCP: Reduce code duplication in
rds_tcp_reset_callbacks()") added cancel_delayed_work_sync() into a section
protected by lock_sock() without realizing that rds_send_xmit() might call
lock_sock().

We don't need to protect cancel_delayed_work_sync() using lock_sock(), for
even if rds_{send,recv}_worker() re-queued this work while __flush_work()
 from cancel_delayed_work_sync() was waiting for this work to complete,
retried rds_{send,recv}_worker() is no-op due to the absence of RDS_CONN_UP
bit.

Link: https://syzkaller.appspot.com/bug?extid=78c55c7bc6f66e53dce2 [1]
Reported-by: syzbot <syzbot+78c55c7bc6f66e53dce2@syzkaller.appspotmail.com>
Co-developed-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Hillf Danton <hdanton@sina.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Tested-by: syzbot <syzbot+78c55c7bc6f66e53dce2@syzkaller.appspotmail.com>
Fixes: ac3615e7f3cffe2a ("RDS: TCP: Reduce code duplication in rds_tcp_reset_callbacks()")
---
Hillf, why don't you propose as a formal patch after syzbot tested your patch?
Explaining as a formal patch helps us with understanding/reviewing what you thought and
how you came to your patch. I feel sorry for stealing result of your trial and error...

 net/rds/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

patchwork-bot+netdevbpf@kernel.org Oct. 3, 2022, 7 a.m. UTC | #1
Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu, 29 Sep 2022 00:25:37 +0900 you wrote:
> syzbot is reporting lockdep warning at rds_tcp_reset_callbacks() [1], for
> commit ac3615e7f3cffe2a ("RDS: TCP: Reduce code duplication in
> rds_tcp_reset_callbacks()") added cancel_delayed_work_sync() into a section
> protected by lock_sock() without realizing that rds_send_xmit() might call
> lock_sock().
> 
> We don't need to protect cancel_delayed_work_sync() using lock_sock(), for
> even if rds_{send,recv}_worker() re-queued this work while __flush_work()
>  from cancel_delayed_work_sync() was waiting for this work to complete,
> retried rds_{send,recv}_worker() is no-op due to the absence of RDS_CONN_UP
> bit.
> 
> [...]

Here is the summary with links:
  - net: rds: don't hold sock lock when cancelling work from rds_tcp_reset_callbacks()
    https://git.kernel.org/netdev/net/c/a91b750fd662

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/rds/tcp.c b/net/rds/tcp.c
index 73ee2771093d..d0ff413f697c 100644
--- a/net/rds/tcp.c
+++ b/net/rds/tcp.c
@@ -166,10 +166,10 @@  void rds_tcp_reset_callbacks(struct socket *sock,
 	 */
 	atomic_set(&cp->cp_state, RDS_CONN_RESETTING);
 	wait_event(cp->cp_waitq, !test_bit(RDS_IN_XMIT, &cp->cp_flags));
-	lock_sock(osock->sk);
 	/* reset receive side state for rds_tcp_data_recv() for osock  */
 	cancel_delayed_work_sync(&cp->cp_send_w);
 	cancel_delayed_work_sync(&cp->cp_recv_w);
+	lock_sock(osock->sk);
 	if (tc->t_tinc) {
 		rds_inc_put(&tc->t_tinc->ti_inc);
 		tc->t_tinc = NULL;