kallsyms_lookup_buildid() copies the symbol name into the given buffer
so that it can be safely read anytime later. But it just copies pointers
to mod->name and mod->build_id which might get reused after the related
struct module gets removed.

The lifetime of struct module is synchronized using RCU. Take the rcu
read lock for the entire __sprint_symbol().

Reviewed-by: Aaron Tomlin <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
---
 kernel/kallsyms.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index 5bc1646f8639..202d39f5493a 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -471,6 +471,9 @@ static int __sprint_symbol(char *buffer, unsigned long 
address,
        unsigned long offset, size;
        int len;
 
+       /* Prevent module removal until modname and modbuildid are printed */
+       guard(rcu)();
+
        address += symbol_offset;
        len = kallsyms_lookup_buildid(address, &size, &offset, &modname, 
&buildid,
                                       buffer);
-- 
2.52.0


Reply via email to