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:	Thu, 26 Aug 2010 11:04:01 -0500
From:	Jeffrey Carlyle <jeff.carlyle@...orola.com>
To:	torvalds@...l.org
Cc:	linux-kernel@...r.kernel.org, tj@...nel.org, jaxboe@...ionio.com,
	OLUSANYA SOYANNWO <c23746@...orola.com>,
	Hu Tao <taohu@...orola.com>
Subject: [PATCH] scatterlist: prevent invalid free when alloc fails

When alloc fails, free_table is being called. Depending on the number of
bytes requested, we determine if we are going to call _get_free_page()
or kmalloc(). When alloc fails, our math is wrong (due to sg_size - 1),
and the last buffer is wrongfully assumed to have been allocated by
kmalloc. Hence, kfree gets called and a panic occurs.

This fix sets the end marker and allows the proper freeing of the
buffers.

Signed-off-by: Olusanya Soyannwo <c23746@...orola.com>
Cc: Tejun Heo <tj@...nel.org>
Cc: Jens Axboe <jaxboe@...ionio.com>
Signed-off-by: Jeffrey Carlyle <jeff.carlyle@...orola.com>
---
 lib/scatterlist.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index a5ec428..acf2c6e 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -163,7 +163,7 @@ void __sg_free_table(struct sg_table *table,
unsigned int max_ents,
 		return;

 	sgl = table->sgl;
-	while (table->orig_nents) {
+	while (table->orig_nents && sgl) {
 		unsigned int alloc_size = table->orig_nents;
 		unsigned int sg_size;

@@ -227,6 +227,7 @@ int __sg_alloc_table(struct sg_table *table,
unsigned int nents,
 {
 	struct scatterlist *sg, *prv;
 	unsigned int left;
+	unsigned int total_alloc = 0;

 #ifndef ARCH_HAS_SG_CHAIN
 	BUG_ON(nents > max_ents);
@@ -248,8 +249,14 @@ int __sg_alloc_table(struct sg_table *table,
unsigned int nents,
 		left -= sg_size;

 		sg = alloc_fn(alloc_size, gfp_mask);
-		if (unlikely(!sg))
+		if (unlikely(!sg)) {
+			table->orig_nents = total_alloc;
+			/* mark the end of previous entry */
+			sg_mark_end(&prv[alloc_size - 1]);
 			return -ENOMEM;
+		}
+
+		total_alloc += alloc_size;

 		sg_init_table(sg, alloc_size);
 		table->nents = table->orig_nents += sg_size;
-- 
1.6.3.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