lkml.org 
[lkml]   [2008]   [Jan]   [4]   [last100]   RSS Feed
Views: [more markup]  [less markup]  [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
DateFri, 4 Jan 2008 15:38:58 +0800
FromDave Young <>
SubjectRe: [PATCH][BUG 3879] add some check before scsi_cmd_ioctl
On Fri, Jan 04, 2008 at 03:28:26PM +0800, Dave Young wrote:
> The behaviour of eject/lock_door ioctl is not consistent, so add some check before scsi_cmd_ioctl.
> 
> Signed-off-by: Dave Young <hidave.darkstar@gmail.com> 
> 
> ---
> drivers/cdrom/cdrom.c |   42 ++++++++++++++++++++++++++++++++++++------
> 1 file changed, 36 insertions(+), 6 deletions(-)
> 
Sorry, should be this one:

The behaviour of eject/lock_door ioctl is not consistent, so add some check before scsi_cmd_ioctl.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com> 
---
drivers/cdrom/cdrom.c |   47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff -upr linux/drivers/cdrom/cdrom.c linux.new/drivers/cdrom/cdrom.c
--- linux/drivers/cdrom/cdrom.c	2008-01-04 15:32:09.000000000 +0800
+++ linux.new/drivers/cdrom/cdrom.c	2008-01-04 15:34:00.000000000 +0800
@@ -2236,14 +2236,22 @@ static int cdrom_ioctl_multisession(stru
 	return 0;
 }
 
-static int cdrom_ioctl_eject(struct cdrom_device_info *cdi)
+static int cdrom_eject_check(struct cdrom_device_info *cdi)
 {
-	cdinfo(CD_DO_IOCTL, "entering CDROMEJECT\n");
-
 	if (!CDROM_CAN(CDC_OPEN_TRAY))
 		return -ENOSYS;
 	if (cdi->use_count != 1 || keeplocked)
 		return -EBUSY;
+	return 0;
+}
+
+static int cdrom_ioctl_eject(struct cdrom_device_info *cdi)
+{
+	cdinfo(CD_DO_IOCTL, "entering CDROMEJECT\n");
+
+	/*
+	 * cdrom_eject_check is done in cdrom_ioctl.
+	 */
 	if (CDROM_CAN(CDC_LOCK)) {
 		int ret = cdi->ops->lock_door(cdi, 0);
 		if (ret)
@@ -2392,22 +2400,31 @@ static int cdrom_ioctl_reset(struct cdro
 	return cdi->ops->reset(cdi);
 }
 
-static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
+static int cdrom_lock_door_check(struct cdrom_device_info *cdi,
 		unsigned long arg)
 {
-	cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl");
-
 	if (!CDROM_CAN(CDC_LOCK))
 		return -EDRIVE_CANT_DO_THIS;
-
-	keeplocked = arg ? 1 : 0;
-
 	/*
 	 * Don't unlock the door on multiple opens by default, but allow
 	 * root to do so.
 	 */
 	if (cdi->use_count != 1 && !arg && !capable(CAP_SYS_ADMIN))
 		return -EBUSY;
+
+	return 0;
+}
+
+
+static int cdrom_ioctl_lock_door(struct cdrom_device_info *cdi,
+		unsigned long arg)
+{
+	cdinfo(CD_DO_IOCTL, "%socking door.\n", arg ? "L" : "Unl");
+
+	/*
+	 * cdrom_lock_door_check is done in cdrom_ioctl.
+	 */
+	keeplocked = arg ? 1 : 0;
 	return cdi->ops->lock_door(cdi, arg);
 }
 
@@ -2701,6 +2718,18 @@ int cdrom_ioctl(struct file * file, stru
 	int ret;
 	struct gendisk *disk = ip->i_bdev->bd_disk;
 
+	if (cmd == CDROMEJECT) {
+		ret = cdrom_eject_check(cdi);
+		if (ret)
+			return ret;
+	}
+
+	if (cmd == CDROM_LOCKDOOR) {
+		ret = cdrom_lock_door_check(cdi, arg);
+		if (ret)
+			return ret;
+	}
+
 	/*
 	 * Try the generic SCSI command ioctl's first.
 	 */

\
 
 \ /
  Last update: 2008-01-04 07:39    [from the cache]
©2003-2008