scsi: fix use-after-free in scsi_init_io()
PATCH 1/1 scsi: fix use-after-free in scsi_init_io()
scsi_init_io() dereferences scsi_cmnd after putting it in the error path leading to oops. Fix it.
Signed-off-by Tejun Heo <[email protected]>
--- drivers/scsi/scsi_lib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +3 -1
@@ -968,7 +968,9 @@ static int scsi_init_sgtable(struct requ*/ int scsi_init_io (struct scsi_cmnd *cmd,gfp_t gfp_mask) { +struct request *req = cmd->request;int error =scsi_init_sgtable (cmd->request, &cmd->sdb, gfp_mask); +if (error) goto err_exit;
@@ -1012,7 +1014,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, err_exit:scsi_release_buffers (cmd);scsi_put_command (cmd); - cmd->request->special =NULL ; + req->special =NULL ;return error; }EXPORT_SYMBOL (scsi_init_io);
Quoted 24 lines · Tejun Heo
scsi_init_io()dereferencesscsi_cmndafter putting it in the error path leading to oops. Fix it.Signed-off-by Tejun Heo <[email protected]>--- drivers/scsi/scsi_lib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Index:
block/drivers/scsi/scsi_lib.c
===================================================================drivers/scsi/scsi_lib.c +2
-0@@ -968,7 +968,9 @@ static int scsi_init_sgtable(struct requ*/ int scsi_init_io (struct scsi_cmnd *cmd,gfp_t gfp_mask) { +struct request *req = cmd->request;int error =scsi_init_sgtable (cmd->request, &cmd->sdb, gfp_mask); +if (error) goto err_exit;
drivers/scsi/scsi_lib.c int scsi_init_io(struct scsi_cmnd *cmd, · line 1017
Quoted 5 lines
drivers/scsi/scsi_lib.c +1
-1@@ -1012,7 +1014,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, err_exit:scsi_release_buffers (cmd);scsi_put_command (cmd); - cmd->request->special =NULL ; + req->special =NULL ;
Thanks for the bug report. The fix is a bit heavy handed; what about this?
James
---
drivers/scsi/scsi_lib.c +1 -1
@@ -1011,8 +1011,8 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask) err_exit:scsi_release_buffers (cmd); -scsi_put_command (cmd); cmd->request->special =NULL ; +scsi_put_command (cmd);return error; }EXPORT_SYMBOL (scsi_init_io);
Hello,
Quoted 2 lines · James Bottomley
Thanks for the bug report. The fix is a bit heavy handed; what about this?
Yeap, sure. Looks good to me.
Signature · 1 line
tejun