diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2007-03-02 19:55:55 -0500 |
---|---|---|
committer | James Bottomley <jejb@mulgrave.il.steeleye.com> | 2007-03-11 12:39:39 -0400 |
commit | e8f8248cbadcd8cb1b737fc57a01bccca4fb7aec (patch) | |
tree | c419893a73f1c4392e9d1acbff3bf7dfc56c5df0 /drivers | |
parent | bc7e380a6a4c94f79a49c36bdb28062a750b3c2b (diff) |
[SCSI] tgt: fix scsi command leak
The failure to map user-space pages leads to scsi command leak. It can
happens mostly because of user-space daemon bugs (or OOM). This patch
makes tgt just notify a LLD of the failure with sense when
blk_rq_map_user() fails.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/scsi/scsi_tgt_lib.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c index dc8781a68d7c..c05dff95bd95 100644 --- a/drivers/scsi/scsi_tgt_lib.c +++ b/drivers/scsi/scsi_tgt_lib.c | |||
@@ -459,6 +459,16 @@ static struct request *tgt_cmd_hash_lookup(struct request_queue *q, u64 tag) | |||
459 | return rq; | 459 | return rq; |
460 | } | 460 | } |
461 | 461 | ||
462 | static void scsi_tgt_build_sense(unsigned char *sense_buffer, unsigned char key, | ||
463 | unsigned char asc, unsigned char asq) | ||
464 | { | ||
465 | sense_buffer[0] = 0x70; | ||
466 | sense_buffer[2] = key; | ||
467 | sense_buffer[7] = 0xa; | ||
468 | sense_buffer[12] = asc; | ||
469 | sense_buffer[13] = asq; | ||
470 | } | ||
471 | |||
462 | int scsi_tgt_kspace_exec(int host_no, int result, u64 tag, | 472 | int scsi_tgt_kspace_exec(int host_no, int result, u64 tag, |
463 | unsigned long uaddr, u32 len, unsigned long sense_uaddr, | 473 | unsigned long uaddr, u32 len, unsigned long sense_uaddr, |
464 | u32 sense_len, u8 rw) | 474 | u32 sense_len, u8 rw) |
@@ -514,9 +524,16 @@ int scsi_tgt_kspace_exec(int host_no, int result, u64 tag, | |||
514 | if (len) { | 524 | if (len) { |
515 | err = scsi_map_user_pages(rq->end_io_data, cmd, uaddr, len, rw); | 525 | err = scsi_map_user_pages(rq->end_io_data, cmd, uaddr, len, rw); |
516 | if (err) { | 526 | if (err) { |
517 | eprintk("%p %d\n", cmd, err); | 527 | /* |
518 | err = -EAGAIN; | 528 | * user-space daemon bugs or OOM |
519 | goto done; | 529 | * TODO: we can do better for OOM. |
530 | */ | ||
531 | eprintk("cmd %p ret %d uaddr %lx len %d rw %d\n", | ||
532 | cmd, err, uaddr, len, rw); | ||
533 | cmd->result = SAM_STAT_CHECK_CONDITION; | ||
534 | memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); | ||
535 | scsi_tgt_build_sense(cmd->sense_buffer, | ||
536 | HARDWARE_ERROR, 0, 0); | ||
520 | } | 537 | } |
521 | } | 538 | } |
522 | err = scsi_tgt_transfer_response(cmd); | 539 | err = scsi_tgt_transfer_response(cmd); |