aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <James.Bottomley@HansenPartnership.com>2015-12-08 12:00:31 -0500
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2015-12-10 11:14:03 -0500
commit3417c1b5cb1fdc10261dbed42b05cc93166a78fd (patch)
tree76eb39bd1254171daf12a0e813a80b96a9ab961c
parent527e9316f8ec44bd53d90fb9f611fa7ffff52bb9 (diff)
ses: Fix problems with simple enclosures
Simple enclosure implementations (mostly USB) are allowed to return only page 8 to every diagnostic query. That really confuses our implementation because we assume the return is the page we asked for and end up doing incorrect offsets based on bogus information leading to accesses outside of allocated ranges. Fix that by checking the page code of the return and giving an error if it isn't the one we asked for. This should fix reported bugs with USB storage by simply refusing to attach to enclosures that behave like this. It's also good defensive practise now that we're starting to see more USB enclosures. Reported-by: Andrea Gelmini <andrea.gelmini@gelma.net> Cc: stable@vger.kernel.org Reviewed-by: Ewan D. Milne <emilne@redhat.com> Reviewed-by: Tomas Henzl <thenzl@redhat.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
-rw-r--r--drivers/scsi/ses.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index dcb0d76d7312..7d9cec50b77d 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -84,6 +84,7 @@ static void init_device_slot_control(unsigned char *dest_desc,
84static int ses_recv_diag(struct scsi_device *sdev, int page_code, 84static int ses_recv_diag(struct scsi_device *sdev, int page_code,
85 void *buf, int bufflen) 85 void *buf, int bufflen)
86{ 86{
87 int ret;
87 unsigned char cmd[] = { 88 unsigned char cmd[] = {
88 RECEIVE_DIAGNOSTIC, 89 RECEIVE_DIAGNOSTIC,
89 1, /* Set PCV bit */ 90 1, /* Set PCV bit */
@@ -92,9 +93,26 @@ static int ses_recv_diag(struct scsi_device *sdev, int page_code,
92 bufflen & 0xff, 93 bufflen & 0xff,
93 0 94 0
94 }; 95 };
96 unsigned char recv_page_code;
95 97
96 return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen, 98 ret = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen,
97 NULL, SES_TIMEOUT, SES_RETRIES, NULL); 99 NULL, SES_TIMEOUT, SES_RETRIES, NULL);
100 if (unlikely(!ret))
101 return ret;
102
103 recv_page_code = ((unsigned char *)buf)[0];
104
105 if (likely(recv_page_code == page_code))
106 return ret;
107
108 /* successful diagnostic but wrong page code. This happens to some
109 * USB devices, just print a message and pretend there was an error */
110
111 sdev_printk(KERN_ERR, sdev,
112 "Wrong diagnostic page; asked for %d got %u\n",
113 page_code, recv_page_code);
114
115 return -EINVAL;
98} 116}
99 117
100static int ses_send_diag(struct scsi_device *sdev, int page_code, 118static int ses_send_diag(struct scsi_device *sdev, int page_code,