lkml.org 
[lkml]   [2016]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH] Race between cat /proc/kallsyms and rmmod
    Date
    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
    \
     
     \ /
      Last update: 2016-01-30 11:41    [W:5.365 / U:0.012 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site