[OpenBIOS] [commit] r741 - in trunk/openbios-devel: arch/amd64 arch/ppc/qemu arch/sparc32 arch/sparc64 arch/unix arch/x86 include/arch/amd64 kernel kernel/include

repository service svn at openbios.org
Mon Apr 12 22:02:53 CEST 2010


Author: mcayland
Date: Mon Apr 12 22:02:53 2010
New Revision: 741
URL: http://tracker.coreboot.org/trac/openbios/changeset/741

Log:
Commit revised version of Igor Kovalenko's patch for detecting whether dictionary allocations have overrun the memory 
buffer allocated for them.

Signed-off-by: Igor V. Kovalenko <igor.v.kovalenko at gmail.com>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at siriusit.co.uk>

Modified:
   trunk/openbios-devel/arch/amd64/openbios.c
   trunk/openbios-devel/arch/ppc/qemu/kernel.c
   trunk/openbios-devel/arch/sparc32/openbios.c
   trunk/openbios-devel/arch/sparc64/openbios.c
   trunk/openbios-devel/arch/unix/unix.c
   trunk/openbios-devel/arch/x86/openbios.c
   trunk/openbios-devel/include/arch/amd64/types.h
   trunk/openbios-devel/kernel/dict.c
   trunk/openbios-devel/kernel/forth.c
   trunk/openbios-devel/kernel/include/dict.h

Modified: trunk/openbios-devel/arch/amd64/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/amd64/openbios.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/amd64/openbios.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -19,7 +19,8 @@
 
 void boot(void);
 
-static char intdict[256 * 1024];
+#define DICTIONARY_SIZE (256*1024)      /* 256K for the dictionary   */
+static char intdict[DICTIONARY_SIZE];
 
 static void init_memory(void)
 {
@@ -63,6 +64,8 @@
         collect_sys_info(&sys_info);
 
 	dict=intdict;
+	dictlimit = DICTIONARY_SIZE;
+
 	load_dictionary((char *)sys_info.dict_start,
 			sys_info.dict_end-sys_info.dict_start);
 

Modified: trunk/openbios-devel/arch/ppc/qemu/kernel.c
==============================================================================
--- trunk/openbios-devel/arch/ppc/qemu/kernel.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/ppc/qemu/kernel.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -83,6 +83,8 @@
 initialize_forth( void )
 {
 	dict = malloc(DICTIONARY_SIZE);
+	dictlimit = DICTIONARY_SIZE;
+
 	load_dictionary( forth_dictionary, sizeof(forth_dictionary) );
 
 	PUSH_xt( bind_noname_func(arch_of_init) );

Modified: trunk/openbios-devel/arch/sparc32/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/sparc32/openbios.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/sparc32/openbios.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -185,6 +185,8 @@
         collect_sys_info(&sys_info);
 
         dict = malloc(DICTIONARY_SIZE);
+	dictlimit = DICTIONARY_SIZE;
+
 	load_dictionary((char *)sys_info.dict_start,
 			(unsigned long)sys_info.dict_end
                         - (unsigned long)sys_info.dict_start);

Modified: trunk/openbios-devel/arch/sparc64/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/sparc64/openbios.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/sparc64/openbios.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -519,6 +519,8 @@
         collect_sys_info(&sys_info);
 
         dict = malloc(DICTIONARY_SIZE);
+        dictlimit = DICTIONARY_SIZE;
+
 	load_dictionary((char *)sys_info.dict_start,
 			(unsigned long)sys_info.dict_end
                         - (unsigned long)sys_info.dict_start);

Modified: trunk/openbios-devel/arch/unix/unix.c
==============================================================================
--- trunk/openbios-devel/arch/unix/unix.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/unix/unix.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -485,6 +485,7 @@
 		return 1;
 	}
 
+	dictlimit = DICTIONARY_SIZE;
 	memset(dict, 0, DICTIONARY_SIZE);
 
 	if (!segfault) {

Modified: trunk/openbios-devel/arch/x86/openbios.c
==============================================================================
--- trunk/openbios-devel/arch/x86/openbios.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/arch/x86/openbios.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -22,7 +22,8 @@
 void boot(void);
 void collect_sys_info(struct sys_info *info);
 
-static unsigned char intdict[256 * 1024];
+#define DICTIONARY_SIZE (256*1024)      /* 256K for the dictionary   */
+static unsigned char intdict[DICTIONARY_SIZE];
 
 #ifdef CONFIG_DRIVER_PCI
 static const pci_arch_t default_pci_host = {
@@ -86,6 +87,8 @@
         collect_sys_info(&sys_info);
 
 	dict=intdict;
+	dictlimit = DICTIONARY_SIZE;
+
 	load_dictionary((char *)sys_info.dict_start,
 			(unsigned long)sys_info.dict_end -
 			(unsigned long)sys_info.dict_start);

Modified: trunk/openbios-devel/include/arch/amd64/types.h
==============================================================================
--- trunk/openbios-devel/include/arch/amd64/types.h	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/include/arch/amd64/types.h	Mon Apr 12 22:02:53 2010	(r741)
@@ -23,6 +23,8 @@
 typedef __int128_t   dcell;
 typedef __uint128_t ducell;
 
+#define FMT_ucellx  "%016llx"
+
 #define FMT_elf     "%#x"
 
 #define bitspercell	(sizeof(cell)<<3)

Modified: trunk/openbios-devel/kernel/dict.c
==============================================================================
--- trunk/openbios-devel/kernel/dict.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/kernel/dict.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -21,6 +21,7 @@
 unsigned char *dict = NULL;
 ucell *last;
 cell dicthead = 0;
+cell dictlimit = 0;
 
 /* lfa2nfa
  * converts a link field address to a name field address,

Modified: trunk/openbios-devel/kernel/forth.c
==============================================================================
--- trunk/openbios-devel/kernel/forth.c	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/kernel/forth.c	Mon Apr 12 22:02:53 2010	(r741)
@@ -851,6 +851,14 @@
 #ifdef CONFIG_DEBUG_INTERNAL
 	printk("here!: new value: %x\n", tmp);
 #endif
+
+	if (dictlimit && dicthead >= dictlimit) {
+	    printk("Dictionary space overflow:"
+	            " dicthead=" FMT_ucellx
+	            " dictlimit=" FMT_ucellx
+	            "\n",
+	            dicthead, dictlimit);
+	}
 }
 
 

Modified: trunk/openbios-devel/kernel/include/dict.h
==============================================================================
--- trunk/openbios-devel/kernel/include/dict.h	Mon Apr 12 12:03:05 2010	(r740)
+++ trunk/openbios-devel/kernel/include/dict.h	Mon Apr 12 22:02:53 2010	(r741)
@@ -50,6 +50,7 @@
 
 extern unsigned char	*dict;
 extern cell 		dicthead;
+extern cell		dictlimit;
 extern ucell		*last;
 #ifdef FCOMPILER
 extern ucell *trampoline;



More information about the OpenBIOS mailing list