Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: replace the fmode_t argument to scsi_cmd_allowed with a simple bool

Instead of passing a fmode_t and only checking it for FMODE_WRITE, pass
a bool open_for_write to prepare for callers that won't have the fmode_t.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-19-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
5f4eb9d5 81b1fb7d

+7 -7
+1 -1
drivers/scsi/scsi_bsg.c
··· 42 42 if (copy_from_user(scmd->cmnd, uptr64(hdr->request), scmd->cmd_len)) 43 43 goto out_put_request; 44 44 ret = -EPERM; 45 - if (!scsi_cmd_allowed(scmd->cmnd, mode)) 45 + if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE)) 46 46 goto out_put_request; 47 47 48 48 ret = 0;
+4 -4
drivers/scsi/scsi_ioctl.c
··· 248 248 * Only a subset of commands are allowed for unprivileged users. Commands used 249 249 * to format the media, update the firmware, etc. are not permitted. 250 250 */ 251 - bool scsi_cmd_allowed(unsigned char *cmd, fmode_t mode) 251 + bool scsi_cmd_allowed(unsigned char *cmd, bool open_for_write) 252 252 { 253 253 /* root can do any command. */ 254 254 if (capable(CAP_SYS_RAWIO)) ··· 338 338 case GPCMD_SET_READ_AHEAD: 339 339 /* ZBC */ 340 340 case ZBC_OUT: 341 - return (mode & FMODE_WRITE); 341 + return open_for_write; 342 342 default: 343 343 return false; 344 344 } ··· 354 354 return -EMSGSIZE; 355 355 if (copy_from_user(scmd->cmnd, hdr->cmdp, hdr->cmd_len)) 356 356 return -EFAULT; 357 - if (!scsi_cmd_allowed(scmd->cmnd, mode)) 357 + if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE)) 358 358 return -EPERM; 359 359 scmd->cmd_len = hdr->cmd_len; 360 360 ··· 554 554 goto error; 555 555 556 556 err = -EPERM; 557 - if (!scsi_cmd_allowed(scmd->cmnd, mode)) 557 + if (!scsi_cmd_allowed(scmd->cmnd, mode & FMODE_WRITE)) 558 558 goto error; 559 559 560 560 /* default. possible overridden later */
+1 -1
drivers/scsi/sg.c
··· 237 237 238 238 if (sfp->parentdp->device->type == TYPE_SCANNER) 239 239 return 0; 240 - if (!scsi_cmd_allowed(cmd, filp->f_mode)) 240 + if (!scsi_cmd_allowed(cmd, filp->f_mode & FMODE_WRITE)) 241 241 return -EPERM; 242 242 return 0; 243 243 }
+1 -1
include/scsi/scsi_ioctl.h
··· 49 49 void __user *arg); 50 50 int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp); 51 51 int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp); 52 - bool scsi_cmd_allowed(unsigned char *cmd, fmode_t mode); 52 + bool scsi_cmd_allowed(unsigned char *cmd, bool open_for_write); 53 53 54 54 #endif /* __KERNEL__ */ 55 55 #endif /* _SCSI_IOCTL_H */