summaryrefslogtreecommitdiffstats
path: root/drivers/vhost/vhost.c
diff options
context:
space:
mode:
authorTakuya Yoshikawa2010-05-27 12:03:56 +0200
committerMichael S. Tsirkin2010-05-27 12:55:17 +0200
commita02c37891a9b2d7ce93f9d09455b4f67c4c23b95 (patch)
tree0d2b9b630a2ff0dab8fda16008762bcaa223ca93 /drivers/vhost/vhost.c
parentvhost-net: fix to check the return value of copy_to/from_user() correctly (diff)
downloadkernel-qcow2-linux-a02c37891a9b2d7ce93f9d09455b4f67c4c23b95.tar.gz
kernel-qcow2-linux-a02c37891a9b2d7ce93f9d09455b4f67c4c23b95.tar.xz
kernel-qcow2-linux-a02c37891a9b2d7ce93f9d09455b4f67c4c23b95.zip
vhost: fix the memory leak which will happen when memory_access_ok fails
We need to free newmem when vhost_set_memory() fails to complete. Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost/vhost.c')
-rw-r--r--drivers/vhost/vhost.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index e36620272715..da21ae951826 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -337,8 +337,10 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
return -EFAULT;
}
- if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL)))
+ if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL))) {
+ kfree(newmem);
return -EFAULT;
+ }
oldmem = d->memory;
rcu_assign_pointer(d->memory, newmem);
synchronize_rcu();