Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Nov 2014 01:25:19 +0000 (UTC)
From:      Peter Grehan <grehan@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r274942 - stable/10/sys/boot/common
Message-ID:  <201411240125.sAO1PJkd008067@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: grehan
Date: Mon Nov 24 01:25:19 2014
New Revision: 274942
URL: https://svnweb.freebsd.org/changeset/base/274942

Log:
  MFC r274407
  
    Fix incorrect reading of 32-bit modinfo by 64-bit loaders.
  
    The various structures in the mod_metadata set of a FreeBSD kernel and
    modules contain pointers. The FreeBSD loader correctly deals with a
    mismatch in loader and kernel pointer size (e.g. 32-bit i386/ppc
    loader, loading 64-bit amd64/ppc64 kernels), but wasn't dealing with
    the inverse case where a 64-bit loader was loading a 32-bit kernel.

Modified:
  stable/10/sys/boot/common/load_elf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/common/load_elf.c
==============================================================================
--- stable/10/sys/boot/common/load_elf.c	Mon Nov 24 01:13:58 2014	(r274941)
+++ stable/10/sys/boot/common/load_elf.c	Mon Nov 24 01:25:19 2014	(r274942)
@@ -610,6 +610,14 @@ struct mod_metadata64 {
 	u_int64_t	md_cval;	/* common string label */
 };
 #endif
+#if defined(__amd64__) && __ELF_WORD_SIZE == 32
+struct mod_metadata32 {
+	int		md_version;	/* structure version MDTV_* */  
+	int		md_type;	/* type of entry MDT_* */
+	u_int32_t	md_data;	/* specific data */
+	u_int32_t	md_cval;	/* common string label */
+};
+#endif
 
 int
 __elfN(parse_modmetadata)(struct preloaded_file *fp, elf_file_t ef)
@@ -617,6 +625,8 @@ __elfN(parse_modmetadata)(struct preload
     struct mod_metadata md;
 #if (defined(__i386__) || defined(__powerpc__)) && __ELF_WORD_SIZE == 64
     struct mod_metadata64 md64;
+#elif defined(__amd64__) && __ELF_WORD_SIZE == 32
+    struct mod_metadata32 md32;
 #endif
     struct mod_depend *mdepend;
     struct mod_version mver;
@@ -652,6 +662,18 @@ __elfN(parse_modmetadata)(struct preload
 	md.md_type = md64.md_type;
 	md.md_cval = (const char *)(uintptr_t)md64.md_cval;
 	md.md_data = (void *)(uintptr_t)md64.md_data;
+#elif defined(__amd64__) && __ELF_WORD_SIZE == 32
+	COPYOUT(v, &md32, sizeof(md32));
+	error = __elfN(reloc_ptr)(fp, ef, v, &md32, sizeof(md32));
+	if (error == EOPNOTSUPP) {
+	    md32.md_cval += ef->off;
+	    md32.md_data += ef->off;
+	} else if (error != 0)
+	    return (error);
+	md.md_version = md32.md_version;
+	md.md_type = md32.md_type;
+	md.md_cval = (const char *)(uintptr_t)md32.md_cval;
+	md.md_data = (void *)(uintptr_t)md32.md_data;
 #else
 	COPYOUT(v, &md, sizeof(md));
 	error = __elfN(reloc_ptr)(fp, ef, v, &md, sizeof(md));



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