Skip to content

Commit

Permalink
staging: zcache: fix memory corruption bug
Browse files Browse the repository at this point in the history
This patch fixes a bug where the zv code writes before the allocated
buffer, resulting in system memory corruption. This was introduced
during the switch from xvmalloc to zsmalloc.

Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Seth Jennings authored and Greg Kroah-Hartman committed Feb 29, 2012
1 parent 843c666 commit 041aba1
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/staging/zcache/zcache-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ static struct zv_hdr *zv_create(struct zs_pool *pool, uint32_t pool_id,
u32 size = clen + sizeof(struct zv_hdr);
int chunks = (size + (CHUNK_SIZE - 1)) >> CHUNK_SHIFT;
void *handle = NULL;
char *buf;

BUG_ON(!irqs_disabled());
BUG_ON(chunks >= NCHUNKS);
Expand All @@ -710,14 +709,13 @@ static struct zv_hdr *zv_create(struct zs_pool *pool, uint32_t pool_id,
goto out;
atomic_inc(&zv_curr_dist_counts[chunks]);
atomic_inc(&zv_cumul_dist_counts[chunks]);
zv = (struct zv_hdr *)((char *)cdata - sizeof(*zv));
zv = zs_map_object(pool, handle);
zv->index = index;
zv->oid = *oid;
zv->pool_id = pool_id;
zv->size = clen;
SET_SENTINEL(zv, ZVH);
buf = zs_map_object(pool, handle);
memcpy(buf, zv, clen + sizeof(*zv));
memcpy((char *)zv + sizeof(struct zv_hdr), cdata, clen);
zs_unmap_object(pool, handle);
out:
return handle;
Expand Down

0 comments on commit 041aba1

Please sign in to comment.