From: Guoqing Jiang <guoqing.jiang@linux.dev>
To: Song Liu <song@kernel.org>, Donald Buczek <buczek@molgen.mpg.de>
Cc: linux-raid <linux-raid@vger.kernel.org>
Subject: Re: [Update PATCH V3] md: don't unregister sync_thread with reconfig_mutex held
Date: Wed, 11 May 2022 16:10:31 +0800 [thread overview]
Message-ID: <52e9aa65-581a-63fc-272a-0477f8c6e873@linux.dev> (raw)
In-Reply-To: <CAPhsuW4ZVkzQa=UKz=TR52ye23RAyubUOgdhT7=OGqTR8uWwVw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1621 bytes --]
On 5/11/22 2:02 AM, Song Liu wrote:
> On Tue, May 10, 2022 at 5:35 AM Donald Buczek <buczek@molgen.mpg.de> wrote:
>> On 5/10/22 2:09 PM, Guoqing Jiang wrote:
>>>
>>> On 5/10/22 8:01 PM, Donald Buczek wrote:
>>>>> I guess v2 is the best at the moment. I pushed a slightly modified v2 to
>>>>> md-next.
>>>> I think, this can be used to get a double-free from md_unregister_thread.
>>>>
>>>> Please review
>>>>
>>>> https://lore.kernel.org/linux-raid/8312a154-14fb-6f07-0cf1-8c970187cc49@molgen.mpg.de/
>>> That is supposed to be addressed by the second one, pls consider it too.
>> Right, but this has not been pulled into md-next. I just wanted to note, that the current state of md-next has this problem.
Thanks for reminder.
>> If the other patch is taken, too, and works as intended, that would be solved.
>>
>>> [PATCH 2/2] md: protect md_unregister_thread from reentrancy
> Good catch!
>
> Guoqing, current 2/2 doesn't apply cleanly. Could you please resend it on top of
> md-next?
Hmm, no issue from my side.
~/source/md> git am
0001-md-protect-md_unregister_thread-from-reentrancy.patch
Applying: md: protect md_unregister_thread from reentrancy
~/source/md> git log --oneline |head -5
dc7147a88766 md: protect md_unregister_thread from reentrancy
5a36c493dc82 md: don't unregister sync_thread with reconfig_mutex held
49c3b9266a71 block: null_blk: Improve device creation with configfs
db060f54e0c5 block: null_blk: Cleanup messages
b3a0a73e8a79 block: null_blk: Cleanup device creation and deletion
Anyway, it is attached. I will rebase it to your latest tree if
something gets wrong.
Thanks,
Guoqing
[-- Attachment #2: 0001-md-protect-md_unregister_thread-from-reentrancy.patch --]
[-- Type: text/x-patch, Size: 1751 bytes --]
From a2da80f62f15023e3fee7a02488c143dfff647b3 Mon Sep 17 00:00:00 2001
From: Guoqing Jiang <guoqing.jiang@cloud.ionos.com>
Date: Fri, 29 Apr 2022 16:49:09 +0800
Subject: [PATCH 2/2] md: protect md_unregister_thread from reentrancy
Generally, the md_unregister_thread is called with reconfig_mutex, but
raid_message in dm-raid doesn't hold reconfig_mutex to unregister thread,
so md_unregister_thread can be called simulitaneously from two call sites
in theory.
Then after previous commit which remove the protection of reconfig_mutex
for md_unregister_thread completely, the potential issue could be worse
than before.
Let's take pers_lock at the beginning of function to ensure reentrancy.
Reported-by: Donald Buczek <buczek@molgen.mpg.de>
Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
---
drivers/md/md.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index a70e7f0f9268..c401e063bec8 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -7962,17 +7962,22 @@ EXPORT_SYMBOL(md_register_thread);
void md_unregister_thread(struct md_thread **threadp)
{
- struct md_thread *thread = *threadp;
- if (!thread)
- return;
- pr_debug("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk));
- /* Locking ensures that mddev_unlock does not wake_up a
+ struct md_thread *thread;
+
+ /*
+ * Locking ensures that mddev_unlock does not wake_up a
* non-existent thread
*/
spin_lock(&pers_lock);
+ thread = *threadp;
+ if (!thread) {
+ spin_unlock(&pers_lock);
+ return;
+ }
*threadp = NULL;
spin_unlock(&pers_lock);
+ pr_debug("interrupting MD-thread pid %d\n", task_pid_nr(thread->tsk));
kthread_stop(thread->tsk);
kfree(thread);
}
--
2.31.1
next prev parent reply other threads:[~2022-05-11 8:10 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 8:16 [PATCH 0/2] two fixes for md Guoqing Jiang
2022-05-05 8:16 ` [PATCH V3 1/2] md: don't unregister sync_thread with reconfig_mutex held Guoqing Jiang
2022-05-05 14:02 ` kernel test robot
2022-05-05 18:04 ` kernel test robot
2022-05-06 2:34 ` Guoqing Jiang
2022-05-05 8:16 ` [PATCH 2/2] md: protect md_unregister_thread from reentrancy Guoqing Jiang
2022-05-09 6:39 ` Song Liu
2022-05-09 8:12 ` Guoqing Jiang
2022-05-06 11:36 ` [Update PATCH V3] md: don't unregister sync_thread with reconfig_mutex held Guoqing Jiang
2022-05-09 6:37 ` Song Liu
2022-05-09 8:09 ` Guoqing Jiang
2022-05-09 9:32 ` Wols Lists
2022-05-09 10:37 ` Guoqing Jiang
2022-05-09 11:19 ` Wols Lists
2022-05-09 11:26 ` Guoqing Jiang
2022-05-10 6:44 ` Song Liu
2022-05-10 12:01 ` Donald Buczek
2022-05-10 12:09 ` Guoqing Jiang
2022-05-10 12:35 ` Donald Buczek
2022-05-10 18:02 ` Song Liu
2022-05-11 8:10 ` Guoqing Jiang [this message]
2022-05-11 21:45 ` Song Liu
2022-05-20 18:27 ` Logan Gunthorpe
2022-05-21 18:23 ` Donald Buczek
2022-05-23 1:08 ` Guoqing Jiang
2022-05-23 5:41 ` Donald Buczek
2022-05-23 9:51 ` Guoqing Jiang
2022-05-24 16:13 ` Logan Gunthorpe
2022-05-25 9:04 ` Guoqing Jiang
2022-05-25 18:22 ` Logan Gunthorpe
2022-05-26 9:46 ` Jan Kara
2022-05-26 11:53 ` Jan Kara
2022-05-31 6:11 ` Christoph Hellwig
2022-05-31 7:43 ` Jan Kara
2022-05-30 9:55 ` Guoqing Jiang
2022-05-30 16:35 ` Logan Gunthorpe
2022-05-31 8:13 ` Guoqing Jiang
2022-05-24 15:58 ` Logan Gunthorpe
2022-05-24 18:16 ` Song Liu
2022-05-25 9:17 ` Guoqing Jiang
2022-05-24 15:51 ` Logan Gunthorpe
2022-06-02 8:12 ` Xiao Ni
2022-05-09 8:18 ` Donald Buczek
2022-05-09 8:48 ` Guoqing Jiang
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=52e9aa65-581a-63fc-272a-0477f8c6e873@linux.dev \
--to=guoqing.jiang@linux.dev \
--cc=buczek@molgen.mpg.de \
--cc=linux-raid@vger.kernel.org \
--cc=song@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).