public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [2.4] Memleak in drivers/scsi/cpqfcTSinit.c::cpqfcTS_ioctl()
@ 2003-03-13 18:49 Oleg Drokin
  0 siblings, 0 replies; only message in thread
From: Oleg Drokin @ 2003-03-13 18:49 UTC (permalink / raw)
  To: alan, linux-kernel

Hello!

   There is a trivial memleak in drivers/scsi/cpqfcTSinit.c::cpqfcTS_ioctl()
   on error exit paths if copy_to/from_user fails, see the patch below.
   Found with help of smatch + enhanced unfree script.

Bye,
    Oleg

===== drivers/scsi/cpqfcTSinit.c 1.14 vs edited =====
--- 1.14/drivers/scsi/cpqfcTSinit.c	Tue Dec 17 16:18:20 2002
+++ edited/drivers/scsi/cpqfcTSinit.c	Thu Mar 13 21:45:20 2003
@@ -467,8 +467,10 @@
 				// Need data from user?
 				// make sure caller's buffer is in kernel space.
 				if ((vendor_cmd->rw_flag == VENDOR_WRITE_OPCODE) && vendor_cmd->len)
-					if (copy_from_user(buf, vendor_cmd->bufp, vendor_cmd->len))
+					if (copy_from_user(buf, vendor_cmd->bufp, vendor_cmd->len)) {
+						kfree(buf);
 						return (-EFAULT);
+					}
 
 				// copy the CDB (if/when MAX_COMMAND_SIZE is 16, remove copy below)
 				memcpy(&ScsiPassThruCmnd->cmnd[0], &vendor_cmd->cdb[0], MAX_COMMAND_SIZE);
@@ -533,7 +535,7 @@
 				// need to pass data back to user (space)?
 				if ((vendor_cmd->rw_flag == VENDOR_READ_OPCODE) && vendor_cmd->len)
 					if (copy_to_user(vendor_cmd->bufp, buf, vendor_cmd->len))
-						return (-EFAULT);
+						result = -EFAULT;
 
 				if (buf)
 					kfree(buf);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-03-13 18:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-03-13 18:49 [2.4] Memleak in drivers/scsi/cpqfcTSinit.c::cpqfcTS_ioctl() Oleg Drokin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox