Skip to content

Commit

Permalink
scsi: target: core: Fix error path in target_setup_session()
Browse files Browse the repository at this point in the history
commit 9127169 upstream.

In the error exits in target_setup_session(), if a branch is taken to
free_sess: transport_free_session() may call to target_free_cmd_counter()
and then fall through to call target_free_cmd_counter() a second time.
This can, and does, sometimes cause seg faults since the data field in
cmd_cnt->refcnt has been freed in the first call.

Fix this problem by simply returning after the call to
transport_free_session(). The second call is redundant for those cases.

Fixes: 4edba7e ("scsi: target: Move cmd counter allocation")
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
Link: https://lore.kernel.org/r/20230613144259.12890-1-rpearsonhpe@gmail.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Bob Pearson authored and Greg Kroah-Hartman committed Jun 21, 2023
1 parent b0ec36d commit 0c7d966
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/target/target_core_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ target_setup_session(struct se_portal_group *tpg,

free_sess:
transport_free_session(sess);
return ERR_PTR(rc);

free_cnt:
target_free_cmd_counter(cmd_cnt);
return ERR_PTR(rc);
Expand Down

0 comments on commit 0c7d966

Please sign in to comment.