diff options
author | Steve French <sfrench@us.ibm.com> | 2008-08-27 22:47:00 -0400 |
---|---|---|
committer | Steve French <sfrench@us.ibm.com> | 2008-08-27 22:47:00 -0400 |
commit | 6405c9cd9bf7b1c35ed76ef8ee3e217056285702 (patch) | |
tree | 0659c9ae17d1375f185f88f4f7fef1a667f375d8 /block | |
parent | bcc55c6664a90146149ba0fd93052adc94287b9f (diff) | |
parent | 4c246edd2550304df5b766cc841584b2bb058843 (diff) |
Merge branch 'master' of /pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'block')
-rw-r--r-- | block/blk-core.c | 2 | ||||
-rw-r--r-- | block/blk-tag.c | 6 | ||||
-rw-r--r-- | block/bsg.c | 44 | ||||
-rw-r--r-- | block/cmd-filter.c | 196 | ||||
-rw-r--r-- | block/scsi_ioctl.c | 94 |
5 files changed, 154 insertions, 188 deletions
diff --git a/block/blk-core.c b/block/blk-core.c index 4889eb86a39e..2cba5ef97b2b 100644 --- a/block/blk-core.c +++ b/block/blk-core.c | |||
@@ -582,6 +582,8 @@ blk_init_queue_node(request_fn_proc *rfn, spinlock_t *lock, int node_id) | |||
582 | 582 | ||
583 | q->sg_reserved_size = INT_MAX; | 583 | q->sg_reserved_size = INT_MAX; |
584 | 584 | ||
585 | blk_set_cmd_filter_defaults(&q->cmd_filter); | ||
586 | |||
585 | /* | 587 | /* |
586 | * all done | 588 | * all done |
587 | */ | 589 | */ |
diff --git a/block/blk-tag.c b/block/blk-tag.c index 32667beb03ee..ed5166fbc599 100644 --- a/block/blk-tag.c +++ b/block/blk-tag.c | |||
@@ -38,7 +38,8 @@ static int __blk_free_tags(struct blk_queue_tag *bqt) | |||
38 | 38 | ||
39 | retval = atomic_dec_and_test(&bqt->refcnt); | 39 | retval = atomic_dec_and_test(&bqt->refcnt); |
40 | if (retval) { | 40 | if (retval) { |
41 | BUG_ON(bqt->busy); | 41 | BUG_ON(find_first_bit(bqt->tag_map, bqt->max_depth) < |
42 | bqt->max_depth); | ||
42 | 43 | ||
43 | kfree(bqt->tag_index); | 44 | kfree(bqt->tag_index); |
44 | bqt->tag_index = NULL; | 45 | bqt->tag_index = NULL; |
@@ -147,7 +148,6 @@ static struct blk_queue_tag *__blk_queue_init_tags(struct request_queue *q, | |||
147 | if (init_tag_map(q, tags, depth)) | 148 | if (init_tag_map(q, tags, depth)) |
148 | goto fail; | 149 | goto fail; |
149 | 150 | ||
150 | tags->busy = 0; | ||
151 | atomic_set(&tags->refcnt, 1); | 151 | atomic_set(&tags->refcnt, 1); |
152 | return tags; | 152 | return tags; |
153 | fail: | 153 | fail: |
@@ -313,7 +313,6 @@ void blk_queue_end_tag(struct request_queue *q, struct request *rq) | |||
313 | * unlock memory barrier semantics. | 313 | * unlock memory barrier semantics. |
314 | */ | 314 | */ |
315 | clear_bit_unlock(tag, bqt->tag_map); | 315 | clear_bit_unlock(tag, bqt->tag_map); |
316 | bqt->busy--; | ||
317 | } | 316 | } |
318 | EXPORT_SYMBOL(blk_queue_end_tag); | 317 | EXPORT_SYMBOL(blk_queue_end_tag); |
319 | 318 | ||
@@ -368,7 +367,6 @@ int blk_queue_start_tag(struct request_queue *q, struct request *rq) | |||
368 | bqt->tag_index[tag] = rq; | 367 | bqt->tag_index[tag] = rq; |
369 | blkdev_dequeue_request(rq); | 368 | blkdev_dequeue_request(rq); |
370 | list_add(&rq->queuelist, &q->tag_busy_list); | 369 | list_add(&rq->queuelist, &q->tag_busy_list); |
371 | bqt->busy++; | ||
372 | return 0; | 370 | return 0; |
373 | } | 371 | } |
374 | EXPORT_SYMBOL(blk_queue_start_tag); | 372 | EXPORT_SYMBOL(blk_queue_start_tag); |
diff --git a/block/bsg.c b/block/bsg.c index 5a68b09a69ba..0aae8d7ba99c 100644 --- a/block/bsg.c +++ b/block/bsg.c | |||
@@ -45,8 +45,6 @@ struct bsg_device { | |||
45 | char name[BUS_ID_SIZE]; | 45 | char name[BUS_ID_SIZE]; |
46 | int max_queue; | 46 | int max_queue; |
47 | unsigned long flags; | 47 | unsigned long flags; |
48 | struct blk_scsi_cmd_filter *cmd_filter; | ||
49 | mode_t *f_mode; | ||
50 | }; | 48 | }; |
51 | 49 | ||
52 | enum { | 50 | enum { |
@@ -174,7 +172,8 @@ unlock: | |||
174 | } | 172 | } |
175 | 173 | ||
176 | static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, | 174 | static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, |
177 | struct sg_io_v4 *hdr, struct bsg_device *bd) | 175 | struct sg_io_v4 *hdr, struct bsg_device *bd, |
176 | int has_write_perm) | ||
178 | { | 177 | { |
179 | if (hdr->request_len > BLK_MAX_CDB) { | 178 | if (hdr->request_len > BLK_MAX_CDB) { |
180 | rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL); | 179 | rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL); |
@@ -187,8 +186,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, | |||
187 | return -EFAULT; | 186 | return -EFAULT; |
188 | 187 | ||
189 | if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) { | 188 | if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) { |
190 | if (blk_cmd_filter_verify_command(bd->cmd_filter, rq->cmd, | 189 | if (blk_verify_command(&q->cmd_filter, rq->cmd, has_write_perm)) |
191 | bd->f_mode)) | ||
192 | return -EPERM; | 190 | return -EPERM; |
193 | } else if (!capable(CAP_SYS_RAWIO)) | 191 | } else if (!capable(CAP_SYS_RAWIO)) |
194 | return -EPERM; | 192 | return -EPERM; |
@@ -244,7 +242,7 @@ bsg_validate_sgv4_hdr(struct request_queue *q, struct sg_io_v4 *hdr, int *rw) | |||
244 | * map sg_io_v4 to a request. | 242 | * map sg_io_v4 to a request. |
245 | */ | 243 | */ |
246 | static struct request * | 244 | static struct request * |
247 | bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr) | 245 | bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm) |
248 | { | 246 | { |
249 | struct request_queue *q = bd->queue; | 247 | struct request_queue *q = bd->queue; |
250 | struct request *rq, *next_rq = NULL; | 248 | struct request *rq, *next_rq = NULL; |
@@ -266,7 +264,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr) | |||
266 | rq = blk_get_request(q, rw, GFP_KERNEL); | 264 | rq = blk_get_request(q, rw, GFP_KERNEL); |
267 | if (!rq) | 265 | if (!rq) |
268 | return ERR_PTR(-ENOMEM); | 266 | return ERR_PTR(-ENOMEM); |
269 | ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd); | 267 | ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm); |
270 | if (ret) | 268 | if (ret) |
271 | goto out; | 269 | goto out; |
272 | 270 | ||
@@ -568,25 +566,6 @@ static inline void bsg_set_block(struct bsg_device *bd, struct file *file) | |||
568 | set_bit(BSG_F_BLOCK, &bd->flags); | 566 | set_bit(BSG_F_BLOCK, &bd->flags); |
569 | } | 567 | } |
570 | 568 | ||
571 | static void bsg_set_cmd_filter(struct bsg_device *bd, | ||
572 | struct file *file) | ||
573 | { | ||
574 | struct inode *inode; | ||
575 | struct gendisk *disk; | ||
576 | |||
577 | if (!file) | ||
578 | return; | ||
579 | |||
580 | inode = file->f_dentry->d_inode; | ||
581 | if (!inode) | ||
582 | return; | ||
583 | |||
584 | disk = inode->i_bdev->bd_disk; | ||
585 | |||
586 | bd->cmd_filter = &disk->cmd_filter; | ||
587 | bd->f_mode = &file->f_mode; | ||
588 | } | ||
589 | |||
590 | /* | 569 | /* |
591 | * Check if the error is a "real" error that we should return. | 570 | * Check if the error is a "real" error that we should return. |
592 | */ | 571 | */ |
@@ -608,7 +587,6 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) | |||
608 | dprintk("%s: read %Zd bytes\n", bd->name, count); | 587 | dprintk("%s: read %Zd bytes\n", bd->name, count); |
609 | 588 | ||
610 | bsg_set_block(bd, file); | 589 | bsg_set_block(bd, file); |
611 | bsg_set_cmd_filter(bd, file); | ||
612 | 590 | ||
613 | bytes_read = 0; | 591 | bytes_read = 0; |
614 | ret = __bsg_read(buf, count, bd, NULL, &bytes_read); | 592 | ret = __bsg_read(buf, count, bd, NULL, &bytes_read); |
@@ -621,7 +599,7 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) | |||
621 | } | 599 | } |
622 | 600 | ||
623 | static int __bsg_write(struct bsg_device *bd, const char __user *buf, | 601 | static int __bsg_write(struct bsg_device *bd, const char __user *buf, |
624 | size_t count, ssize_t *bytes_written) | 602 | size_t count, ssize_t *bytes_written, int has_write_perm) |
625 | { | 603 | { |
626 | struct bsg_command *bc; | 604 | struct bsg_command *bc; |
627 | struct request *rq; | 605 | struct request *rq; |
@@ -652,7 +630,7 @@ static int __bsg_write(struct bsg_device *bd, const char __user *buf, | |||
652 | /* | 630 | /* |
653 | * get a request, fill in the blanks, and add to request queue | 631 | * get a request, fill in the blanks, and add to request queue |
654 | */ | 632 | */ |
655 | rq = bsg_map_hdr(bd, &bc->hdr); | 633 | rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm); |
656 | if (IS_ERR(rq)) { | 634 | if (IS_ERR(rq)) { |
657 | ret = PTR_ERR(rq); | 635 | ret = PTR_ERR(rq); |
658 | rq = NULL; | 636 | rq = NULL; |
@@ -683,10 +661,11 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | |||
683 | dprintk("%s: write %Zd bytes\n", bd->name, count); | 661 | dprintk("%s: write %Zd bytes\n", bd->name, count); |
684 | 662 | ||
685 | bsg_set_block(bd, file); | 663 | bsg_set_block(bd, file); |
686 | bsg_set_cmd_filter(bd, file); | ||
687 | 664 | ||
688 | bytes_written = 0; | 665 | bytes_written = 0; |
689 | ret = __bsg_write(bd, buf, count, &bytes_written); | 666 | ret = __bsg_write(bd, buf, count, &bytes_written, |
667 | file->f_mode & FMODE_WRITE); | ||
668 | |||
690 | *ppos = bytes_written; | 669 | *ppos = bytes_written; |
691 | 670 | ||
692 | /* | 671 | /* |
@@ -792,7 +771,6 @@ static struct bsg_device *bsg_add_device(struct inode *inode, | |||
792 | bd->queue = rq; | 771 | bd->queue = rq; |
793 | 772 | ||
794 | bsg_set_block(bd, file); | 773 | bsg_set_block(bd, file); |
795 | bsg_set_cmd_filter(bd, file); | ||
796 | 774 | ||
797 | atomic_set(&bd->ref_count, 1); | 775 | atomic_set(&bd->ref_count, 1); |
798 | mutex_lock(&bsg_mutex); | 776 | mutex_lock(&bsg_mutex); |
@@ -943,7 +921,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
943 | if (copy_from_user(&hdr, uarg, sizeof(hdr))) | 921 | if (copy_from_user(&hdr, uarg, sizeof(hdr))) |
944 | return -EFAULT; | 922 | return -EFAULT; |
945 | 923 | ||
946 | rq = bsg_map_hdr(bd, &hdr); | 924 | rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE); |
947 | if (IS_ERR(rq)) | 925 | if (IS_ERR(rq)) |
948 | return PTR_ERR(rq); | 926 | return PTR_ERR(rq); |
949 | 927 | ||
diff --git a/block/cmd-filter.c b/block/cmd-filter.c index eec4404fd357..1d4026206ac2 100644 --- a/block/cmd-filter.c +++ b/block/cmd-filter.c | |||
@@ -20,15 +20,14 @@ | |||
20 | #include <linux/list.h> | 20 | #include <linux/list.h> |
21 | #include <linux/genhd.h> | 21 | #include <linux/genhd.h> |
22 | #include <linux/spinlock.h> | 22 | #include <linux/spinlock.h> |
23 | #include <linux/parser.h> | ||
24 | #include <linux/capability.h> | 23 | #include <linux/capability.h> |
25 | #include <linux/bitops.h> | 24 | #include <linux/bitops.h> |
26 | 25 | ||
27 | #include <scsi/scsi.h> | 26 | #include <scsi/scsi.h> |
28 | #include <linux/cdrom.h> | 27 | #include <linux/cdrom.h> |
29 | 28 | ||
30 | int blk_cmd_filter_verify_command(struct blk_scsi_cmd_filter *filter, | 29 | int blk_verify_command(struct blk_cmd_filter *filter, |
31 | unsigned char *cmd, mode_t *f_mode) | 30 | unsigned char *cmd, int has_write_perm) |
32 | { | 31 | { |
33 | /* root can do any command. */ | 32 | /* root can do any command. */ |
34 | if (capable(CAP_SYS_RAWIO)) | 33 | if (capable(CAP_SYS_RAWIO)) |
@@ -43,34 +42,15 @@ int blk_cmd_filter_verify_command(struct blk_scsi_cmd_filter *filter, | |||
43 | return 0; | 42 | return 0; |
44 | 43 | ||
45 | /* Write-safe commands require a writable open */ | 44 | /* Write-safe commands require a writable open */ |
46 | if (test_bit(cmd[0], filter->write_ok) && (*f_mode & FMODE_WRITE)) | 45 | if (test_bit(cmd[0], filter->write_ok) && has_write_perm) |
47 | return 0; | 46 | return 0; |
48 | 47 | ||
49 | return -EPERM; | 48 | return -EPERM; |
50 | } | 49 | } |
51 | EXPORT_SYMBOL(blk_cmd_filter_verify_command); | ||
52 | |||
53 | int blk_verify_command(struct file *file, unsigned char *cmd) | ||
54 | { | ||
55 | struct gendisk *disk; | ||
56 | struct inode *inode; | ||
57 | |||
58 | if (!file) | ||
59 | return -EINVAL; | ||
60 | |||
61 | inode = file->f_dentry->d_inode; | ||
62 | if (!inode) | ||
63 | return -EINVAL; | ||
64 | |||
65 | disk = inode->i_bdev->bd_disk; | ||
66 | |||
67 | return blk_cmd_filter_verify_command(&disk->cmd_filter, | ||
68 | cmd, &file->f_mode); | ||
69 | } | ||
70 | EXPORT_SYMBOL(blk_verify_command); | 50 | EXPORT_SYMBOL(blk_verify_command); |
71 | 51 | ||
72 | /* and now, the sysfs stuff */ | 52 | /* and now, the sysfs stuff */ |
73 | static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, | 53 | static ssize_t rcf_cmds_show(struct blk_cmd_filter *filter, char *page, |
74 | int rw) | 54 | int rw) |
75 | { | 55 | { |
76 | char *npage = page; | 56 | char *npage = page; |
@@ -84,8 +64,7 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, | |||
84 | 64 | ||
85 | for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) { | 65 | for (i = 0; i < BLK_SCSI_MAX_CMDS; i++) { |
86 | if (test_bit(i, okbits)) { | 66 | if (test_bit(i, okbits)) { |
87 | sprintf(npage, "%02x", i); | 67 | npage += sprintf(npage, "0x%02x", i); |
88 | npage += 2; | ||
89 | if (i < BLK_SCSI_MAX_CMDS - 1) | 68 | if (i < BLK_SCSI_MAX_CMDS - 1) |
90 | sprintf(npage++, " "); | 69 | sprintf(npage++, " "); |
91 | } | 70 | } |
@@ -97,57 +76,65 @@ static ssize_t rcf_cmds_show(struct blk_scsi_cmd_filter *filter, char *page, | |||
97 | return npage - page; | 76 | return npage - page; |
98 | } | 77 | } |
99 | 78 | ||
100 | static ssize_t rcf_readcmds_show(struct blk_scsi_cmd_filter *filter, char *page) | 79 | static ssize_t rcf_readcmds_show(struct blk_cmd_filter *filter, char *page) |
101 | { | 80 | { |
102 | return rcf_cmds_show(filter, page, READ); | 81 | return rcf_cmds_show(filter, page, READ); |
103 | } | 82 | } |
104 | 83 | ||
105 | static ssize_t rcf_writecmds_show(struct blk_scsi_cmd_filter *filter, | 84 | static ssize_t rcf_writecmds_show(struct blk_cmd_filter *filter, |
106 | char *page) | 85 | char *page) |
107 | { | 86 | { |
108 | return rcf_cmds_show(filter, page, WRITE); | 87 | return rcf_cmds_show(filter, page, WRITE); |
109 | } | 88 | } |
110 | 89 | ||
111 | static ssize_t rcf_cmds_store(struct blk_scsi_cmd_filter *filter, | 90 | static ssize_t rcf_cmds_store(struct blk_cmd_filter *filter, |
112 | const char *page, size_t count, int rw) | 91 | const char *page, size_t count, int rw) |
113 | { | 92 | { |
114 | ssize_t ret = 0; | ||
115 | unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; | 93 | unsigned long okbits[BLK_SCSI_CMD_PER_LONG], *target_okbits; |
116 | int cmd, status, len; | 94 | int cmd, set; |
117 | substring_t ss; | 95 | char *p, *status; |
118 | 96 | ||
119 | memset(&okbits, 0, sizeof(okbits)); | 97 | if (rw == READ) { |
120 | 98 | memcpy(&okbits, filter->read_ok, sizeof(okbits)); | |
121 | for (len = strlen(page); len > 0; len -= 3) { | 99 | target_okbits = filter->read_ok; |
122 | if (len < 2) | 100 | } else { |
123 | break; | 101 | memcpy(&okbits, filter->write_ok, sizeof(okbits)); |
124 | ss.from = (char *) page + ret; | 102 | target_okbits = filter->write_ok; |
125 | ss.to = (char *) page + ret + 2; | 103 | } |
126 | ret += 3; | 104 | |
127 | status = match_hex(&ss, &cmd); | 105 | while ((p = strsep((char **)&page, " ")) != NULL) { |
106 | set = 1; | ||
107 | |||
108 | if (p[0] == '+') { | ||
109 | p++; | ||
110 | } else if (p[0] == '-') { | ||
111 | set = 0; | ||
112 | p++; | ||
113 | } | ||
114 | |||
115 | cmd = simple_strtol(p, &status, 16); | ||
116 | |||
128 | /* either of these cases means invalid input, so do nothing. */ | 117 | /* either of these cases means invalid input, so do nothing. */ |
129 | if (status || cmd >= BLK_SCSI_MAX_CMDS) | 118 | if ((status == p) || cmd >= BLK_SCSI_MAX_CMDS) |
130 | return -EINVAL; | 119 | return -EINVAL; |
131 | 120 | ||
132 | __set_bit(cmd, okbits); | 121 | if (set) |
122 | __set_bit(cmd, okbits); | ||
123 | else | ||
124 | __clear_bit(cmd, okbits); | ||
133 | } | 125 | } |
134 | 126 | ||
135 | if (rw == READ) | 127 | memcpy(target_okbits, okbits, sizeof(okbits)); |
136 | target_okbits = filter->read_ok; | ||
137 | else | ||
138 | target_okbits = filter->write_ok; | ||
139 | |||
140 | memmove(target_okbits, okbits, sizeof(okbits)); | ||
141 | return count; | 128 | return count; |
142 | } | 129 | } |
143 | 130 | ||
144 | static ssize_t rcf_readcmds_store(struct blk_scsi_cmd_filter *filter, | 131 | static ssize_t rcf_readcmds_store(struct blk_cmd_filter *filter, |
145 | const char *page, size_t count) | 132 | const char *page, size_t count) |
146 | { | 133 | { |
147 | return rcf_cmds_store(filter, page, count, READ); | 134 | return rcf_cmds_store(filter, page, count, READ); |
148 | } | 135 | } |
149 | 136 | ||
150 | static ssize_t rcf_writecmds_store(struct blk_scsi_cmd_filter *filter, | 137 | static ssize_t rcf_writecmds_store(struct blk_cmd_filter *filter, |
151 | const char *page, size_t count) | 138 | const char *page, size_t count) |
152 | { | 139 | { |
153 | return rcf_cmds_store(filter, page, count, WRITE); | 140 | return rcf_cmds_store(filter, page, count, WRITE); |
@@ -155,8 +142,8 @@ static ssize_t rcf_writecmds_store(struct blk_scsi_cmd_filter *filter, | |||
155 | 142 | ||
156 | struct rcf_sysfs_entry { | 143 | struct rcf_sysfs_entry { |
157 | struct attribute attr; | 144 | struct attribute attr; |
158 | ssize_t (*show)(struct blk_scsi_cmd_filter *, char *); | 145 | ssize_t (*show)(struct blk_cmd_filter *, char *); |
159 | ssize_t (*store)(struct blk_scsi_cmd_filter *, const char *, size_t); | 146 | ssize_t (*store)(struct blk_cmd_filter *, const char *, size_t); |
160 | }; | 147 | }; |
161 | 148 | ||
162 | static struct rcf_sysfs_entry rcf_readcmds_entry = { | 149 | static struct rcf_sysfs_entry rcf_readcmds_entry = { |
@@ -183,9 +170,9 @@ static ssize_t | |||
183 | rcf_attr_show(struct kobject *kobj, struct attribute *attr, char *page) | 170 | rcf_attr_show(struct kobject *kobj, struct attribute *attr, char *page) |
184 | { | 171 | { |
185 | struct rcf_sysfs_entry *entry = to_rcf(attr); | 172 | struct rcf_sysfs_entry *entry = to_rcf(attr); |
186 | struct blk_scsi_cmd_filter *filter; | 173 | struct blk_cmd_filter *filter; |
187 | 174 | ||
188 | filter = container_of(kobj, struct blk_scsi_cmd_filter, kobj); | 175 | filter = container_of(kobj, struct blk_cmd_filter, kobj); |
189 | if (entry->show) | 176 | if (entry->show) |
190 | return entry->show(filter, page); | 177 | return entry->show(filter, page); |
191 | 178 | ||
@@ -197,7 +184,7 @@ rcf_attr_store(struct kobject *kobj, struct attribute *attr, | |||
197 | const char *page, size_t length) | 184 | const char *page, size_t length) |
198 | { | 185 | { |
199 | struct rcf_sysfs_entry *entry = to_rcf(attr); | 186 | struct rcf_sysfs_entry *entry = to_rcf(attr); |
200 | struct blk_scsi_cmd_filter *filter; | 187 | struct blk_cmd_filter *filter; |
201 | 188 | ||
202 | if (!capable(CAP_SYS_RAWIO)) | 189 | if (!capable(CAP_SYS_RAWIO)) |
203 | return -EPERM; | 190 | return -EPERM; |
@@ -205,7 +192,7 @@ rcf_attr_store(struct kobject *kobj, struct attribute *attr, | |||
205 | if (!entry->store) | 192 | if (!entry->store) |
206 | return -EINVAL; | 193 | return -EINVAL; |
207 | 194 | ||
208 | filter = container_of(kobj, struct blk_scsi_cmd_filter, kobj); | 195 | filter = container_of(kobj, struct blk_cmd_filter, kobj); |
209 | return entry->store(filter, page, length); | 196 | return entry->store(filter, page, length); |
210 | } | 197 | } |
211 | 198 | ||
@@ -219,114 +206,27 @@ static struct kobj_type rcf_ktype = { | |||
219 | .default_attrs = default_attrs, | 206 | .default_attrs = default_attrs, |
220 | }; | 207 | }; |
221 | 208 | ||
222 | #ifndef MAINTENANCE_IN_CMD | ||
223 | #define MAINTENANCE_IN_CMD 0xa3 | ||
224 | #endif | ||
225 | |||
226 | static void rcf_set_defaults(struct blk_scsi_cmd_filter *filter) | ||
227 | { | ||
228 | /* Basic read-only commands */ | ||
229 | __set_bit(TEST_UNIT_READY, filter->read_ok); | ||
230 | __set_bit(REQUEST_SENSE, filter->read_ok); | ||
231 | __set_bit(READ_6, filter->read_ok); | ||
232 | __set_bit(READ_10, filter->read_ok); | ||
233 | __set_bit(READ_12, filter->read_ok); | ||
234 | __set_bit(READ_16, filter->read_ok); | ||
235 | __set_bit(READ_BUFFER, filter->read_ok); | ||
236 | __set_bit(READ_DEFECT_DATA, filter->read_ok); | ||
237 | __set_bit(READ_CAPACITY, filter->read_ok); | ||
238 | __set_bit(READ_LONG, filter->read_ok); | ||
239 | __set_bit(INQUIRY, filter->read_ok); | ||
240 | __set_bit(MODE_SENSE, filter->read_ok); | ||
241 | __set_bit(MODE_SENSE_10, filter->read_ok); | ||
242 | __set_bit(LOG_SENSE, filter->read_ok); | ||
243 | __set_bit(START_STOP, filter->read_ok); | ||
244 | __set_bit(GPCMD_VERIFY_10, filter->read_ok); | ||
245 | __set_bit(VERIFY_16, filter->read_ok); | ||
246 | __set_bit(REPORT_LUNS, filter->read_ok); | ||
247 | __set_bit(SERVICE_ACTION_IN, filter->read_ok); | ||
248 | __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok); | ||
249 | __set_bit(MAINTENANCE_IN_CMD, filter->read_ok); | ||
250 | __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok); | ||
251 | |||
252 | /* Audio CD commands */ | ||
253 | __set_bit(GPCMD_PLAY_CD, filter->read_ok); | ||
254 | __set_bit(GPCMD_PLAY_AUDIO_10, filter->read_ok); | ||
255 | __set_bit(GPCMD_PLAY_AUDIO_MSF, filter->read_ok); | ||
256 | __set_bit(GPCMD_PLAY_AUDIO_TI, filter->read_ok); | ||
257 | __set_bit(GPCMD_PAUSE_RESUME, filter->read_ok); | ||
258 | |||
259 | /* CD/DVD data reading */ | ||
260 | __set_bit(GPCMD_READ_CD, filter->read_ok); | ||
261 | __set_bit(GPCMD_READ_CD_MSF, filter->read_ok); | ||
262 | __set_bit(GPCMD_READ_DISC_INFO, filter->read_ok); | ||
263 | __set_bit(GPCMD_READ_CDVD_CAPACITY, filter->read_ok); | ||
264 | __set_bit(GPCMD_READ_DVD_STRUCTURE, filter->read_ok); | ||
265 | __set_bit(GPCMD_READ_HEADER, filter->read_ok); | ||
266 | __set_bit(GPCMD_READ_TRACK_RZONE_INFO, filter->read_ok); | ||
267 | __set_bit(GPCMD_READ_SUBCHANNEL, filter->read_ok); | ||
268 | __set_bit(GPCMD_READ_TOC_PMA_ATIP, filter->read_ok); | ||
269 | __set_bit(GPCMD_REPORT_KEY, filter->read_ok); | ||
270 | __set_bit(GPCMD_SCAN, filter->read_ok); | ||
271 | __set_bit(GPCMD_GET_CONFIGURATION, filter->read_ok); | ||
272 | __set_bit(GPCMD_READ_FORMAT_CAPACITIES, filter->read_ok); | ||
273 | __set_bit(GPCMD_GET_EVENT_STATUS_NOTIFICATION, filter->read_ok); | ||
274 | __set_bit(GPCMD_GET_PERFORMANCE, filter->read_ok); | ||
275 | __set_bit(GPCMD_SEEK, filter->read_ok); | ||
276 | __set_bit(GPCMD_STOP_PLAY_SCAN, filter->read_ok); | ||
277 | |||
278 | /* Basic writing commands */ | ||
279 | __set_bit(WRITE_6, filter->write_ok); | ||
280 | __set_bit(WRITE_10, filter->write_ok); | ||
281 | __set_bit(WRITE_VERIFY, filter->write_ok); | ||
282 | __set_bit(WRITE_12, filter->write_ok); | ||
283 | __set_bit(WRITE_VERIFY_12, filter->write_ok); | ||
284 | __set_bit(WRITE_16, filter->write_ok); | ||
285 | __set_bit(WRITE_LONG, filter->write_ok); | ||
286 | __set_bit(WRITE_LONG_2, filter->write_ok); | ||
287 | __set_bit(ERASE, filter->write_ok); | ||
288 | __set_bit(GPCMD_MODE_SELECT_10, filter->write_ok); | ||
289 | __set_bit(MODE_SELECT, filter->write_ok); | ||
290 | __set_bit(LOG_SELECT, filter->write_ok); | ||
291 | __set_bit(GPCMD_BLANK, filter->write_ok); | ||
292 | __set_bit(GPCMD_CLOSE_TRACK, filter->write_ok); | ||
293 | __set_bit(GPCMD_FLUSH_CACHE, filter->write_ok); | ||
294 | __set_bit(GPCMD_FORMAT_UNIT, filter->write_ok); | ||
295 | __set_bit(GPCMD_REPAIR_RZONE_TRACK, filter->write_ok); | ||
296 | __set_bit(GPCMD_RESERVE_RZONE_TRACK, filter->write_ok); | ||
297 | __set_bit(GPCMD_SEND_DVD_STRUCTURE, filter->write_ok); | ||
298 | __set_bit(GPCMD_SEND_EVENT, filter->write_ok); | ||
299 | __set_bit(GPCMD_SEND_KEY, filter->write_ok); | ||
300 | __set_bit(GPCMD_SEND_OPC, filter->write_ok); | ||
301 | __set_bit(GPCMD_SEND_CUE_SHEET, filter->write_ok); | ||
302 | __set_bit(GPCMD_SET_SPEED, filter->write_ok); | ||
303 | __set_bit(GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, filter->write_ok); | ||
304 | __set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok); | ||
305 | __set_bit(GPCMD_SET_STREAMING, filter->write_ok); | ||
306 | } | ||
307 | |||
308 | int blk_register_filter(struct gendisk *disk) | 209 | int blk_register_filter(struct gendisk *disk) |
309 | { | 210 | { |
310 | int ret; | 211 | int ret; |
311 | struct blk_scsi_cmd_filter *filter = &disk->cmd_filter; | 212 | struct blk_cmd_filter *filter = &disk->queue->cmd_filter; |
312 | struct kobject *parent = kobject_get(disk->holder_dir->parent); | 213 | struct kobject *parent = kobject_get(disk->holder_dir->parent); |
313 | 214 | ||
314 | if (!parent) | 215 | if (!parent) |
315 | return -ENODEV; | 216 | return -ENODEV; |
316 | 217 | ||
317 | ret = kobject_init_and_add(&filter->kobj, &rcf_ktype, parent, | 218 | ret = kobject_init_and_add(&filter->kobj, &rcf_ktype, parent, |
318 | "%s", "cmd_filter"); | 219 | "%s", "cmd_filter"); |
319 | 220 | ||
320 | if (ret < 0) | 221 | if (ret < 0) |
321 | return ret; | 222 | return ret; |
322 | 223 | ||
323 | rcf_set_defaults(filter); | ||
324 | return 0; | 224 | return 0; |
325 | } | 225 | } |
326 | 226 | ||
327 | void blk_unregister_filter(struct gendisk *disk) | 227 | void blk_unregister_filter(struct gendisk *disk) |
328 | { | 228 | { |
329 | struct blk_scsi_cmd_filter *filter = &disk->cmd_filter; | 229 | struct blk_cmd_filter *filter = &disk->queue->cmd_filter; |
330 | 230 | ||
331 | kobject_put(&filter->kobj); | 231 | kobject_put(&filter->kobj); |
332 | kobject_put(disk->holder_dir->parent); | 232 | kobject_put(disk->holder_dir->parent); |
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 12a5182173f6..ec4b7f234626 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c | |||
@@ -105,12 +105,96 @@ static int sg_emulated_host(struct request_queue *q, int __user *p) | |||
105 | return put_user(1, p); | 105 | return put_user(1, p); |
106 | } | 106 | } |
107 | 107 | ||
108 | void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter) | ||
109 | { | ||
110 | /* Basic read-only commands */ | ||
111 | __set_bit(TEST_UNIT_READY, filter->read_ok); | ||
112 | __set_bit(REQUEST_SENSE, filter->read_ok); | ||
113 | __set_bit(READ_6, filter->read_ok); | ||
114 | __set_bit(READ_10, filter->read_ok); | ||
115 | __set_bit(READ_12, filter->read_ok); | ||
116 | __set_bit(READ_16, filter->read_ok); | ||
117 | __set_bit(READ_BUFFER, filter->read_ok); | ||
118 | __set_bit(READ_DEFECT_DATA, filter->read_ok); | ||
119 | __set_bit(READ_CAPACITY, filter->read_ok); | ||
120 | __set_bit(READ_LONG, filter->read_ok); | ||
121 | __set_bit(INQUIRY, filter->read_ok); | ||
122 | __set_bit(MODE_SENSE, filter->read_ok); | ||
123 | __set_bit(MODE_SENSE_10, filter->read_ok); | ||
124 | __set_bit(LOG_SENSE, filter->read_ok); | ||
125 | __set_bit(START_STOP, filter->read_ok); | ||
126 | __set_bit(GPCMD_VERIFY_10, filter->read_ok); | ||
127 | __set_bit(VERIFY_16, filter->read_ok); | ||
128 | __set_bit(REPORT_LUNS, filter->read_ok); | ||
129 | __set_bit(SERVICE_ACTION_IN, filter->read_ok); | ||
130 | __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok); | ||
131 | __set_bit(MAINTENANCE_IN, filter->read_ok); | ||
132 | __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok); | ||
133 | |||
134 | /* Audio CD commands */ | ||
135 | __set_bit(GPCMD_PLAY_CD, filter->read_ok); | ||
136 | __set_bit(GPCMD_PLAY_AUDIO_10, filter->read_ok); | ||
137 | __set_bit(GPCMD_PLAY_AUDIO_MSF, filter->read_ok); | ||
138 | __set_bit(GPCMD_PLAY_AUDIO_TI, filter->read_ok); | ||
139 | __set_bit(GPCMD_PAUSE_RESUME, filter->read_ok); | ||
140 | |||
141 | /* CD/DVD data reading */ | ||
142 | __set_bit(GPCMD_READ_CD, filter->read_ok); | ||
143 | __set_bit(GPCMD_READ_CD_MSF, filter->read_ok); | ||
144 | __set_bit(GPCMD_READ_DISC_INFO, filter->read_ok); | ||
145 | __set_bit(GPCMD_READ_CDVD_CAPACITY, filter->read_ok); | ||
146 | __set_bit(GPCMD_READ_DVD_STRUCTURE, filter->read_ok); | ||
147 | __set_bit(GPCMD_READ_HEADER, filter->read_ok); | ||
148 | __set_bit(GPCMD_READ_TRACK_RZONE_INFO, filter->read_ok); | ||
149 | __set_bit(GPCMD_READ_SUBCHANNEL, filter->read_ok); | ||
150 | __set_bit(GPCMD_READ_TOC_PMA_ATIP, filter->read_ok); | ||
151 | __set_bit(GPCMD_REPORT_KEY, filter->read_ok); | ||
152 | __set_bit(GPCMD_SCAN, filter->read_ok); | ||
153 | __set_bit(GPCMD_GET_CONFIGURATION, filter->read_ok); | ||
154 | __set_bit(GPCMD_READ_FORMAT_CAPACITIES, filter->read_ok); | ||
155 | __set_bit(GPCMD_GET_EVENT_STATUS_NOTIFICATION, filter->read_ok); | ||
156 | __set_bit(GPCMD_GET_PERFORMANCE, filter->read_ok); | ||
157 | __set_bit(GPCMD_SEEK, filter->read_ok); | ||
158 | __set_bit(GPCMD_STOP_PLAY_SCAN, filter->read_ok); | ||
159 | |||
160 | /* Basic writing commands */ | ||
161 | __set_bit(WRITE_6, filter->write_ok); | ||
162 | __set_bit(WRITE_10, filter->write_ok); | ||
163 | __set_bit(WRITE_VERIFY, filter->write_ok); | ||
164 | __set_bit(WRITE_12, filter->write_ok); | ||
165 | __set_bit(WRITE_VERIFY_12, filter->write_ok); | ||
166 | __set_bit(WRITE_16, filter->write_ok); | ||
167 | __set_bit(WRITE_LONG, filter->write_ok); | ||
168 | __set_bit(WRITE_LONG_2, filter->write_ok); | ||
169 | __set_bit(ERASE, filter->write_ok); | ||
170 | __set_bit(GPCMD_MODE_SELECT_10, filter->write_ok); | ||
171 | __set_bit(MODE_SELECT, filter->write_ok); | ||
172 | __set_bit(LOG_SELECT, filter->write_ok); | ||
173 | __set_bit(GPCMD_BLANK, filter->write_ok); | ||
174 | __set_bit(GPCMD_CLOSE_TRACK, filter->write_ok); | ||
175 | __set_bit(GPCMD_FLUSH_CACHE, filter->write_ok); | ||
176 | __set_bit(GPCMD_FORMAT_UNIT, filter->write_ok); | ||
177 | __set_bit(GPCMD_REPAIR_RZONE_TRACK, filter->write_ok); | ||
178 | __set_bit(GPCMD_RESERVE_RZONE_TRACK, filter->write_ok); | ||
179 | __set_bit(GPCMD_SEND_DVD_STRUCTURE, filter->write_ok); | ||
180 | __set_bit(GPCMD_SEND_EVENT, filter->write_ok); | ||
181 | __set_bit(GPCMD_SEND_KEY, filter->write_ok); | ||
182 | __set_bit(GPCMD_SEND_OPC, filter->write_ok); | ||
183 | __set_bit(GPCMD_SEND_CUE_SHEET, filter->write_ok); | ||
184 | __set_bit(GPCMD_SET_SPEED, filter->write_ok); | ||
185 | __set_bit(GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL, filter->write_ok); | ||
186 | __set_bit(GPCMD_LOAD_UNLOAD, filter->write_ok); | ||
187 | __set_bit(GPCMD_SET_STREAMING, filter->write_ok); | ||
188 | } | ||
189 | EXPORT_SYMBOL_GPL(blk_set_cmd_filter_defaults); | ||
190 | |||
108 | static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, | 191 | static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, |
109 | struct sg_io_hdr *hdr, struct file *file) | 192 | struct sg_io_hdr *hdr, struct file *file) |
110 | { | 193 | { |
111 | if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len)) | 194 | if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len)) |
112 | return -EFAULT; | 195 | return -EFAULT; |
113 | if (blk_verify_command(file, rq->cmd)) | 196 | if (blk_verify_command(&q->cmd_filter, rq->cmd, |
197 | file->f_mode & FMODE_WRITE)) | ||
114 | return -EPERM; | 198 | return -EPERM; |
115 | 199 | ||
116 | /* | 200 | /* |
@@ -298,7 +382,7 @@ int sg_scsi_ioctl(struct file *file, struct request_queue *q, | |||
298 | struct gendisk *disk, struct scsi_ioctl_command __user *sic) | 382 | struct gendisk *disk, struct scsi_ioctl_command __user *sic) |
299 | { | 383 | { |
300 | struct request *rq; | 384 | struct request *rq; |
301 | int err; | 385 | int err, write_perm = 0; |
302 | unsigned int in_len, out_len, bytes, opcode, cmdlen; | 386 | unsigned int in_len, out_len, bytes, opcode, cmdlen; |
303 | char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE]; | 387 | char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE]; |
304 | 388 | ||
@@ -340,7 +424,11 @@ int sg_scsi_ioctl(struct file *file, struct request_queue *q, | |||
340 | if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len)) | 424 | if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len)) |
341 | goto error; | 425 | goto error; |
342 | 426 | ||
343 | err = blk_verify_command(file, rq->cmd); | 427 | /* scsi_ioctl passes NULL */ |
428 | if (file && (file->f_mode & FMODE_WRITE)) | ||
429 | write_perm = 1; | ||
430 | |||
431 | err = blk_verify_command(&q->cmd_filter, rq->cmd, write_perm); | ||
344 | if (err) | 432 | if (err) |
345 | goto error; | 433 | goto error; |
346 | 434 | ||