lkml.org 
[lkml]   [2012]   [Feb]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] lkdtm: avoid calling sleeping functions in interrupt context
Date
lkdtm_do_action() could be called in interrupt context,
but it also calls sleeping functions like schedule(),
kmalloc(GFP_KERNEL) etc., for such cases, avoid calling them
if we are in interrupt context.

BTW, check the return value of kmalloc().

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <greg@kroah.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

---
drivers/misc/lkdtm.c | 15 +++++++++++++--
1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index afdef2e..63b23a4 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -311,22 +311,31 @@ static void lkdtm_do_action(enum ctype which)
}
case CT_OVERWRITE_ALLOCATION: {
size_t len = 1020;
- u32 *data = kmalloc(len, GFP_KERNEL);
+ u32 *data = kmalloc(len, GFP_ATOMIC);

+ if (!data)
+ break;
data[1024 / sizeof(u32)] = 0x12345678;
kfree(data);
break;
}
case CT_WRITE_AFTER_FREE: {
size_t len = 1024;
- u32 *data = kmalloc(len, GFP_KERNEL);
+ u32 *data;

+ if (in_interrupt())
+ break;
+ data = kmalloc(len, GFP_KERNEL);
+ if (!data)
+ break;
kfree(data);
schedule();
memset(data, 0x78, len);
break;
}
case CT_SOFTLOCKUP:
+ if (in_interrupt())
+ break;
preempt_disable();
for (;;)
cpu_relax();
@@ -337,6 +346,8 @@ static void lkdtm_do_action(enum ctype which)
cpu_relax();
break;
case CT_HUNG_TASK:
+ if (in_interrupt())
+ break;
set_current_state(TASK_UNINTERRUPTIBLE);
schedule();
break;
--
1.7.7.6


\
 
 \ /
  Last update: 2012-02-01 08:01    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site