Skip to contentSkip to conversation

PATCH: Fix modutils to check ELF symbol index

PATCH H . J . Lu 2 participants 2 messages Aug 20, 2001 – Aug 21, 2001

lore
Share & tools
lore

H . J . Lu

author
#0 lore raw

Hi Keith,

All my previous email sent to you are bounced. I am sending this to the kernel mailing list, hoping you will read it..

H.J.
---

obj/obj_load.c renamed from obj/obj_load.c.symbol +9 -1
@@ -257,7 +257,7 @@ obj_load (int fp, Elf32_Half e_type, con
 	{
 	case SHT_RELM:
 	  {
-	    unsigned long nrel, j;
+	    unsigned long nrel, j, nsyms;
 	    ElfW(RelM) *rel;
 	    struct obj_section *symtab;
 	    char *strtab;
@@ -273,6 +273,7 @@ obj_load (int fp, Elf32_Half e_type, con
 	    nrel = sec->header.sh_size / sizeof(ElfW(RelM));
 	    rel = (ElfW(RelM) *) sec->contents;
 	    symtab = f->sections[sec->header.sh_link];
+	    nsyms = symtab->header.sh_size / symtab->header.sh_entsize;
 	    strtab = f->sections[symtab->header.sh_link]->contents;
 
 	    /* Save the relocate type in each symbol entry.  */
@@ -284,6 +285,13 @@ obj_load (int fp, Elf32_Half e_type, con
 		symndx = ELFW(R_SYM)(rel->r_info);
 		if (symndx)
 		  {
+		    if (symndx >= nsyms)
+		      {
+			error("%s: Bad symbol index: %08lx >= %08lx",
+			      filename, symndx, nsyms);
+			continue;
+		      }
+
 		    extsym = ((ElfW(Sym) *) symtab->contents) + symndx;
 		    if (ELFW(ST_BIND)(extsym->st_info) == STB_LOCAL)
 		      {
obj/obj_reloc.c renamed from obj/obj_reloc.c.symbol +9 -0
@@ -284,6 +284,7 @@ obj_relocate (struct obj_file *f, ElfW(A
       ElfW(RelM) *rel, *relend;
       ElfW(Sym) *symtab;
       const char *strtab;
+      unsigned long nsyms;
 
       relsec = f->sections[i];
       if (relsec->header.sh_type != SHT_RELM)
@@ -296,6 +297,7 @@ obj_relocate (struct obj_file *f, ElfW(A
       rel = (ElfW(RelM) *)relsec->contents;
       relend = rel + (relsec->header.sh_size / sizeof(ElfW(RelM)));
       symtab = (ElfW(Sym) *)symsec->contents;
+      nsyms = symsec->header.sh_size / symsec->header.sh_entsize;
       strtab = (const char *)strsec->contents;
 
       for (; rel < relend; ++rel)
@@ -312,6 +314,13 @@ obj_relocate (struct obj_file *f, ElfW(A
 	  if (symndx)
 	    {
 	      /* Note we've already checked for undefined symbols.  */
+
+	      if (symndx >= nsyms)
+		{
+		  error("Bad symbol index: %08lx >= %08lx",
+			symndx, nsyms);
+		  continue;
+		}
 
 	      extsym = &symtab[symndx];
 	      if (ELFW(ST_BIND)(extsym->st_info) == STB_LOCAL)
#1 lore raw
Quoted 4 lines · H . J . Lu

Hi Keith,

All my previous email sent to you are bounced. I am sending this to the kernel mailing list, hoping you will read it..

My mail logs for August only show 2 attempts from 24.176.137.160, both in the past 12 hours. The first was blocked with a 451 response because the reverse DNS lookup failed, blame home.com for not doing anything about spammers. The second got through because reverse DNS worked.

Patch will be in modutils 2.4.8, thanks.