Skip to contentSkip to conversation

Kernel page table and module text

DISCUSSION Allison 2 participants 2 messages Apr 19, 2005 – Apr 20, 2005 Proc filesystem

lore
Share & tools
lore

Allison

author
#0 lore raw

I want to do the following.

I want to find where each module is loaded in memory by traversing the module list . Once I have the address and the size of the module, I want to read the bytes in memory of the module and hash it to check it's integrity.

How do I,
1. Traverse the module list and find it's address
2. Read the kernel page table to find the physical address of the module location

thanks,
Allison

Quoted 25 lines · Allison

Hi,

Since module is loaded in non-contiguous memory, there has to be an entry in the kernel page table for all modules that are loaded on the system. I am trying to find entries corresponding to my module text in the page tables.

I am not clear about how the kernel page table is organized after the system switches to protected mode.

I printed out the page starting with swapper_pg_dir . But I do not find the addresses for all the modules loaded in the system.

Do I still need to read the pg0 and pg1 pages ?

If somebody can explain how to traverse the kernel page tables, that would be very helpful.

thanks,
Allison
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#1 lore raw
Quoted 5 lines

I want to find where each module is loaded in memory by traversing the module list . Once I have the address and the size of the module, I want to read the bytes in memory of the module and hash it to check it's integrity.

Heres some code I wrote for Stargames to do a CRC tracking of every module loaded, it may have a race condition on module unload, but it works perfectly for what they want to use it for....

It just runs a kthread doing the CRCing of the kernel test and modules every so often...

I also have similiar code to do the same for shared objects loaded in userspace, but it requires a daemon in userspace to the CRCing whose license I'm not entirely sure of..

Dave.

arch/i386/Kconfig renamed from linux-2.6.10/arch/i386/Kconfig +13 -0
diff -urpN --exclude-from=/storage/devel/dontdiff clean/linux-2.6.10/arch/i386/Kconfig linux-2.6.10/arch/i386/Kconfig
@@ -876,6 +876,24 @@ config REGPARM
 
 endmenu
 
+menu "Stargames Options"
+
+config KERNEL_CRC
+	prompt "Kernel CRC Support"
+	bool
+	default y
+
+config SG_CRC_USE_KERNEL
+	prompt "Use in-kernel routines for CRC"
+	bool
+	default y
+
+endmenu
 
 menu "Power management options (ACPI, APM)"
 	depends on !X86_VOYAGER
fs/proc/root.c renamed from linux-2.6.10/fs/proc/root.c +3 -0
diff -urpN --exclude-from=/storage/devel/dontdiff clean/linux-2.6.10/fs/proc/root.c linux-2.6.10/fs/proc/root.c
@@ -76,6 +76,9 @@ void __init proc_root_init(void)
 #ifdef CONFIG_PROC_DEVICETREE
 	proc_device_tree_init();
 #endif
+#if defined(CONFIG_KERNEL_CRC)
+	proc_mkdir("stargames", 0);
+#endif
 	proc_bus = proc_mkdir("bus", NULL);
 }
 
include/linux/kern_crc.h renamed from linux-2.6.10/include/linux/kern_crc.h +8 -0
diff -urpN --exclude-from=/storage/devel/dontdiff clean/linux-2.6.10/include/linux/kern_crc.h linux-2.6.10/include/linux/kern_crc.h
@@ -0,0 +1,8 @@
+#ifndef LINUX_KERNEL_CRC_H
+#define LINUX_KERNEL_CRC_H
+
+int kernel_crc_init(void);
+int kernel_crc_module_init(const char *modname, const void *modstart);
+int kernel_crc_module_remove(const char *modname);
+int kernel_crc_module_enable(struct module *mod);
+#endif
kernel/kern_crc.c renamed from linux-2.6.10/kernel/kern_crc.c +419 -0

419 lines not on this page · raw message

kernel/Makefile renamed from linux-2.6.10/kernel/Makefile +2 -0
diff -urpN --exclude-from=/storage/devel/dontdiff clean/linux-2.6.10/kernel/Makefile linux-2.6.10/kernel/Makefile
@@ -27,6 +27,9 @@ obj-$(CONFIG_KPROBES) += kprobes.o
 obj-$(CONFIG_SYSFS) += ksysfs.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 
+obj-$(CONFIG_KERNEL_CRC) += kern_crc.o
+
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
 # needed for x86 only.  Why this used to be enabled for all architectures is beyond
kernel/module.c renamed from linux-2.6.10/kernel/module.c +8 -0
diff -urpN --exclude-from=/storage/devel/dontdiff clean/linux-2.6.10/kernel/module.c linux-2.6.10/kernel/module.c
@@ -35,6 +35,7 @@
 #include <linux/notifier.h>
 #include <linux/stop_machine.h>
 #include <linux/device.h>
+#include <linux/kern_crc.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
@@ -1105,6 +1106,9 @@ static void free_module(struct module *m
 	remove_sect_attrs(mod);
 	mod_kobject_remove(mod);
 
+#ifdef CONFIG_KERNEL_CRC
+	kernel_crc_module_remove(mod->name);
+#endif
 	/* Arch-specific cleanup. */
 	module_arch_cleanup(mod);
 
@@ -1775,6 +1779,10 @@ sys_init_module(void __user *umod,
 		return PTR_ERR(mod);
 	}
 
+#ifdef CONFIG_KERNEL_CRC
+	kernel_crc_module_enable(mod);
+#endif
+
 	/* Flush the instruction cache, since we've played with text */
 	if (mod->module_init)
 		flush_icache_range((unsigned long)mod->module_init,