From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MTSK8-0000S5-Kh for mharc-grub-devel@gnu.org; Tue, 21 Jul 2009 23:16:56 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MTSK6-0000RK-TX for grub-devel@gnu.org; Tue, 21 Jul 2009 23:16:54 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MTSK2-0000PF-CV for grub-devel@gnu.org; Tue, 21 Jul 2009 23:16:54 -0400 Received: from [199.232.76.173] (port=43965 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MTSK2-0000P9-2P for grub-devel@gnu.org; Tue, 21 Jul 2009 23:16:50 -0400 Received: from c60.cesmail.net ([216.154.195.49]:53351) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.60) (envelope-from ) id 1MTSK1-0007iK-M0 for grub-devel@gnu.org; Tue, 21 Jul 2009 23:16:49 -0400 Received: from unknown (HELO smtprelay1.cesmail.net) ([192.168.1.111]) by c60.cesmail.net with ESMTP; 21 Jul 2009 23:16:48 -0400 Received: from mj.roinet.com (static-72-92-88-10.phlapa.fios.verizon.net [72.92.88.10]) by smtprelay1.cesmail.net (Postfix) with ESMTPSA id 5987334C69 for ; Tue, 21 Jul 2009 23:16:46 -0400 (EDT) To: grub-devel@gnu.org From: Pavel Roskin Date: Tue, 21 Jul 2009 23:16:45 -0400 Message-ID: <20090722031645.6348.11610.stgit@mj.roinet.com> In-Reply-To: <20090722031638.6348.79007.stgit@mj.roinet.com> References: <20090722031638.6348.79007.stgit@mj.roinet.com> User-Agent: StGit/0.15-rc1-9-gd8846 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [PATCH 2/4] Fix insmod not to increase refcount above 1 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jul 2009 03:16:55 -0000 grub_dl_get() can return non-NULL for an already loaded module. insmod should not increase it refcount. Only increase refcount if the module is newly loaded or if the module is unused and autoloaded, so that it won't get unloaded automatically. It's not perfect, but close enough. insmod won't lock autoloaded modules with dependencies. But it can be fixed by running insmod on the dependent module. ChangeLog: * kern/corecmd.c (grub_core_cmd_insmod): Exit without increasing refcount if the module is already loaded. --- kern/corecmd.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/kern/corecmd.c b/kern/corecmd.c index 03944f2..078b33e 100644 --- a/kern/corecmd.c +++ b/kern/corecmd.c @@ -102,7 +102,8 @@ grub_core_cmd_insmod (struct grub_command *cmd __attribute__ ((unused)), else mod = grub_dl_load_file (argv[0]); - if (mod) + /* Pin module in memory unless already pinned */ + if (mod && mod->ref_count == 0) grub_dl_ref (mod); return 0;