drivers: target: Fix error path in target_setup_session
Subsystems (2)
PATCH 1/1 drivers: target: Fix error path in target_setup_session
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. This patch fixes this problem by simply returning after the call to transport_free_session. The second call is redundant for those cases.
--- drivers/target/target_core_transport.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/target/target_core_transport.c +2 -0
@@ -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);
Signature · 1 line
2.39.2
Quoted 20 lines · Bob Pearson
In the error exits in
target_setup_session, if a branch is taken tofree_sess:transport_free_sessionmay call totarget_free_cmd_counterand then fall through to calltarget_free_cmd_countera second time. This can, and does, sometimes cause seg faults since the data field incmd_cnt->refcnthas been freed in the first call. This patch fixes this problem by simply returning after the call totransport_free_session. The second call is redundant for those cases.Fixes 4edba7e4a8f3 ("scsi: target: Move cmd counter allocation")Signed-off-by Bob Pearson <[email protected]>--- drivers/target/target_core_transport.c | 2 ++ 1 file changed, 2 insertions(+)drivers/target/target_core_transport.c +0
-0
drivers/target/target_core_transport.c target_setup_session(struct se_portal_group *tpg, · line 511
Quoted 8 lines
drivers/target/target_core_transport.c +2
-0@@ -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);
Thanks. Reviewed-by: Mike Christie <[email protected]>
Martin K. Petersen
AppliedQuoted 10 lines · Bob Pearson
In the error exits in
target_setup_session, if a branch is taken tofree_sess:transport_free_sessionmay call totarget_free_cmd_counterand then fall through to calltarget_free_cmd_countera second time. This can, and does, sometimes cause seg faults since the data field incmd_cnt->refcnthas been freed in the first call. This patch fixes this problem by simply returning after the call totransport_free_session. The second call is redundant for those cases.[...]
Applied to 6.4/scsi-fixes, thanks!
[1/1] drivers: target: Fix error path in target_setup_session
https://git.kernel.org/mkp/scsi/c/91271699228b
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering