scsi: qedi: fix OOB read in login/text response completion
Subsystems (3)
PATCH 1/1 scsi: qedi: fix OOB read in login/text response completion
qedi_process_text_resp() and qedi_process_login_resp() take the payload length straight from the CQE field (hdr_second_dword & ISCSI_{LOGIN,TEXT}_RESPONSE_HDR_DATA_SEG_LEN_MASK, 24 bits) written back by the adapter, without any bounds check:
pld_len = cqe_text_response->hdr_second_dword & ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len; ... __iscsi_complete_pdu(conn, ..., qedi_conn->gen_pdu.resp_buf, (qedi_conn->gen_pdu.resp_wr_ptr - qedi_conn->gen_pdu.resp_buf));
resp_buf is an 8192-byte buffer (qedi_iscsi.c). A CQE whose data segment length exceeds the buffer makes resp_wr_ptr point past its end, and the fabricated length is then passed to __iscsi_complete_pdu() as the response buffer size: an out-of-bounds read of the buffer (and beyond) delivered to the iscsi userspace daemon over the iscsi_recv_pdu netlink unicast.
Clamp the payload length to the response buffer size before computing the write pointer, in both the login and text response handlers.
This issue was discovered by Tencent CodeBuddy Security.
--- drivers/scsi/qedi/qedi_fw.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/scsi/qedi/qedi_fw.c +4 -0
@@ -115,6 +115,8 @@ static void qedi_process_text_resp(struct qedi_ctx *qedi, pld_len = cqe_text_response->hdr_second_dword &ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;memset (task_ctx,'\0' ,sizeof (*task_ctx));
@@ -292,6 +294,8 @@ static void qedi_process_login_resp(struct qedi_ctx *qedi, resp_hdr_ptr->status_detail = cqe_login_response->status_detail; pld_len = cqe_login_response->hdr_second_dword &ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;spin_lock (&qedi_conn->list_lock);
Signature · 1 line
2.43.7
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] scsi: qedi: unclamped dlength in qedi_process_text_resp() and login_resp() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: qedi: unclamped dlength in qedi_process_text_resp() and login_resp() --
commit b81ce3a14651452d3f551e4635d2337a8b305729
Author: Henry Martin <[email protected]>
scsi: qedi: fix OOB read in login/text response completion
This commit clamps the payload length extracted from the CQE in qedi_process_text_resp() and qedi_process_login_resp() to qedi_conn->gen_pdu.resp_buf_size before advancing resp_wr_ptr, preventing an out-of-bounds read when completing the PDU to userspace.
Quoted 14 lines
drivers/scsi/qedi/qedi_fw.c +2
-0@@ -115,6 +115,8 @@ static void qedi_process_text_resp(struct qedi_ctx *qedi, pld_len = cqe_text_response->hdr_second_dword &ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;memset (task_ctx,'\0' ,sizeof (*task_ctx));
drivers/scsi/qedi/qedi_fw.c static void qedi_process_login_resp(struct qedi_ctx *qedi, · line 301
Quoted 6 lines
drivers/scsi/qedi/qedi_fw.c +2
-0@@ -294,6 +296,8 @@ static void qedi_process_login_resp(struct qedi_ctx *qedi, resp_hdr_ptr->status_detail = cqe_login_response->status_detail; pld_len = cqe_login_response->hdr_second_dword &ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;
[Severity: Medium]
Should resp_hdr_ptr->dlength also be populated from the clamped pld_len in both qedi_process_text_resp() and qedi_process_login_resp()?
Earlier in both functions, resp_hdr_ptr->dlength is written using the raw unclamped 24-bit CQE value before pld_len is clamped to qedi_conn->gen_pdu.resp_buf_size:
drivers/scsi/qedi/qedi_fw.c:qedi_process_text_resp() {
...
hton24(resp_hdr_ptr->dlength,
(cqe_text_response->hdr_second_dword &
ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK));
...
pld_len = cqe_text_response->hdr_second_dword &
ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK;
if (pld_len > qedi_conn->gen_pdu.resp_buf_size)
pld_len = qedi_conn->gen_pdu.resp_buf_size;
qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;and similarly in qedi_process_login_resp():
drivers/scsi/qedi/qedi_fw.c:qedi_process_login_resp() {
...
hton24(resp_hdr_ptr->dlength,
(cqe_login_response->hdr_second_dword &
ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK));
...
pld_len = cqe_login_response->hdr_second_dword &
ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK;
if (pld_len > qedi_conn->gen_pdu.resp_buf_size)
pld_len = qedi_conn->gen_pdu.resp_buf_size;
qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;When __iscsi_complete_pdu() calls iscsi_recv_pdu(), the netlink message is allocated and populated with only data_size (the clamped pld_len) bytes of payload following the header:
drivers/scsi/scsi_transport_iscsi.c:iscsi_recv_pdu() {
int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) +
data_size);
...
pdu = (char*)ev + sizeof(*ev);
memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);If the CQE data segment length exceeds resp_buf_size, won't this leave resp_hdr_ptr->dlength advertising the larger unclamped length in the embedded struct iscsi_hdr while only resp_buf_size bytes of payload are actually present in the netlink message sent to userspace?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Correct, thanks. Confirmed in-tree: push_callback_call() only propagates -EFAULT from btf_check_subprog_call(), so the -EINVAL path reaches check_stack_arg_read() with caller->stack_arg_regs unvalidated or stale - and it is a heap array sized by out_stack_arg_cnt, so this is a NULL deref or stale-state copy.
One refinement: set_timer_callback_state() (async timer/workqueue) does not set in_callback_fn, so that check alone misses the original frame[-1] case. v2 rejects on both:
if (vstate->curframe == 0 || state->in_callback_fn)
pw-bot: cr
Regards,
Henry
Quoted 89 lines · <[email protected]> 于2026年10月27日周二 23:23写道:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] scsi: qedi: unclamped dlength inqedi_process_text_resp()andlogin_resp()--commit
b81ce3a14651452d3f551e4635d2337a8b305729
Author: Henry Martin <[email protected]>scsi: qedi: fix OOB read in login/text response completion
This commit clamps the payload length extracted from the CQE in
qedi_process_text_resp()andqedi_process_login_resp()toqedi_conn->gen_pdu.resp_buf_sizebefore advancingresp_wr_ptr, preventing an out-of-bounds read when completing the PDU to userspace.Quoted 14 lines
drivers/scsi/qedi/qedi_fw.c +2
-0@@ -115,6 +115,8 @@ static void qedi_process_text_resp(struct qedi_ctx *qedi, pld_len = cqe_text_response->hdr_second_dword &ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;memset (task_ctx,'\0' ,sizeof (*task_ctx));drivers/scsi/qedi/qedi_fw.c static void qedi_process_login_resp(struct qedi_ctx *qedi, · line 301
Quoted 6 lines
drivers/scsi/qedi/qedi_fw.c +2
-0@@ -294,6 +296,8 @@ static void qedi_process_login_resp(struct qedi_ctx *qedi, resp_hdr_ptr->status_detail = cqe_login_response->status_detail; pld_len = cqe_login_response->hdr_second_dword &ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK ; +if (pld_len > qedi_conn->gen_pdu.resp_buf_size) + pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;[Severity: Medium]
Shouldresp_hdr_ptr->dlengthalso be populated from the clampedpld_lenin bothqedi_process_text_resp()andqedi_process_login_resp()?Earlier in both functions,
resp_hdr_ptr->dlengthis written using the raw unclamped 24-bit CQE value beforepld_lenis clamped toqedi_conn->gen_pdu.resp_buf_size:drivers/scsi/qedi/qedi_fw.c:qedi_process_text_resp() { ... hton24(resp_hdr_ptr->dlength, (cqe_text_response->hdr_second_dword & ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK)); ... pld_len = cqe_text_response->hdr_second_dword & ISCSI_TEXT_RESPONSE_HDR_DATA_SEG_LEN_MASK; if (pld_len > qedi_conn->gen_pdu.resp_buf_size) pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;and similarly in
qedi_process_login_resp():drivers/scsi/qedi/qedi_fw.c:qedi_process_login_resp() { ... hton24(resp_hdr_ptr->dlength, (cqe_login_response->hdr_second_dword & ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK)); ... pld_len = cqe_login_response->hdr_second_dword & ISCSI_LOGIN_RESPONSE_HDR_DATA_SEG_LEN_MASK; if (pld_len > qedi_conn->gen_pdu.resp_buf_size) pld_len = qedi_conn->gen_pdu.resp_buf_size; qedi_conn->gen_pdu.resp_wr_ptr = qedi_conn->gen_pdu.resp_buf + pld_len;When
__iscsi_complete_pdu()callsiscsi_recv_pdu(), the netlink message is allocated and populated with onlydata_size(the clampedpld_len) bytes of payload following the header:drivers/scsi/scsi_transport_iscsi.c:iscsi_recv_pdu() { int len = nlmsg_total_size(sizeof(*ev) + sizeof(struct iscsi_hdr) + data_size); ... pdu = (char*)ev + sizeof(*ev); memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);If the CQE data segment length exceeds
resp_buf_size, won't this leaveresp_hdr_ptr->dlengthadvertising the larger unclamped length in the embedded structiscsi_hdrwhile onlyresp_buf_sizebytes of payload are actually present in the netlink message sent to userspace?--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1