All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Check copy_*_user return value in drivers/block/scsi_ioctl.c
@ 2003-05-25 16:25 Paulo Andre'
  2003-05-25 16:28 ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Paulo Andre' @ 2003-05-25 16:25 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 218 bytes --]

Hi Jens,

Please find attached a trivial patch that checks both
copy_to_user() and copy_from_user() returns values in scsi_ioctl.c,
returning accordinly in case of a transfer error.

Please review.


		Paulo Andre'




[-- Attachment #2: patch-scsi_ioctl.c.diff --]
[-- Type: text/plain, Size: 1248 bytes --]

--- scsi_ioctl.c.orig	2003-05-25 16:42:22.000000000 +0100
+++ scsi_ioctl.c	2003-05-25 16:59:44.000000000 +0100
@@ -213,7 +213,8 @@
 
 			nr_sectors = bytes >> 9;
 			if (writing)
-				copy_from_user(buffer,hdr.dxferp,hdr.dxfer_len);
+				if (copy_from_user(buffer,hdr.dxferp,hdr.dxfer_len))
+					goto efault;
 			else
 				memset(buffer, 0, hdr.dxfer_len);
 		}
@@ -225,7 +226,8 @@
 	 * fill in request structure
 	 */
 	rq->cmd_len = hdr.cmd_len;
-	copy_from_user(rq->cmd, hdr.cmdp, hdr.cmd_len);
+	if (copy_from_user(rq->cmd, hdr.cmdp, hdr.cmd_len))
+		goto efault;
 	if (sizeof(rq->cmd) != hdr.cmd_len)
 		memset(rq->cmd + hdr.cmd_len, 0, sizeof(rq->cmd) - hdr.cmd_len);
 
@@ -286,17 +288,23 @@
 
 	blk_put_request(rq);
 
-	copy_to_user(uptr, &hdr, sizeof(*uptr));
+	if (copy_to_user(uptr, &hdr, sizeof(*uptr)))
+		goto efault;
 
 	if (buffer) {
 		if (reading)
-			copy_to_user(hdr.dxferp, buffer, hdr.dxfer_len);
+			if (copy_to_user(hdr.dxferp, buffer, hdr.dxfer_len))
+				goto efault;
 
 		kfree(buffer);
 	}
 	/* may not have succeeded, but output values written to control
 	 * structure (struct sg_io_hdr).  */
 	return 0;
+efault:
+	if (buffer)
+		kfree(buffer);
+	return -EFAULT;
 }
 
 #define FORMAT_UNIT_TIMEOUT		(2 * 60 * 60 * HZ)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-05-25 18:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-05-25 16:25 [PATCH] Check copy_*_user return value in drivers/block/scsi_ioctl.c Paulo Andre'
2003-05-25 16:28 ` Jens Axboe
2003-05-25  1:29   ` dan carpenter
2003-05-25 16:54   ` Oliver Neukum
2003-05-25 16:58   ` Paulo Andre'

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.