public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@steeleye.com>
To: Rusty Russell <rusty@au1.ibm.com>, torvalds@transmeta.com
Cc: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] fix insidious bug with init section identification in the kernel module loader
Date: 12 Jun 2003 16:09:16 -0500	[thread overview]
Message-ID: <1055452158.2117.52.camel@mulgrave> (raw)

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

This problem manifests itself nastily on parisc, where the linker seems
to generate large number of elf sections, often one for each non static
function, with names like

.text.<function name>

The problem is that the kernel/module.c uses the following test to
identify init sections:

                           || strstr(secstrings + s->sh_name, ".init"))

Which will pass if ".init" is matched anywhere in the elf section name. 
Obviously, any parisc sections for functions that begin with "init"
match, and are spuriously dumped into the init code.

The fix that works for me on parisc is just to check the beginning of
the string for ".init".  However, I can't find any document that
guarantees this to be correct.  On the other hand, no non-init section
will begin with ".init", so the patch should be safe, just may be non
optimal.

James


[-- Attachment #2: tmp.diff --]
[-- Type: text/plain, Size: 1208 bytes --]

===== kernel/module.c 1.86 vs edited =====
--- 1.86/kernel/module.c	Wed Jun 11 00:55:09 2003
+++ edited/kernel/module.c	Thu Jun 12 15:46:13 2003
@@ -1194,7 +1194,8 @@
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || strstr(secstrings + s->sh_name, ".init"))
+			    || strncmp(secstrings + s->sh_name,
+				       ".init", 5) == 0)
 				continue;
 			s->sh_entsize = get_offset(&mod->core_size, s);
 			DEBUGP("\t%s\n", secstrings + s->sh_name);
@@ -1209,7 +1210,8 @@
 			if ((s->sh_flags & masks[m][0]) != masks[m][0]
 			    || (s->sh_flags & masks[m][1])
 			    || s->sh_entsize != ~0UL
-			    || !strstr(secstrings + s->sh_name, ".init"))
+			    || strncmp(secstrings + s->sh_name,
+				       ".init", 5) != 0)
 				continue;
 			s->sh_entsize = (get_offset(&mod->init_size, s)
 					 | INIT_OFFSET_MASK);
@@ -1413,7 +1415,7 @@
 		}
 #ifndef CONFIG_MODULE_UNLOAD
 		/* Don't load .exit sections */
-		if (strstr(secstrings+sechdrs[i].sh_name, ".exit"))
+		if (strncmp(secstrings+sechdrs[i].sh_name, ".exit", 5) == 0)
 			sechdrs[i].sh_flags &= ~(unsigned long)SHF_ALLOC;
 #endif
 	}

             reply	other threads:[~2003-06-12 20:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-12 21:09 James Bottomley [this message]
2003-06-13  1:18 ` [PATCH] fix insidious bug with init section identification in the kernel module loader Rusty Russell
2003-06-13  2:57   ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1055452158.2117.52.camel@mulgrave \
    --to=james.bottomley@steeleye.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@au1.ibm.com \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox