Commit d3861d44 authored by Jens Axboe's avatar Jens Axboe Committed by Linus Torvalds

[PATCH] cdrom memory leaks

From Szombathelyi György

This fixes a memory leak in the uniform cdrom layer.
parent 9f15e609
...@@ -1869,20 +1869,26 @@ static int cdrom_do_cmd(struct cdrom_device_info *cdi, ...@@ -1869,20 +1869,26 @@ static int cdrom_do_cmd(struct cdrom_device_info *cdi,
if (cgc->buflen < 0 || cgc->buflen >= 131072) if (cgc->buflen < 0 || cgc->buflen >= 131072)
return -EINVAL; return -EINVAL;
if ((ubuf = cgc->buffer)) { usense = cgc->sense;
cgc->sense = &sense;
if (usense && !access_ok(VERIFY_WRITE, usense, sizeof(*usense))) {
return -EFAULT;
}
ubuf = cgc->buffer;
if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
cgc->buffer = kmalloc(cgc->buflen, GFP_KERNEL); cgc->buffer = kmalloc(cgc->buflen, GFP_KERNEL);
if (cgc->buffer == NULL) if (cgc->buffer == NULL)
return -ENOMEM; return -ENOMEM;
} }
usense = cgc->sense;
cgc->sense = &sense;
if (usense && !access_ok(VERIFY_WRITE, usense, sizeof(*usense)))
return -EFAULT;
if (cgc->data_direction == CGC_DATA_READ) { if (cgc->data_direction == CGC_DATA_READ) {
if (!access_ok(VERIFY_READ, ubuf, cgc->buflen)) if (!access_ok(VERIFY_READ, ubuf, cgc->buflen)) {
kfree(cgc->buffer);
return -EFAULT; return -EFAULT;
}
} else if (cgc->data_direction == CGC_DATA_WRITE) { } else if (cgc->data_direction == CGC_DATA_WRITE) {
if (copy_from_user(cgc->buffer, ubuf, cgc->buflen)) { if (copy_from_user(cgc->buffer, ubuf, cgc->buflen)) {
kfree(cgc->buffer); kfree(cgc->buffer);
...@@ -1894,7 +1900,10 @@ static int cdrom_do_cmd(struct cdrom_device_info *cdi, ...@@ -1894,7 +1900,10 @@ static int cdrom_do_cmd(struct cdrom_device_info *cdi,
__copy_to_user(usense, cgc->sense, sizeof(*usense)); __copy_to_user(usense, cgc->sense, sizeof(*usense));
if (!ret && cgc->data_direction == CGC_DATA_READ) if (!ret && cgc->data_direction == CGC_DATA_READ)
__copy_to_user(ubuf, cgc->buffer, cgc->buflen); __copy_to_user(ubuf, cgc->buffer, cgc->buflen);
kfree(cgc->buffer); if (cgc->data_direction == CGC_DATA_READ ||
cgc->data_direction == CGC_DATA_WRITE) {
kfree(cgc->buffer);
}
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment