提交 f7068114 编写于 作者: J Jens Axboe

sr: pass down correctly sized SCSI sense buffer

We're casting the CDROM layer request_sense to the SCSI sense
buffer, but the former is 64 bytes and the latter is 96 bytes.
As we generally allocate these on the stack, we end up blowing
up the stack.

Fix this by wrapping the scsi_execute() call with a properly
sized sense buffer, and copying back the bits for the CDROM
layer.

Cc: stable@vger.kernel.org
Reported-by: NPiotr Gabriel Kosinski <pg.kosinski@gmail.com>
Reported-by: NDaniel Shapira <daniel@twistlock.com>
Tested-by: NKees Cook <keescook@chromium.org>
Fixes: 82ed4db4 ("block: split scsi_request out of struct request")
Signed-off-by: NJens Axboe <axboe@kernel.dk>
上级 1c1a2ee1
...@@ -188,9 +188,13 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) ...@@ -188,9 +188,13 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
struct scsi_device *SDev; struct scsi_device *SDev;
struct scsi_sense_hdr sshdr; struct scsi_sense_hdr sshdr;
int result, err = 0, retries = 0; int result, err = 0, retries = 0;
unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE], *senseptr = NULL;
SDev = cd->device; SDev = cd->device;
if (cgc->sense)
senseptr = sense_buffer;
retry: retry:
if (!scsi_block_when_processing_errors(SDev)) { if (!scsi_block_when_processing_errors(SDev)) {
err = -ENODEV; err = -ENODEV;
...@@ -198,10 +202,12 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) ...@@ -198,10 +202,12 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
} }
result = scsi_execute(SDev, cgc->cmd, cgc->data_direction, result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
cgc->buffer, cgc->buflen, cgc->buffer, cgc->buflen, senseptr, &sshdr,
(unsigned char *)cgc->sense, &sshdr,
cgc->timeout, IOCTL_RETRIES, 0, 0, NULL); cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
if (cgc->sense)
memcpy(cgc->sense, sense_buffer, sizeof(*cgc->sense));
/* Minimal error checking. Ignore cases we know about, and report the rest. */ /* Minimal error checking. Ignore cases we know about, and report the rest. */
if (driver_byte(result) != 0) { if (driver_byte(result) != 0) {
switch (sshdr.sense_key) { switch (sshdr.sense_key) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册