mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Weilong Chen <chenweilong@huawei.com>
To: <linux-kernel@vger.kernel.org>, <jcm@jonmasters.org>,
	<rusty@rustcorp.com.au>
Subject: [PATCH] Race between cat /proc/kallsyms and rmmod
Date: Sat, 30 Jan 2016 18:23:36 +0800	[thread overview]
Message-ID: <1454149416-105680-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

ref:http://lkml.iu.edu/hypermail/linux/kernel/0703.1/2582.html
    https://bugzilla.kernel.org/show_bug.cgi?id=111541

Signed-off-by: Weilong Chen <chenweilong@huawei.com>
---
 kernel/kallsyms.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 3127ad5..aaecf19 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -515,6 +515,7 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos)
 
 static void *s_start(struct seq_file *m, loff_t *pos)
 {
+	mutex_lock(&module_mutex);
 	if (!update_iter(m->private, *pos))
 		return NULL;
 	return m->private;
@@ -522,6 +523,7 @@ static void *s_start(struct seq_file *m, loff_t *pos)
 
 static void s_stop(struct seq_file *m, void *p)
 {
+	mutex_unlock(&module_mutex);
 }
 
 static int s_show(struct seq_file *m, void *p)
-- 
1.8.3.1

             reply	other threads:[~2016-01-30 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-30 10:23 Weilong Chen [this message]
2016-01-30 10:45 ` kbuild test robot
  -- strict thread matches above, loose matches on Subject: below --
2007-03-14 11:13 Alexey Dobriyan
2007-03-14 12:11 ` Andi Kleen
2007-03-14 12:55 ` Paulo Marques

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=1454149416-105680-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®