Sun Mar 15 19:43:49 2009 UTC ()
Pull up following revision(s) (requested by christos in ticket #458):
	sys/conf/Makefile.kern.inc: revision 1.121
	sys/conf/files: revision 1.940
	sys/kern/init_main.c: revision 1.381
	sys/kern/kern_ssp.c: revision 1.1
	sys/kern/subr_autoconf.c: revision 1.168
	sys/sys/device.h: revision 1.116
	sys/sys/systm.h: revision 1.233
Unbreak ssp kernels. The issue here that when the ssp_init() call was
deferred, it caused the return from the enclosing function to break, as
well as the ssp return on i386. To fix both issues, split configure in
two pieces the one before calling ssp_init and the one after, and move
the ssp_init() call back in main. Put ssp_init() in its own file, and
compile this new file with -fno-stack-protector. Tested on amd64.
XXX: If we want to have ssp kernels working on 5.0, this change needs to
be pulled up.


(snj)
diff -r1.118 -r1.118.4.1 src/sys/conf/Makefile.kern.inc
diff -r1.924 -r1.924.4.1 src/sys/conf/files
diff -r1.371 -r1.371.2.1 src/sys/kern/init_main.c
diff -r0 -r1.2.4.2 src/sys/kern/kern_ssp.c
diff -r1.163.4.1 -r1.163.4.2 src/sys/kern/subr_autoconf.c
diff -r1.112 -r1.112.6.1 src/sys/sys/device.h
diff -r1.228.4.1 -r1.228.4.2 src/sys/sys/systm.h

cvs diff -r1.118 -r1.118.4.1 src/sys/conf/Makefile.kern.inc (expand / switch to context diff)
--- src/sys/conf/Makefile.kern.inc 2008/10/25 22:27:38 1.118
+++ src/sys/conf/Makefile.kern.inc 2009/03/15 19:43:48 1.118.4.1
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.kern.inc,v 1.118 2008/10/25 22:27:38 apb Exp $
+#	$NetBSD: Makefile.kern.inc,v 1.118.4.1 2009/03/15 19:43:48 snj Exp $
 #
 # This file contains common `MI' targets and definitions and it is included
 # at the bottom of each `MD' ${MACHINE}/conf/Makefile.${MACHINE}.
@@ -95,6 +95,7 @@
 .if ${USE_SSP:Uno} == "yes"
 CFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
 LDFLAGS+=-fstack-protector -Wstack-protector --param ssp-buffer-size=1
+COPTS.kern_ssp.c+=	-fno-stack-protector -D__SSP__
 .endif
 
 # If we want the bpendtsleep: label in kern_synch.c, we need to use

cvs diff -r1.924 -r1.924.4.1 src/sys/conf/files (expand / switch to context diff)
--- src/sys/conf/files 2008/10/15 06:51:20 1.924
+++ src/sys/conf/files 2009/03/15 19:43:48 1.924.4.1
@@ -1,4 +1,4 @@
-#	$NetBSD: files,v 1.924 2008/10/15 06:51:20 wrstuden Exp $
+#	$NetBSD: files,v 1.924.4.1 2009/03/15 19:43:48 snj Exp $
 
 #	@(#)files.newconf	7.5 (Berkeley) 5/10/93
 
@@ -1408,6 +1408,7 @@
 file	kern/kern_sig.c
 file	kern/kern_sleepq.c
 file	kern/kern_softint.c
+file	kern/kern_ssp.c
 file	kern/kern_stub.c
 file	kern/kern_subr.c
 file	kern/kern_synch.c

cvs diff -r1.371 -r1.371.2.1 src/sys/kern/init_main.c (expand / switch to context diff)
--- src/sys/kern/init_main.c 2008/10/28 15:33:10 1.371
+++ src/sys/kern/init_main.c 2009/03/15 19:43:48 1.371.2.1
@@ -1,4 +1,4 @@
-/*	$NetBSD: init_main.c,v 1.371 2008/10/28 15:33:10 tsutsui Exp $	*/
+/*	$NetBSD: init_main.c,v 1.371.2.1 2009/03/15 19:43:48 snj Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.371 2008/10/28 15:33:10 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.371.2.1 2009/03/15 19:43:48 snj Exp $");
 
 #include "opt_ddb.h"
 #include "opt_ipsec.h"
@@ -252,53 +252,7 @@
 static void check_console(struct lwp *l);
 static void start_init(void *);
 void main(void);
-void ssp_init(void);
 
-#if defined(__SSP__) || defined(__SSP_ALL__)
-long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
-void __stack_chk_fail(void);
-
-void
-__stack_chk_fail(void)
-{
-	panic("stack overflow detected; terminated");
-}
-
-void
-ssp_init(void)
-{
-	int s;
-
-#ifdef DIAGNOSTIC
-	printf("Initializing SSP:");
-#endif
-	/*
-	 * We initialize ssp here carefully:
-	 *	1. after we got some entropy
-	 *	2. without calling a function
-	 */
-	size_t i;
-	long guard[__arraycount(__stack_chk_guard)];
-
-	arc4randbytes(guard, sizeof(guard));
-	s = splhigh();
-	for (i = 0; i < __arraycount(guard); i++)
-		__stack_chk_guard[i] = guard[i];
-	splx(s);
-#ifdef DIAGNOSTIC
-	for (i = 0; i < __arraycount(guard); i++)
-		printf("%lx ", guard[i]);
-	printf("\n");
-#endif
-}
-#else
-void
-ssp_init(void)
-{
-
-}
-#endif
-
 void __secmodel_none(void);
 __weak_alias(secmodel_start,__secmodel_none);
 void
@@ -506,6 +460,10 @@
 
 	/* Configure the system hardware.  This will enable interrupts. */
 	configure();
+
+	ssp_init();
+
+	configure2();
 
 	ubc_init();		/* must be after autoconfig */
 

File Added: src/sys/kern/kern_ssp.c
/*	$NetBSD: kern_ssp.c,v 1.2.4.2 2009/03/15 19:43:48 snj Exp $	*/

/*-
 * Copyright (c) 2008 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_ssp.c,v 1.2.4.2 2009/03/15 19:43:48 snj Exp $");

#include <sys/systm.h>
#include <sys/intr.h>

#if defined(__SSP__) || defined(__SSP_ALL__)
long __stack_chk_guard[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void __stack_chk_fail(void);

void
__stack_chk_fail(void)
{
	panic("stack overflow detected; terminated");
}

void
ssp_init(void)
{
	int s;

#ifdef DIAGNOSTIC
	printf("Initializing SSP:");
#endif
	/*
	 * We initialize ssp here carefully:
	 *	1. after we got some entropy
	 *	2. without calling a function
	 */
	size_t i;
	long guard[__arraycount(__stack_chk_guard)];

	arc4randbytes(guard, sizeof(guard));
	s = splhigh();
	for (i = 0; i < __arraycount(guard); i++)
		__stack_chk_guard[i] = guard[i];
	splx(s);
#ifdef DIAGNOSTIC
	for (i = 0; i < __arraycount(guard); i++)
		printf("%lx ", guard[i]);
	printf("\n");
#endif
}
#else
void
ssp_init(void)
{
}
#endif

cvs diff -r1.163.4.1 -r1.163.4.2 src/sys/kern/subr_autoconf.c (expand / switch to context diff)
--- src/sys/kern/subr_autoconf.c 2009/02/02 02:38:32 1.163.4.1
+++ src/sys/kern/subr_autoconf.c 2009/03/15 19:43:48 1.163.4.2
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.163.4.1 2009/02/02 02:38:32 snj Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.163.4.2 2009/03/15 19:43:48 snj Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.163.4.1 2009/02/02 02:38:32 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.163.4.2 2009/03/15 19:43:48 snj Exp $");
 
 #include "opt_ddb.h"
 #include "drvctl.h"
@@ -411,11 +411,6 @@
 void
 configure(void)
 {
-	extern void ssp_init(void);
-	CPU_INFO_ITERATOR cii;
-	struct cpu_info *ci;
-	int i, s;
-
 	/* Initialize data structures. */
 	config_init();
 	pmf_init();
@@ -440,9 +435,14 @@
 	 * to be enabled.
 	 */
 	cpu_configure();
+}
 
-	/* Initialize SSP. */
-	ssp_init();
+void
+configure2(void)
+{
+	CPU_INFO_ITERATOR cii;
+	struct cpu_info *ci;
+	int i, s;
 
 	/*
 	 * Now that we've found all the hardware, start the real time

cvs diff -r1.112 -r1.112.6.1 src/sys/sys/device.h (expand / switch to context diff)
--- src/sys/sys/device.h 2008/06/11 15:56:11 1.112
+++ src/sys/sys/device.h 2009/03/15 19:43:48 1.112.6.1
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.112 2008/06/11 15:56:11 drochner Exp $ */
+/* $NetBSD: device.h,v 1.112.6.1 2009/03/15 19:43:48 snj Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -394,6 +394,7 @@
 void	config_init(void);
 void	drvctl_init(void);
 void	configure(void);
+void	configure2(void);
 
 int	config_cfdriver_attach(struct cfdriver *);
 int	config_cfdriver_detach(struct cfdriver *);

cvs diff -r1.228.4.1 -r1.228.4.2 src/sys/sys/systm.h (expand / switch to context diff)
--- src/sys/sys/systm.h 2009/02/26 20:38:00 1.228.4.1
+++ src/sys/sys/systm.h 2009/03/15 19:43:48 1.228.4.2
@@ -1,4 +1,4 @@
-/*	$NetBSD: systm.h,v 1.228.4.1 2009/02/26 20:38:00 snj Exp $	*/
+/*	$NetBSD: systm.h,v 1.228.4.2 2009/03/15 19:43:48 snj Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1988, 1991, 1993
@@ -290,6 +290,8 @@
 #else
 void	ntp_init(void);	/* also provides adjtime() functionality */
 #endif /* NTP */
+
+void	ssp_init(void);
 
 void	initclocks(void);
 void	inittodr(time_t);