diff options
| author | Nicholas Bellinger <nab@linux-iscsi.org> | 2014-01-30 16:08:49 -0500 |
|---|---|---|
| committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2014-02-12 18:11:01 -0500 |
| commit | fc09149df6e20cfbb0bb86f10899607c321a31eb (patch) | |
| tree | d8b6190b82010100caec7643e065d2dc233bc013 /drivers/target | |
| parent | b28a960c42fcd9cfc987441fa6d1c1a471f0f9ed (diff) | |
target: Fix free-after-use regression in PR unregister
This patch addresses a >= v3.11 free-after-use regression
in core_scsi3_emulate_pro_register() that was introduced
in the following commit:
commit bc118fe4c4a8cfa453491ba77c0a146a6d0e73e0
Author: Andy Grover <agrover@redhat.com>
Date: Thu May 16 10:41:04 2013 -0700
target: Further refactoring of core_scsi3_emulate_pro_register()
To avoid the free-after-use, save an type value before hand, and
only call core_scsi3_put_pr_reg() with a valid *pr_reg.
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Andy Grover <agrover@redhat.com>
Cc: <stable@vger.kernel.org> #3.11+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
| -rw-r--r-- | drivers/target/target_core_pr.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 2f5d77932c80..3013287a2aaa 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c | |||
| @@ -2009,7 +2009,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, | |||
| 2009 | struct t10_reservation *pr_tmpl = &dev->t10_pr; | 2009 | struct t10_reservation *pr_tmpl = &dev->t10_pr; |
| 2010 | unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL; | 2010 | unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL; |
| 2011 | sense_reason_t ret = TCM_NO_SENSE; | 2011 | sense_reason_t ret = TCM_NO_SENSE; |
| 2012 | int pr_holder = 0; | 2012 | int pr_holder = 0, type; |
| 2013 | 2013 | ||
| 2014 | if (!se_sess || !se_lun) { | 2014 | if (!se_sess || !se_lun) { |
| 2015 | pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); | 2015 | pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); |
| @@ -2131,6 +2131,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, | |||
| 2131 | ret = TCM_RESERVATION_CONFLICT; | 2131 | ret = TCM_RESERVATION_CONFLICT; |
| 2132 | goto out; | 2132 | goto out; |
| 2133 | } | 2133 | } |
| 2134 | type = pr_reg->pr_res_type; | ||
| 2134 | 2135 | ||
| 2135 | spin_lock(&pr_tmpl->registration_lock); | 2136 | spin_lock(&pr_tmpl->registration_lock); |
| 2136 | /* | 2137 | /* |
| @@ -2161,6 +2162,7 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, | |||
| 2161 | * Release the calling I_T Nexus registration now.. | 2162 | * Release the calling I_T Nexus registration now.. |
| 2162 | */ | 2163 | */ |
| 2163 | __core_scsi3_free_registration(cmd->se_dev, pr_reg, NULL, 1); | 2164 | __core_scsi3_free_registration(cmd->se_dev, pr_reg, NULL, 1); |
| 2165 | pr_reg = NULL; | ||
| 2164 | 2166 | ||
| 2165 | /* | 2167 | /* |
| 2166 | * From spc4r17, section 5.7.11.3 Unregistering | 2168 | * From spc4r17, section 5.7.11.3 Unregistering |
| @@ -2174,8 +2176,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, | |||
| 2174 | * RESERVATIONS RELEASED. | 2176 | * RESERVATIONS RELEASED. |
| 2175 | */ | 2177 | */ |
| 2176 | if (pr_holder && | 2178 | if (pr_holder && |
| 2177 | (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY || | 2179 | (type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY || |
| 2178 | pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) { | 2180 | type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY)) { |
| 2179 | list_for_each_entry(pr_reg_p, | 2181 | list_for_each_entry(pr_reg_p, |
| 2180 | &pr_tmpl->registration_list, | 2182 | &pr_tmpl->registration_list, |
| 2181 | pr_reg_list) { | 2183 | pr_reg_list) { |
| @@ -2194,7 +2196,8 @@ core_scsi3_emulate_pro_register(struct se_cmd *cmd, u64 res_key, u64 sa_res_key, | |||
| 2194 | ret = core_scsi3_update_and_write_aptpl(dev, aptpl); | 2196 | ret = core_scsi3_update_and_write_aptpl(dev, aptpl); |
| 2195 | 2197 | ||
| 2196 | out: | 2198 | out: |
| 2197 | core_scsi3_put_pr_reg(pr_reg); | 2199 | if (pr_reg) |
| 2200 | core_scsi3_put_pr_reg(pr_reg); | ||
| 2198 | return ret; | 2201 | return ret; |
| 2199 | } | 2202 | } |
| 2200 | 2203 | ||
