diff options
-rw-r--r-- | block/scsi_ioctl.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index c2ac36dfe4f3..18de84c8ccd8 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c | |||
@@ -190,16 +190,21 @@ static int verify_command(struct file *file, unsigned char *cmd) | |||
190 | safe_for_write(GPCMD_SET_STREAMING), | 190 | safe_for_write(GPCMD_SET_STREAMING), |
191 | }; | 191 | }; |
192 | unsigned char type = cmd_type[cmd[0]]; | 192 | unsigned char type = cmd_type[cmd[0]]; |
193 | int has_write_perm = 0; | ||
193 | 194 | ||
194 | /* Anybody who can open the device can do a read-safe command */ | 195 | /* Anybody who can open the device can do a read-safe command */ |
195 | if (type & CMD_READ_SAFE) | 196 | if (type & CMD_READ_SAFE) |
196 | return 0; | 197 | return 0; |
197 | 198 | ||
199 | /* | ||
200 | * file can be NULL from ioctl_by_bdev()... | ||
201 | */ | ||
202 | if (file) | ||
203 | has_write_perm = file->f_mode & FMODE_WRITE; | ||
204 | |||
198 | /* Write-safe commands just require a writable open.. */ | 205 | /* Write-safe commands just require a writable open.. */ |
199 | if (type & CMD_WRITE_SAFE) { | 206 | if ((type & CMD_WRITE_SAFE) && has_write_perm) |
200 | if (file->f_mode & FMODE_WRITE) | 207 | return 0; |
201 | return 0; | ||
202 | } | ||
203 | 208 | ||
204 | /* And root can do any command.. */ | 209 | /* And root can do any command.. */ |
205 | if (capable(CAP_SYS_RAWIO)) | 210 | if (capable(CAP_SYS_RAWIO)) |