Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754086AbbG0KBr (ORCPT ); Mon, 27 Jul 2015 06:01:47 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:24329 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753996AbbG0KBq (ORCPT ); Mon, 27 Jul 2015 06:01:46 -0400 From: He Kuang To: CC: , Subject: [PATCH] module: Fix missing to hold module_mutex lock in module_kallsyms_lookup_name Date: Mon, 27 Jul 2015 10:01:26 +0000 Message-ID: <1437991286-101906-1-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.250] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1589 Lines: 42 Function find_module_all() searches for module by name and must be called with module_mutex. module_kallsyms_lookup_name() calls it without this mutex which emits a warning message (CONFIG_LOCKDEP=y) by failed assertion for testing this module_mutex lock, as following: [ 202.877152] ------------[ cut here ]------------ [ 202.881070] WARNING: CPU: 0 PID: 1010 at kernel/module.c:281 module_assert_mutex+0x35/0x40() [ 202.885446] Modules linked in: test_bpf [ 202.886997] CPU: 0 PID: 1010 Comm: perf Tainted: G W 4.2.0-rc3+ #5 ... This patch wraps this call with mutex_{lock,unlock} and fix the bug. Signed-off-by: He Kuang --- kernel/module.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/module.c b/kernel/module.c index 4d2b82e..43d728b 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -3802,8 +3802,10 @@ unsigned long module_kallsyms_lookup_name(const char *name) /* Don't lock: we're in enough trouble already. */ preempt_disable(); if ((colon = strchr(name, ':')) != NULL) { + mutex_lock(&module_mutex); if ((mod = find_module_all(name, colon - name, false)) != NULL) ret = mod_find_symname(mod, colon+1); + mutex_unlock(&module_mutex); } else { list_for_each_entry_rcu(mod, &modules, list) { if (mod->state == MODULE_STATE_UNFORMED) -- 1.8.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/