X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=block%2Fscsi_ioctl.c;h=cc72210687eb4f3a75e17ce39a46bfd2b4e70fa9;hb=05818a004a84951fd383694f3b35d89eb49fa308;hp=1d8852f7bbff077d14209b850b6d64e35186f81c;hpb=0a75c23a009ff65f651532cecc16675d05f4de37;p=powerpc.git diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 1d8852f7bb..cc72210687 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ EXPORT_SYMBOL(scsi_command_size); static int sg_get_version(int __user *p) { - static int sg_version_num = 30527; + static const int sg_version_num = 30527; return put_user(sg_version_num, p); } @@ -190,16 +191,21 @@ static int verify_command(struct file *file, unsigned char *cmd) safe_for_write(GPCMD_SET_STREAMING), }; unsigned char type = cmd_type[cmd[0]]; + int has_write_perm = 0; /* Anybody who can open the device can do a read-safe command */ if (type & CMD_READ_SAFE) return 0; + /* + * file can be NULL from ioctl_by_bdev()... + */ + if (file) + has_write_perm = file->f_mode & FMODE_WRITE; + /* Write-safe commands just require a writable open.. */ - if (type & CMD_WRITE_SAFE) { - if (file->f_mode & FMODE_WRITE) - return 0; - } + if ((type & CMD_WRITE_SAFE) && has_write_perm) + return 0; /* And root can do any command.. */ if (capable(CAP_SYS_RAWIO))