From: Weilong Chen <chenweilong@huawei.com>
To: <linux-kernel@vger.kernel.org>, <jcm@jonmasters.org>,
<rusty@rustcorp.com.au>
Subject: [PATCH v2] Race between cat /proc/kallsyms and rmmod
Date: Mon, 1 Feb 2016 09:51:32 +0800 [thread overview]
Message-ID: <1454291492-105918-1-git-send-email-chenweilong@huawei.com> (raw)
Iterating code of /proc/kallsyms calls module_get_kallsym() which grabs
and drops module_mutex internally and returns "struct module *",
module is removed, aforementioned "struct module *" is used in non-trivial
way.
So, grab module_mutex for entire operation like /proc/modules does.
Steps to reproduce:
while true; do modprobe xfs; rmmod xfs; done
vs
while true; do cat /proc/kallsyms >/dev/null; done
Signed-off-by: Weilong Chen <chenweilong@huawei.com>
---
kernel/kallsyms.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 5c5987f..e09df60 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -516,6 +516,9 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos)
static void *s_start(struct seq_file *m, loff_t *pos)
{
+#ifdef CONFIG_MODULES
+ mutex_lock(&module_mutex);
+#endif
if (!update_iter(m->private, *pos))
return NULL;
return m->private;
@@ -523,6 +526,9 @@ static void *s_start(struct seq_file *m, loff_t *pos)
static void s_stop(struct seq_file *m, void *p)
{
+#ifdef CONFIG_MODULES
+ mutex_unlock(&module_mutex);
+#endif
}
static int s_show(struct seq_file *m, void *p)
--
1.8.3.1
next reply other threads:[~2016-02-01 1:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-01 1:51 Weilong Chen [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-03-14 11:40 Alexey Dobriyan
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=1454291492-105918-1-git-send-email-chenweilong@huawei.com \
--to=chenweilong@huawei.com \
--cc=jcm@jonmasters.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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®