Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151378944
D17512.id49651.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D17512.id49651.diff
View Options
Index: sys/conf/kmod.mk
===================================================================
--- sys/conf/kmod.mk
+++ sys/conf/kmod.mk
@@ -242,7 +242,13 @@
.else
${FULLPROG}: ${OBJS}
.endif
+.if !defined(FIRMWS) && (${MACHINE_CPUARCH} == "i386")
+ ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r \
+ -T ${SYSDIR}/conf/ldscript.set_padding \
+ -d -o ${.TARGET} ${OBJS}
+.else
${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
+.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
.endif
Index: sys/conf/ldscript.set_padding
===================================================================
--- /dev/null
+++ sys/conf/ldscript.set_padding
@@ -0,0 +1,46 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+SECTIONS
+{
+ set_pcpu :
+ {
+ *(set_pcpu)
+ LONG(0xf1f0) ;
+ }
+}
+
+SECTIONS
+{
+ set_vnet :
+ {
+ *(set_vnet)
+ LONG(0xf1f0) ;
+ }
+}
+/* end */
Index: sys/kern/link_elf.c
===================================================================
--- sys/kern/link_elf.c
+++ sys/kern/link_elf.c
@@ -615,10 +615,14 @@
return (0);
}
+#define LS_PADDING 0xf1f0
static int
parse_dpcpu(elf_file_t ef)
{
int error, size;
+#if defined(__i386__)
+ uint32_t pad;
+#endif
ef->pcpu_start = 0;
ef->pcpu_stop = 0;
@@ -631,6 +635,26 @@
/* Empty set? */
if (size < 1)
return (0);
+#if defined(__i386__)
+ /* In case we do find __start/stop_set_ symbols double-check. */
+ if (size < 4) {
+ uprintf("Kernel module '%s' must be recompiled with "
+ "linker script\n", ef->lf.pathname);
+ return (ENOEXEC);
+ }
+
+ /* Padding from linker-script correct? */
+ pad = *(uint32_t *)((uintptr_t)ef->pcpu_stop - sizeof(pad));
+ if (pad != LS_PADDING) {
+ uprintf("Kernel module '%s' must be recompiled with "
+ "linker script, invalid padding %#04x (%#04x)\n",
+ ef->lf.pathname, pad, LS_PADDING);
+ return (ENOEXEC);
+ }
+ /* If we only have valid padding, nothing to do. */
+ if (size == 4)
+ return (0);
+#endif
/*
* Allocate space in the primary pcpu area. Copy in our
* initialization from the data section and then initialize
@@ -652,6 +676,9 @@
parse_vnet(elf_file_t ef)
{
int error, size;
+#if defined(__i386__)
+ uint32_t pad;
+#endif
ef->vnet_start = 0;
ef->vnet_stop = 0;
@@ -664,6 +691,26 @@
/* Empty set? */
if (size < 1)
return (0);
+#if defined(__i386__)
+ /* In case we do find __start/stop_set_ symbols double-check. */
+ if (size < 4) {
+ uprintf("Kernel module '%s' must be recompiled with "
+ "linker script\n", ef->lf.pathname);
+ return (ENOEXEC);
+ }
+
+ /* Padding from linker-script correct? */
+ pad = *(uint32_t *)((uintptr_t)ef->vnet_stop - sizeof(pad));
+ if (pad != LS_PADDING) {
+ uprintf("Kernel module '%s' must be recompiled with "
+ "linker script, invalid padding %#04x (%#04x)\n",
+ ef->lf.pathname, pad, LS_PADDING);
+ return (ENOEXEC);
+ }
+ /* If we only have valid padding, nothing to do. */
+ if (size == 4)
+ return (0);
+#endif
/*
* Allocate space in the primary vnet area. Copy in our
* initialization from the data section and then initialize
@@ -680,6 +727,7 @@
return (0);
}
#endif
+#undef LS_PADDING
static int
link_elf_link_preload(linker_class_t cls,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 9, 12:24 AM (18 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31123878
Default Alt Text
D17512.id49651.diff (4 KB)
Attached To
Mode
D17512: Fix dpcpu and vnet panics with complex types at the end of the section
Attached
Detach File
Event Timeline
Log In to Comment