lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Fri, 2 Jul 2010 10:16:11 +0200
From:	Roman Fietze <roman.fietze@...emotive.de>
To:	Jason Baron <jbaron@...hat.com>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] dynamic_debug: parse module parameters to enable dynamic printk at load time

Hello Jason, hello LKML,

On Thursday 01 July 2010 22:43:19 Jason Baron wrote:

> make sense.
> ...
> I would keep as simple as possible for now.

So here we go with a first proposal. I think this can be just a base
for discussions, because I'm not yet used to tweak around in the guts
of the kernel itself, so there must be better solutions compared to
what I can offer here.

BTW, I had to move the ddebug setup below the parameter parsing and
setup, just in case somebody is wondering.

From 7ae21e5fc935e6aef4801e0ebce1886bdd2a7b74 Mon Sep 17 00:00:00 2001
From: Roman Fietze <roman.fietze@...emotive.de>
Date: Fri, 2 Jul 2010 10:06:20 +0200
Subject: [PATCH] dynamic_debug: parse module parameters to enable dynamic 
printk at load time

When a module is loaded do an additional check for a module parameter
named "dprintk" of type bool or int. If this paremeter is unequal to 0
then set the dynamic debug print flag right at load time.

Signed-off-by: Roman Fietze <roman.fietze@...emotive.de>
---
 include/linux/dynamic_debug.h |    2 +-
 kernel/module.c               |   50 +++++++++++++++++++++++++++++++---------
 lib/dynamic_debug.c           |   27 +++++++++++++++++++--
 3 files changed, 63 insertions(+), 16 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index f8c2e17..1b790a7 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -37,7 +37,7 @@ struct _ddebug {
 
 
 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
-				const char *modname);
+				const char *modname, bool p_flag);
 
 #if defined(CONFIG_DYNAMIC_DEBUG)
 extern int ddebug_remove_module(char *mod_name);
diff --git a/kernel/module.c b/kernel/module.c
index 1016b75..58b4713 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1954,10 +1954,35 @@ static inline void add_kallsyms(struct module *mod,
 }
 #endif /* CONFIG_KALLSYMS */
 
-static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
+static void dynamic_debug_setup(struct _ddebug *debug,
+				unsigned int num_debug,
+				struct kernel_param *params,
+				unsigned int num_kp)
 {
 #ifdef CONFIG_DYNAMIC_DEBUG
-	if (ddebug_add_module(debug, num, debug->modname))
+	bool p_flag = 0;
+
+	while (num_kp--) {
+		if (!strcmp("dprintk", params->name)) {
+			if (params->get == param_get_bool) {
+				if (params->flags & KPARAM_ISBOOL)
+					p_flag = *(bool *)params->arg;
+				else
+					p_flag = *(int *)params->arg;
+			}
+			else if (params->get == param_get_int) {
+				p_flag = *((int *)params->arg);
+			}
+			else {
+				pr_err("invalid type of dprintk module "
+				       "parameter adding module: %s\n",
+				       debug->modname);
+			}
+			break;
+		}
+		params++;
+	}
+	if (ddebug_add_module(debug, num_debug, debug->modname, p_flag))
 		printk(KERN_ERR "dynamic debug error adding module: %s\n",
 					debug->modname);
 #endif
@@ -2387,16 +2412,6 @@ static noinline struct module *load_module(void __user 
*umod,
 	kfree(strmap);
 	strmap = NULL;
 
-	if (!mod->taints) {
-		struct _ddebug *debug;
-		unsigned int num_debug;
-
-		debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
-				     sizeof(*debug), &num_debug);
-		if (debug)
-			dynamic_debug_setup(debug, num_debug);
-	}
-
 	err = module_finalize(hdr, sechdrs, mod);
 	if (err < 0)
 		goto cleanup;
@@ -2443,6 +2458,17 @@ static noinline struct module *load_module(void __user 
*umod,
 	add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
 	add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
 
+	if (!mod->taints) {
+		struct _ddebug *debug;
+		unsigned int num_debug;
+
+		debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
+				     sizeof(*debug), &num_debug);
+		if (debug)
+			dynamic_debug_setup(debug, num_debug,
+					    mod->kp, mod->num_kp);
+	}
+
 	/* Get rid of temporary copy */
 	vfree(hdr);
 
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index d6b8b9b..2ea876b 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -652,7 +652,7 @@ static const struct file_operations ddebug_proc_fops = {
  * and add it to the global list.
  */
 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
-			     const char *name)
+		      const char *name, bool p_flag)
 {
 	struct ddebug_table *dt;
 	char *new_name;
@@ -671,6 +671,26 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int 
n,
 	dt->ddebugs = tab;
 
 	mutex_lock(&ddebug_lock);
+	if (p_flag) {
+		struct _ddebug *dp = dt->ddebugs;
+		size_t i = dt->num_ddebugs;
+		while (i--) {
+			dp->flags |= _DPRINTK_FLAGS_PRINT;
+			dt->num_enabled++;
+			dynamic_debug_enabled |= (1LL << dp->primary_hash);
+			dynamic_debug_enabled2 |= (1LL << dp->secondary_hash);
+			if (verbose) {
+				char flagbuf[8];
+				printk(KERN_INFO
+				       "ddebug: added %s:%d [%s]%s %s\n",
+				       dp->filename, dp->lineno,
+				       dt->mod_name, dp->function,
+				       ddebug_describe_flags(dp, flagbuf,
+							     
sizeof(flagbuf)));
+			}
+			dp++;
+		}
+	}
 	list_add_tail(&dt->link, &ddebug_tables);
 	mutex_unlock(&ddebug_lock);
 
@@ -748,7 +768,8 @@ static int __init dynamic_debug_init(void)
 		iter_start = iter;
 		for (; iter < __stop___verbose; iter++) {
 			if (strcmp(modname, iter->modname)) {
-				ret = ddebug_add_module(iter_start, n, 
modname);
+				ret = ddebug_add_module(iter_start, n, 
modname,
+							0);
 				if (ret)
 					goto out_free;
 				n = 0;
@@ -757,7 +778,7 @@ static int __init dynamic_debug_init(void)
 			}
 			n++;
 		}
-		ret = ddebug_add_module(iter_start, n, modname);
+		ret = ddebug_add_module(iter_start, n, modname, 0);
 	}
 out_free:
 	if (ret) {
-- 
1.7.1




Roman

-- 
Roman Fietze                Telemotive AG Büro Mühlhausen
Breitwiesen                              73347 Mühlhausen
Tel.: +49(0)7335/18493-45        http://www.telemotive.de

Amtsgericht Ulm                                HRB 541321
Vorstand:
Peter Kersten, Markus Fischer, Franz Diller, Markus Stolz

Download attachment "signature.asc " of type "application/pgp-signature" (199 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ