* [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip
@ 2021-05-24 9:50 Lv Yunlong
2021-06-29 22:02 ` Martin K. Petersen
0 siblings, 1 reply; 4+ messages in thread
From: Lv Yunlong @ 2021-05-24 9:50 UTC (permalink / raw)
To: subbu.seetharaman, ketan.mukadam, jitendra.bhivare, jejb,
martin.petersen
Cc: linux-scsi, linux-kernel, Lv Yunlong
In the free_cmd error path of callee beiscsi_exec_nemb_cmd(),
nonemb_cmd->va is freed by dma_free_coherent().
As req = nonemb_cmd.va, we can see that the freed nonemb_cmd.va
is still dereferenced and used by req->ip_params.ip_record.status.
My patch uses status to replace req->ip_params.ip_record.status
to avoid the uaf.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/scsi/be2iscsi/be_mgmt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 462717bbb5b7..f05fcea707cd 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -509,6 +509,7 @@ beiscsi_if_clr_ip(struct beiscsi_hba *phba,
{
struct be_cmd_set_ip_addr_req *req;
struct be_dma_mem nonemb_cmd;
+ u32 status;
int rc;
rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI,
@@ -531,11 +532,12 @@ beiscsi_if_clr_ip(struct beiscsi_hba *phba,
memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
if_info->ip_addr.subnet_mask,
sizeof(if_info->ip_addr.subnet_mask));
+ status = req->ip_params.ip_record.status;
rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0);
- if (rc < 0 || req->ip_params.ip_record.status) {
+ if (rc < 0 || status) {
beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
"BG_%d : failed to clear IP: rc %d status %d\n",
- rc, req->ip_params.ip_record.status);
+ rc, status);
}
return rc;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip
2021-05-24 9:50 [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip Lv Yunlong
@ 2021-06-29 22:02 ` Martin K. Petersen
2021-07-01 1:13 ` michael.christie
0 siblings, 1 reply; 4+ messages in thread
From: Martin K. Petersen @ 2021-06-29 22:02 UTC (permalink / raw)
To: Lv Yunlong
Cc: subbu.seetharaman, ketan.mukadam, jitendra.bhivare, jejb,
martin.petersen, linux-scsi, linux-kernel, Mike Christie
Lv,
> In the free_cmd error path of callee beiscsi_exec_nemb_cmd(),
> nonemb_cmd->va is freed by dma_free_coherent(). As req =
> nonemb_cmd.va, we can see that the freed nonemb_cmd.va is still
> dereferenced and used by req->ip_params.ip_record.status.
> My patch uses status to replace req->ip_params.ip_record.status to
> avoid the uaf.
This status is captured prior to executing the command so it doesn't
actually reflect whether the operation was successful (which I believe
was the intent).
Some of the callers of beiscsi_exec_nemb_cmd() pass a response buffer
and a response length as the two last arguments. Since
beiscsi_exec_nemb_cmd() frees the command before returning, passing a
response buffer seems to be the only way to get meaningful data out.
I am not sure whether the OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR
operation returns something useful from the controller. As far as I can
tell not all operations have a response buffer defined.
My recommendation would be to add a response buffer and try to decipher
what comes back from the firmware. Also, beiscsi_if_set_ip() appears to
have the same problem as beiscsi_if_clr_ip().
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip
2021-06-29 22:02 ` Martin K. Petersen
@ 2021-07-01 1:13 ` michael.christie
0 siblings, 0 replies; 4+ messages in thread
From: michael.christie @ 2021-07-01 1:13 UTC (permalink / raw)
To: Martin K. Petersen, Lv Yunlong
Cc: subbu.seetharaman, ketan.mukadam, jitendra.bhivare, jejb,
linux-scsi, linux-kernel
On 6/29/21 5:02 PM, Martin K. Petersen wrote:
>
> Lv,
>
>> In the free_cmd error path of callee beiscsi_exec_nemb_cmd(),
>> nonemb_cmd->va is freed by dma_free_coherent(). As req =
>> nonemb_cmd.va, we can see that the freed nonemb_cmd.va is still
>> dereferenced and used by req->ip_params.ip_record.status.
>
>> My patch uses status to replace req->ip_params.ip_record.status to
>> avoid the uaf.
>
> This status is captured prior to executing the command so it doesn't
> actually reflect whether the operation was successful (which I believe
> was the intent).
>
> Some of the callers of beiscsi_exec_nemb_cmd() pass a response buffer
> and a response length as the two last arguments. Since
> beiscsi_exec_nemb_cmd() frees the command before returning, passing a
> response buffer seems to be the only way to get meaningful data out.
>
> I am not sure whether the OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR
> operation returns something useful from the controller. As far as I can
> tell not all operations have a response buffer defined.
>
> My recommendation would be to add a response buffer and try to decipher
> what comes back from the firmware. Also, beiscsi_if_set_ip() appears to
> have the same problem as beiscsi_if_clr_ip().
>
Hopefully the broadcom devs will chime in, but it doesn't look like we get
a response buffer. I think we just need to move the:
dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd->size,
nonemb_cmd->va, nonemb_cmd->dma);
to a helper and have the callers free the cmd.
Oh yeah, I guess we haven't been able to hit this bug, because
beiscsi_if_set_ip/beiscsi_if_clr_ip hasn't been run since 2013.
This patch
https://patchwork.kernel.org/project/linux-scsi/patch/20210701002559.89533-1-michael.christie@oracle.com/
allows us to be able to set the IP and hit those code paths.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip
@ 2021-04-03 6:40 Lv Yunlong
0 siblings, 0 replies; 4+ messages in thread
From: Lv Yunlong @ 2021-04-03 6:40 UTC (permalink / raw)
To: subbu.seetharaman, ketan.mukadam, jitendra.bhivare, jejb,
martin.petersen
Cc: linux-scsi, linux-kernel, Lv Yunlong
In the free_cmd error path of callee beiscsi_exec_nemb_cmd(),
nonemb_cmd->va is freed by dma_free_coherent().
As req = nonemb_cmd.va, we can see that the freed nonemb_cmd.va
is still dereferenced and used by req->ip_params.ip_record.status.
My patch uses status to replace req->ip_params.ip_record.status
to avoid the uaf.
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
drivers/scsi/be2iscsi/be_mgmt.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/be2iscsi/be_mgmt.c b/drivers/scsi/be2iscsi/be_mgmt.c
index 0d4928567265..b93b1a8c6c81 100644
--- a/drivers/scsi/be2iscsi/be_mgmt.c
+++ b/drivers/scsi/be2iscsi/be_mgmt.c
@@ -509,6 +509,7 @@ beiscsi_if_clr_ip(struct beiscsi_hba *phba,
{
struct be_cmd_set_ip_addr_req *req;
struct be_dma_mem nonemb_cmd;
+ u32 status;
int rc;
rc = beiscsi_prep_nemb_cmd(phba, &nonemb_cmd, CMD_SUBSYSTEM_ISCSI,
@@ -531,11 +532,12 @@ beiscsi_if_clr_ip(struct beiscsi_hba *phba,
memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
if_info->ip_addr.subnet_mask,
sizeof(if_info->ip_addr.subnet_mask));
+ status = req->ip_params.ip_record.status;
rc = beiscsi_exec_nemb_cmd(phba, &nonemb_cmd, NULL, NULL, 0);
- if (rc < 0 || req->ip_params.ip_record.status) {
+ if (rc < 0 || status) {
beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
"BG_%d : failed to clear IP: rc %d status %d\n",
- rc, req->ip_params.ip_record.status);
+ rc, status);
}
return rc;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-01 1:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 9:50 [PATCH] scsi: be2iscsi: Fix a use after free in beiscsi_if_clr_ip Lv Yunlong
2021-06-29 22:02 ` Martin K. Petersen
2021-07-01 1:13 ` michael.christie
-- strict thread matches above, loose matches on Subject: below --
2021-04-03 6:40 Lv Yunlong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.