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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Wed,  1 Feb 2012 14:58:19 +0800
From:	Cong Wang <xiyou.wangcong@...il.com>
To:	linux-kernel@...r.kernel.org
Cc:	Andrew Morton <akpm@...ux-foundation.org>,
	Cong Wang <xiyou.wangcong@...il.com>,
	Prarit Bhargava <prarit@...hat.com>,
	Arnd Bergmann <arnd@...db.de>,
	Greg Kroah-Hartman <greg@...ah.com>,
	Dave Young <dyoung@...hat.com>
Subject: [PATCH 1/2] lkdtm: use atomic_t to replace count_lock

Andrew, this patch replaces
lkdtm-avoid-calling-lkdtm_do_action-with-spin-lock-held.patch
in your tree.

---------->

The spin lock count_lock only protects count, it can be removed by
using atomic_t. Suggested by Arnd.

Cc: Prarit Bhargava <prarit@...hat.com>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: Greg Kroah-Hartman <greg@...ah.com>
Cc: Dave Young <dyoung@...hat.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Signed-off-by: Cong Wang <xiyou.wangcong@...il.com>

---
 drivers/misc/lkdtm.c |   19 ++++---------------
 1 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 150cd70..afdef2e 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -119,8 +119,7 @@ static int recur_count = REC_NUM_DEFAULT;
 
 static enum cname cpoint = CN_INVALID;
 static enum ctype cptype = CT_NONE;
-static int count = DEFAULT_COUNT;
-static DEFINE_SPINLOCK(count_lock);
+static atomic_t count = ATOMIC_INIT(DEFAULT_COUNT);
 
 module_param(recur_count, int, 0644);
 MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
@@ -231,14 +230,11 @@ static const char *cp_name_to_str(enum cname name)
 static int lkdtm_parse_commandline(void)
 {
 	int i;
-	unsigned long flags;
 
 	if (cpoint_count < 1 || recur_count < 1)
 		return -EINVAL;
 
-	spin_lock_irqsave(&count_lock, flags);
-	count = cpoint_count;
-	spin_unlock_irqrestore(&count_lock, flags);
+	atomic_set(&count, cpoint_count);
 
 	/* No special parameters */
 	if (!cpoint_type && !cpoint_name)
@@ -353,18 +349,11 @@ static void lkdtm_do_action(enum ctype which)
 
 static void lkdtm_handler(void)
 {
-	unsigned long flags;
-
-	spin_lock_irqsave(&count_lock, flags);
-	count--;
 	printk(KERN_INFO "lkdtm: Crash point %s of type %s hit, trigger in %d rounds\n",
-			cp_name_to_str(cpoint), cp_type_to_str(cptype), count);
+			cp_name_to_str(cpoint), cp_type_to_str(cptype), atomic_dec_return(&count));
 
-	if (count == 0) {
+	if (!atomic_cmpxchg(&count, 0, cpoint_count))
 		lkdtm_do_action(cptype);
-		count = cpoint_count;
-	}
-	spin_unlock_irqrestore(&count_lock, flags);
 }
 
 static int lkdtm_register_cpoint(enum cname which)
-- 
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ