Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1206095

[PATCH v3] zram: fix pool name truncation

From Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v3] zram: fix pool name truncation
Date 2015-08-12 15:40 +0200
Message-ID <pWEq7-5Pp-43@gated-at.bofh.it> (permalink)
References <pWhWA-6y2-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


zram_meta_alloc() constructs a pool name for zs_create_pool() call
as
 snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);

However, it defines pool name buffer to be only 8 bytes long
(minus trailing zero), which means that we can have only 1000
pool names: zram0 -- zram999.

With CONFIG_ZSMALLOC_STAT enabled an attempt to create a device
zram1000 can fail if device zram100 already exists, because
snprintf() will truncate new pool name to zram100 and pass it
debugfs_create_dir(), causing:

  debugfs dir <zram100> creation failed
  zram: Error creating memory pool

... and so on.

Fix it by passing zram->disk->disk_name to zram_meta_alloc()
instead of divice_id. We construct zram%d name earlier and
keep it as a ->disk_name, no need to snprintf() it again.

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 drivers/block/zram/zram_drv.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index b088ca9..c87d2f6 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -499,10 +499,9 @@ static void zram_meta_free(struct zram_meta *meta, u64 disksize)
 	kfree(meta);
 }
 
-static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
+static struct zram_meta *zram_meta_alloc(char *pool_name, u64 disksize)
 {
 	size_t num_pages;
-	char pool_name[8];
 	struct zram_meta *meta = kmalloc(sizeof(*meta), GFP_KERNEL);
 
 	if (!meta)
@@ -515,7 +514,6 @@ static struct zram_meta *zram_meta_alloc(int device_id, u64 disksize)
 		goto out_error;
 	}
 
-	snprintf(pool_name, sizeof(pool_name), "zram%d", device_id);
 	meta->mem_pool = zs_create_pool(pool_name, GFP_NOIO | __GFP_HIGHMEM);
 	if (!meta->mem_pool) {
 		pr_err("Error creating memory pool\n");
@@ -1033,7 +1031,7 @@ static ssize_t disksize_store(struct device *dev,
 		return -EINVAL;
 
 	disksize = PAGE_ALIGN(disksize);
-	meta = zram_meta_alloc(zram->disk->first_minor, disksize);
+	meta = zram_meta_alloc(zram->disk->disk_name, disksize);
 	if (!meta)
 		return -ENOMEM;
 
-- 
2.5.0

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

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-08-11 15:40 +0200
  [PATCH v2] zram: fix pool name truncation Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-08-11 17:50 +0200
  [PATCH v3] zram: fix pool name truncation Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-08-12 15:40 +0200
  Re: [PATCH 4.2] zram: fix pool names truncation Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2015-08-12 15:40 +0200

csiph-web