Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Oct 2020 23:14:49 +0000 (UTC)
From:      Mitchell Horne <mhorne@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r366526 - head/sys/kern
Message-ID:  <202010072314.097NEnp0056874@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mhorne
Date: Wed Oct  7 23:14:49 2020
New Revision: 366526
URL: https://svnweb.freebsd.org/changeset/base/366526

Log:
  Handle kmod local relocation failures gracefully
  
  It is possible for elf_reloc_local() to fail in the unlikely case of
  an unsupported relocation type. If this occurs, do not continue to
  process the file.
  
  Reviewed by:	kib, markj (earlier version)
  MFC after:	1 week
  Sponsored by:	NetApp, Inc.
  Sponsored by:	Klara, Inc.
  Differential Revision:	https://reviews.freebsd.org/D26701

Modified:
  head/sys/kern/link_elf_obj.c

Modified: head/sys/kern/link_elf_obj.c
==============================================================================
--- head/sys/kern/link_elf_obj.c	Wed Oct  7 22:52:24 2020	(r366525)
+++ head/sys/kern/link_elf_obj.c	Wed Oct  7 23:14:49 2020	(r366526)
@@ -1676,9 +1676,11 @@ link_elf_reloc_local(linker_file_t lf, bool ifuncs)
 			if (ELF_ST_BIND(sym->st_info) != STB_LOCAL)
 				continue;
 			if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC ||
-			    elf_is_ifunc_reloc(rel->r_info)) == ifuncs)
-				elf_reloc_local(lf, base, rel, ELF_RELOC_REL,
-				    elf_obj_lookup);
+			    elf_is_ifunc_reloc(rel->r_info)) != ifuncs)
+				continue;
+			if (elf_reloc_local(lf, base, rel, ELF_RELOC_REL,
+			    elf_obj_lookup) != 0)
+				return (ENOEXEC);
 		}
 	}
 
@@ -1704,9 +1706,11 @@ link_elf_reloc_local(linker_file_t lf, bool ifuncs)
 			if (ELF_ST_BIND(sym->st_info) != STB_LOCAL)
 				continue;
 			if ((ELF_ST_TYPE(sym->st_info) == STT_GNU_IFUNC ||
-			    elf_is_ifunc_reloc(rela->r_info)) == ifuncs)
-				elf_reloc_local(lf, base, rela, ELF_RELOC_RELA,
-				    elf_obj_lookup);
+			    elf_is_ifunc_reloc(rela->r_info)) != ifuncs)
+				continue;
+			if (elf_reloc_local(lf, base, rela, ELF_RELOC_RELA,
+			    elf_obj_lookup) != 0)
+				return (ENOEXEC);
 		}
 	}
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202010072314.097NEnp0056874>