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>] [day] [month] [year] [list]
Date:	Fri, 23 Dec 2011 18:52:08 +0530
From:	Ajeet Yadav <ajeet.yadav.77@...il.com>
To:	Phillip Lougher <phillip@...ashfs.org.uk>,
	linux-kernel@...r.kernel.org
Subject: [PATCH 1/2] Squashfs: add assert to cache entry refcount

>From a7bb6c920bdc8341830387cff72726629dfd8730 Mon Sep 17 00:00:00 2001
From: Ajeet Yadav <ajeet.yadav.77@...il.com>
Date: Fri, 23 Dec 2011 17:25:48 +0530
Subject: [PATCH 1/2] Squashfs: add assert to cache entry refcount

squashfs_cache_put() function decrements refcount, if the given
function is incorrectly used, refcount can have negative value.

Add ASSERT to entry->refcount, enabled if CONFIG_SQUASHFS_DEBUGGER
is defined.

Signed-off-by: Ajeet Yadav <ajeet.yadav.77@...il.com>
---
 fs/squashfs/cache.c       |    8 ++++----
 fs/squashfs/squashfs_fs.h |   10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c
index f744be9..88d986a 100644
--- a/fs/squashfs/cache.c
+++ b/fs/squashfs/cache.c
@@ -58,7 +58,7 @@
 #include "squashfs.h"

 /*
- * Look-up block in cache, and increment usage count.  If not in cache, read
+ * Look-up block in cache, and increment reference count.  If not in
cache, read
  * and decompress it from disk.
  */
 struct squashfs_cache_entry *squashfs_cache_get(struct super_block *sb,
@@ -177,15 +177,15 @@ out:


 /*
- * Release cache entry, once usage count is zero it can be reused.
+ * Release cache entry, once reference count is zero it can be reused.
  */
 void squashfs_cache_put(struct squashfs_cache_entry *entry)
 {
 	struct squashfs_cache *cache = entry->cache;

 	spin_lock(&cache->lock);
-	entry->refcount--;
-	if (entry->refcount == 0) {
+	ASSERT(entry->refcount);
+	if (!(--entry->refcount)) {
 		cache->unused++;
 		/*
 		 * If there's any processes waiting for a block to become
diff --git a/fs/squashfs/squashfs_fs.h b/fs/squashfs/squashfs_fs.h
index e8e1464..db6cf53 100644
--- a/fs/squashfs/squashfs_fs.h
+++ b/fs/squashfs/squashfs_fs.h
@@ -463,4 +463,14 @@ struct squashfs_xattr_id_table {
 	__le32			unused;
 };

+#ifdef CONFIG_SQUASHFS_DEBUGGER
+#define ASSERT(x)                                                       \
+	if (!(x)) {                                                     \
+		printk(KERN_WARNING "assertion failed %s:%d: %s\n",     \
+			__FILE__, __LINE__, #x);                         \
+	}
+#else
+#define ASSERT(x) do { } while (0)
+#endif
+
 #endif
-- 
1.6.0.3
--
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