NVMe/TCP: Fixed the out of order H2C PDU Crash
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): BL3PR01MB684908447A2F3F7D2AFC57DAC8A3A@BL3PR01MB6849.prod.exchangelabs.com
PATCH 1/1 NVMe/TCP: Fixed the out of order H2C PDU Crash
From: Shivam <[email protected]>
--- drivers/nvme/target/tcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/nvme/target/tcp.c +12 -0
@@ -982,6 +982,18 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)pr_err ("H2CData PDU len %u is invalid\n" , cmd->pdu_len); goto err_proto; } +/* +* Ensure command data structures are initialized. we must check both +* cmd->req.sg and cmd->iov because they can have different NULL state: +*- Unintialized commands: both NULL +*- READ commands: cmd->req.sg allocated, cmd->iov NULL +*- WRITE commands: both allocated +*/ +if (unlikely (!cmd->req.sg || !cmd->iov)) { +pr_err ("queue %d: H2CData PDU received for invalid command state (ttag %u)\n" , + queue->idx, data->ttag); + goto err_proto; + } cmd->pdu_recv =0 ;nvmet_tcp_build_pdu_iovec (cmd); queue->cmd = cmd;
Signature · 1 line
2.34.1
Jens Axboe
maintainerQuoted 3 lines · Shivam
From: Shivam <[email protected]>
Signed-off-by Shivam Kumar <[email protected]>
You forgot to write an actual commit message.
Signature · 1 line
Jens Axboe
PATCH v2 1/1 nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
From: Shivam <[email protected]>
The CVE-2023-6356 patch added ttag bounds checking and data_offset validation in nvmet_tcp_handle_h2c_data_pdu(), but it did not validate whether the command's data structures (cmd->req.sg and cmd->iov) have been properly initialized before processing H2C_DATA PDUs.
The nvmet_tcp_build_pdu_iovec() function dereferences these pointers without NULL checks. This can be triggered by sending an H2C_DATA PDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command.
Attack vectors that trigger NULL pointer dereferences:
1. H2C_DATA PDU sent before CONNECT → both pointers NULL
2. H2C_DATA PDU for READ command → cmd->req.sg allocated, cmd->iov NULL
3. H2C_DATA PDU for uninitialized command slot → both pointers NULL
The fix validates both cmd->req.sg and cmd->iov before calling nvmet_tcp_build_pdu_iovec(). Both checks are required because:
- Uninitialized commands: both NULL
- READ commands: cmd->req.sg allocated, cmd->iov NULL
- WRITE commands: both allocated
--- drivers/nvme/target/tcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/nvme/target/tcp.c +12 -0
@@ -982,6 +982,18 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)pr_err ("H2CData PDU len %u is invalid\n" , cmd->pdu_len); goto err_proto; } +/* +* Ensure command data structures are initialized. We must check both +* cmd->req.sg and cmd->iov because they can have different NULL states: +* - Uninitialized commands: both NULL +* - READ commands: cmd->req.sg allocated, cmd->iov NULL +* - WRITE commands: both allocated +*/ +if (unlikely (!cmd->req.sg || !cmd->iov)) { +pr_err ("queue %d: H2CData PDU received for invalid command state (ttag %u)\n" , + queue->idx, data->ttag); + goto err_proto; + } cmd->pdu_recv =0 ;nvmet_tcp_build_pdu_iovec (cmd); queue->cmd = cmd;
Signature · 1 line
2.34.1
Jens Axboe
maintainerRe: [PATCH v2] nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
Quoted 3 lines · Shivam
From: Shivam <[email protected]>
The CVE-2023-6356 patch added ttag bounds checking and
data_offset
Please just replace that with an actual sha, and add it as a Fixes tag too. No need to resend for that, I'm assuming whoever applies this can sort that out. Some random CVE number doesn't mean anything to me, a sha is something that is easily identifiable.
Rest of commit message looks good.
Quoted 14 lines
validation in
nvmet_tcp_handle_h2c_data_pdu(), but it did not validate whether the command's data structures (cmd->req.sgandcmd->iov) have been properly initialized before processingH2C_DATAPDUs.The
nvmet_tcp_build_pdu_iovec()function dereferences these pointers without NULL checks. This can be triggered by sending anH2C_DATAPDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command.Attack vectors that trigger NULL pointer dereferences:
1.H2C_DATAPDU sent before CONNECT → both pointers NULL
2.H2C_DATAPDU for READ command →cmd->req.sgallocated,cmd->iovNULL
3.H2C_DATAPDU for uninitialized command slot → both pointers NULL
Quoted 8 lines
The fix validates both
cmd->req.sgandcmd->iovbefore callingnvmet_tcp_build_pdu_iovec(). Both checks are required because:
- Uninitialized commands: both NULL
- READ commands:cmd->req.sgallocated,cmd->iovNULL
- WRITE commands: both allocatedReported-by Shivam Kumar <[email protected]>Signed-off-by Shivam Kumar <[email protected]>
No need for the Reported-by tag, you already have your SOB there.
Signature · 1 line
Jens Axboe
Re: [PATCH v2] nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
In reply to ShivamQuoted 3 lines · Shivam
From: Shivam <[email protected]>
The CVE-2023-6356 patch
Can you provide the commit hash here?
Quoted 15 lines
added ttag bounds checking and
data_offset
validation innvmet_tcp_handle_h2c_data_pdu(), but it did not validate whether the command's data structures (cmd->req.sgandcmd->iov) have been properly initialized before processingH2C_DATAPDUs.The
nvmet_tcp_build_pdu_iovec()function dereferences these pointers without NULL checks. This can be triggered by sending anH2C_DATAPDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command.Attack vectors that trigger NULL pointer dereferences:
1.H2C_DATAPDU sent before CONNECT → both pointers NULL
2.H2C_DATAPDU for READ command →cmd->req.sgallocated,cmd->iovNULL
3.H2C_DATAPDU for uninitialized command slot → both pointers NULL
Quoted 5 lines
The fix validates both
cmd->req.sgandcmd->iovbefore callingnvmet_tcp_build_pdu_iovec(). Both checks are required because:
- Uninitialized commands: both NULL
- READ commands:cmd->req.sgallocated,cmd->iovNULL
- WRITE commands: both allocated
Needs a Fixes tag.
Other than that, you can add my:
on your v3.
Re: [PATCH v2] nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
In reply to ShivamQuoted 1 line · Shivam
From: Shivam <[email protected]>
Does not match your signed-off-by line :(
PATCH v3 1/1 nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
In reply to Jens AxboeCommit efa56305908b ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length") added ttag bounds checking and data_offset
validation in nvmet_tcp_handle_h2c_data_pdu(), but it did not validate
whether the command's data structures (cmd->req.sg and cmd->iov) have
been properly initialized before processing H2C_DATA PDUs.
The nvmet_tcp_build_pdu_iovec() function dereferences these pointers without NULL checks. This can be triggered by sending H2C_DATA PDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command.
Attack vectors that trigger NULL pointer dereferences:
1. H2C_DATA PDU sent before CONNECT → both pointers NULL
2. H2C_DATA PDU for READ command → cmd->req.sg allocated, cmd->iov NULL
3. H2C_DATA PDU for uninitialized command slot → both pointers NULL
The fix validates both cmd->req.sg and cmd->iov before calling nvmet_tcp_build_pdu_iovec(). Both checks are required because:
- Uninitialized commands: both NULL
- READ commands: cmd->req.sg allocated, cmd->iov NULL
- WRITE commands: both allocated
--- drivers/nvme/target/tcp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/nvme/target/tcp.c +12 -0
@@ -982,6 +982,18 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)pr_err ("H2CData PDU len %u is invalid\n" , cmd->pdu_len); goto err_proto; } +/* +* Ensure command data structures are initialized. We must check both +* cmd->req.sg and cmd->iov because they can have different NULL states: +* - Uninitialized commands: both NULL +* - READ commands: cmd->req.sg allocated, cmd->iov NULL +* - WRITE commands: both allocated +*/ +if (unlikely (!cmd->req.sg || !cmd->iov)) { +pr_err ("queue %d: H2CData PDU received for invalid command state (ttag %u)\n" , + queue->idx, data->ttag); + goto err_proto; + } cmd->pdu_recv =0 ;nvmet_tcp_build_pdu_iovec (cmd); queue->cmd = cmd;
Signature · 1 line
2.34.1
Re: [PATCH v3] nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec
Quoted 16 lines · Shivam Kumar
Commit
efa56305908b("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length") added ttag bounds checking anddata_offset
validation innvmet_tcp_handle_h2c_data_pdu(), but it did not validate
whether the command's data structures (cmd->req.sgandcmd->iov) have
been properly initialized before processingH2C_DATAPDUs.The
nvmet_tcp_build_pdu_iovec()function dereferences these pointers without NULL checks. This can be triggered by sendingH2C_DATAPDU immediately after the ICREQ/ICRESP handshake, before sending a CONNECT command or NVMe write command.Attack vectors that trigger NULL pointer dereferences:
1.H2C_DATAPDU sent before CONNECT -> both pointers NULL
2.H2C_DATAPDU for READ command ->cmd->req.sgallocated,cmd->iovNULL
3.H2C_DATAPDU for uninitialized command slot -> both pointers NULL
Quoted 5 lines
The fix validates both
cmd->req.sgandcmd->iovbefore callingnvmet_tcp_build_pdu_iovec(). Both checks are required because:
- Uninitialized commands: both NULL
- READ commands:cmd->req.sgallocated,cmd->iovNULL
- WRITE commands: both allocated
Thanks, applied.