Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6211439ybe; Tue, 17 Sep 2019 23:01:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyim6C17ZGbR9eXMSld6N1z/N+WBlR3spAvDHU7/P7NbrGRlVBjtVPfGPLUBUbdbAmpn0hG X-Received: by 2002:a05:6402:13c9:: with SMTP id a9mr1914236edx.25.1568786465749; Tue, 17 Sep 2019 23:01:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568786465; cv=none; d=google.com; s=arc-20160816; b=eCKWUlKP/ytE93dLBM2AL3wLY5bUDRxUO0B+vKnbgKJBQbchIED7cG2QOwxmndn78n /jIgk9XXllQljjhKJw/5nq48VX7syqHA7YWvDE7Jnf0bBYEMlI3WZnny1zrbmbRZVQNY kl6+hH0p06MUCcvP+LrolJZOFkSbZvuGrhowKIhhPHSY7vKAroQaDCyOOvglhnXWcH54 tzBZsWjovRh2tgFxYEWFwJST0MAak7u3lJLbu+BjIRbQnxuwSLzjIRzt4jl02GqZpoB1 0qgApTBeYA0U/Xnu4rL1AWZmSBaC/okk9AkFW6cuGtn4p0YAa8RKW7S/cSOVV7f35380 dSNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=GkBQYZE5ti5Qs9+7mzwZj649MzXZd/pkxd82kwRRR6I=; b=nUlYHYSZgmhkX6rd+XGDAVByCXoTFCtGKOaCAHKzeDXI/kNyuoZThy9igLM4cxT5yh I3EBH5DNU3g3DhjkNlqt0gIEj9z7l7u9dwvRvNKd2KIzlHcZvTK2WWyKnIcluHUMtK2B DpeJqdJiqBVWUNJZ62xevf9/p823zQ0r7PX4h1BATwobrw0Xs0KpxMJPQb6HRpeRW3fW 3N4dkxSHXpYpLva7Y7QZDf6XTj29i6lgIV6Umn57e82m8zdlHQR+tnfg2zOIamc4fSzU Xb/nEBN+4wPkfZbRGJLLP8IseL0DE1L8l2TbJATt/dVOu4XtPEgsLDJyEf5NaVOAjcER PXDw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si2742785edc.386.2019.09.17.23.00.42; Tue, 17 Sep 2019 23:01:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728224AbfIRDJr (ORCPT + 99 others); Tue, 17 Sep 2019 23:09:47 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33988 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728206AbfIRDJq (ORCPT ); Tue, 17 Sep 2019 23:09:46 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5335DCD535D0C4A99B76; Wed, 18 Sep 2019 11:09:44 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.177) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.439.0; Wed, 18 Sep 2019 11:09:36 +0800 From: chenzefeng To: , , , , CC: , , , , , Subject: [PATCH] arm:unwind: fix incorrect backtrace with unwind_table Date: Wed, 18 Sep 2019 11:09:34 +0800 Message-ID: <1568776174-84980-1-git-send-email-chenzefeng2@huawei.com> X-Mailer: git-send-email 1.8.5.6 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.177] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For arm, if the CONFIG_ARM_UNWIND is open, when insmod a module, the init section add to the unwind_table, the code path as follow: load_module --->post_relocation ------->module_finalize ----------->maps[ARM_SEC_INIT].txt_sec = s ----------->unwind_table_add Later if load_module success, the init section's memory will be vfree, the code path as follow: load_module --->do_init_module ------->freeinit->module_init = mod->init_layout.base ------->schedule_work(&init_free_wq) ----------->do_free_init --------------->vfree(freeinit->module_init) But after the init section's had been vfree, but it's unwind_table is not removed. The issue as follow: When insmod module A, the system alloc the "Addr1" for it's init text section, and add it to the unwind_table list, after insmod success, the "Addr1" would be vfreed. Unfortunately, later insmod module B, the system alloc the "Addr1" for it's text section, and add it to the unwind_table list, too. And we dumpstack in module B, we may get a incorrect backtrace. Signed-off-by: chenzefeng --- arch/arm/kernel/module.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index deef17f..438ed67 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -410,7 +410,20 @@ int module_finalize(const Elf32_Ehdr *hdr, const Elf_Shdr *sechdrs, int i; for (i = 0; i < ARM_SEC_MAX; i++) - if (mod->arch.unwind[i]) + if (mod->arch.unwind[i]) { unwind_table_del(mod->arch.unwind[i]); + mod->arch.unwind[i] = NULL; + } +#endif +} + +void +module_arch_freeing_init(struct module *mod) +{ +#ifdef CONFIG_ARM_UNWIND + if (mod->arch.unwind[ARM_SEC_INIT]) { + unwind_table_del(mod->arch.unwind[ARM_SEC_INIT]); + mod->arch.unwind[ARM_SEC_INIT] = NULL; + } #endif } -- 1.8.5.6