Skip to content

Commit f706811

Browse files
committed
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: [email protected] Reported-by: Piotr Gabriel Kosinski <[email protected]> Reported-by: Daniel Shapira <[email protected]> Tested-by: Kees Cook <[email protected]> Fixes: 82ed4db ("block: split scsi_request out of struct request") Signed-off-by: Jens Axboe <[email protected]>
1 parent 1c1a2ee commit f706811

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/scsi/sr_ioctl.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,26 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
188188
struct scsi_device *SDev;
189189
struct scsi_sense_hdr sshdr;
190190
int result, err = 0, retries = 0;
191+
unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE], *senseptr = NULL;
191192

192193
SDev = cd->device;
193194

195+
if (cgc->sense)
196+
senseptr = sense_buffer;
197+
194198
retry:
195199
if (!scsi_block_when_processing_errors(SDev)) {
196200
err = -ENODEV;
197201
goto out;
198202
}
199203

200204
result = scsi_execute(SDev, cgc->cmd, cgc->data_direction,
201-
cgc->buffer, cgc->buflen,
202-
(unsigned char *)cgc->sense, &sshdr,
205+
cgc->buffer, cgc->buflen, senseptr, &sshdr,
203206
cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
204207

208+
if (cgc->sense)
209+
memcpy(cgc->sense, sense_buffer, sizeof(*cgc->sense));
210+
205211
/* Minimal error checking. Ignore cases we know about, and report the rest. */
206212
if (driver_byte(result) != 0) {
207213
switch (sshdr.sense_key) {

0 commit comments

Comments
 (0)