From: Hawkins Jiawei <yin31149@gmail.com>
To: syzbot+7f0483225d0c94cb3441@syzkaller.appspotmail.com,
David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com,
linux-kernel-mentees@lists.linuxfoundation.org,
paskripkin@gmail.com, skhan@linuxfoundation.org,
18801353760@163.com, Hawkins Jiawei <yin31149@gmail.com>
Subject: [PATCH] rxrpc: fix bad unlock balance in rxrpc_do_sendmsg
Date: Sun, 21 Aug 2022 20:57:50 +0800 [thread overview]
Message-ID: <20220821125751.4185-1-yin31149@gmail.com> (raw)
In-Reply-To: <000000000000ce327f05d537ebf7@google.com>
Syzkaller reports bad unlock balance bug as follows:
------------[ cut here ]------------
WARNING: bad unlock balance detected!
syz-executor.0/4094 is trying to release lock (&call->user_mutex) at:
[<ffffffff87c1d8d1>] rxrpc_do_sendmsg+0x851/0x1110 net/rxrpc/sendmsg.c:754
but there are no more locks to release!
other info that might help us debug this:
no locks held by syz-executor.0/4094.
stack backtrace:
[...]
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x57/0x7d lib/dump_stack.c:106
print_unlock_imbalance_bug include/trace/events/lock.h:69 [inline]
__lock_release kernel/locking/lockdep.c:5333 [inline]
lock_release.cold+0x49/0x4e kernel/locking/lockdep.c:5686
__mutex_unlock_slowpath+0x99/0x5e0 kernel/locking/mutex.c:907
rxrpc_do_sendmsg+0x851/0x1110 net/rxrpc/sendmsg.c:754
sock_sendmsg_nosec net/socket.c:714 [inline]
sock_sendmsg+0xab/0xe0 net/socket.c:734
____sys_sendmsg+0x5c2/0x7a0 net/socket.c:2485
___sys_sendmsg+0xdb/0x160 net/socket.c:2539
__sys_sendmsg+0xc3/0x160 net/socket.c:2568
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
[...]
</TASK>
------------------------------------
When kernel wants to send a message through an RxRPC socket in
rxrpc_do_sendmsg(), kernel should hold the call->user_mutex lock,
or it will triggers bug when releasing this lock before returning
from rxrpc_do_sendmsg().
Yet the problem is that during rxrpc_do_sendmsg(), kernel may call
rxrpc_wait_for_tx_window_intr() to wait for space to appear in the
tx queue or a signal to occur. When kernel fails the
mutex_lock_interruptible(), kernel will returns from the
rxrpc_wait_for_tx_window_intr() without acquiring the mutex lock, then
triggers bug when releasing the mutex lock in rxrpc_do_sendmsg().
This patch solves it by acquiring the call->user_mutex lock, when
kernel fails the mutex_lock_interruptible() before returning from
the rxrpc_wait_for_tx_window_intr().
Reported-and-tested-by: syzbot+7f0483225d0c94cb3441@syzkaller.appspotmail.com
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
net/rxrpc/sendmsg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
index 1d38e279e2ef..e13043d357d5 100644
--- a/net/rxrpc/sendmsg.c
+++ b/net/rxrpc/sendmsg.c
@@ -53,8 +53,10 @@ static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx,
trace_rxrpc_transmit(call, rxrpc_transmit_wait);
mutex_unlock(&call->user_mutex);
*timeo = schedule_timeout(*timeo);
- if (mutex_lock_interruptible(&call->user_mutex) < 0)
+ if (mutex_lock_interruptible(&call->user_mutex) < 0) {
+ mutex_lock(&call->user_mutex);
return sock_intr_errno(*timeo);
+ }
}
}
--
2.25.1
next prev parent reply other threads:[~2022-08-21 12:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-10 10:37 [syzbot] WARNING: " syzbot
2022-08-21 12:57 ` Hawkins Jiawei [this message]
2022-08-21 15:58 ` [PATCH] rxrpc: fix " Khalid Masum
2022-08-21 16:42 ` Khalid Masum
2022-08-22 5:19 ` Hawkins Jiawei
2022-08-21 19:17 ` [syzbot] WARNING: " Khalid Masum
2022-08-21 22:29 ` syzbot
2022-08-22 8:48 ` [PATCH] rxrpc: fix " David Howells
2022-08-22 9:21 ` David Howells
2022-08-22 11:29 ` Hawkins Jiawei
2022-08-22 11:29 ` Hawkins Jiawei
2022-08-22 13:04 ` Hawkins Jiawei
2022-08-22 13:44 ` Dan Carpenter
2022-08-22 13:55 ` Khalid Masum
2022-08-22 14:05 ` Dan Carpenter
2022-08-22 15:39 ` Hawkins Jiawei
2022-08-22 16:00 ` Khalid Masum
2022-08-22 14:24 ` [syzbot] WARNING: " David Howells
2022-08-22 15:45 ` David Howells
2022-08-22 16:23 ` syzbot
2022-08-24 16:30 ` Marc Dionne
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220821125751.4185-1-yin31149@gmail.com \
--to=yin31149@gmail.com \
--cc=18801353760@163.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=paskripkin@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=syzbot+7f0483225d0c94cb3441@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®