Skip to content

Commit 9a1abc2

Browse files
maurizio-lombardikeithbusch
authored andcommitted
nvmet-tcp: Fix the H2C expected PDU len calculation
The nvmet_tcp_handle_h2c_data_pdu() function should take into consideration the possibility that the header digest and/or the data digests are enabled when calculating the expected PDU length, before comparing it to the value stored in cmd->pdu_len. Fixes: efa5630 ("nvmet-tcp: Fix a kernel panic when host sends an invalid H2C PDU length") Signed-off-by: Maurizio Lombardi <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 45c36f0 commit 9a1abc2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/nvme/target/tcp.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
979979
{
980980
struct nvme_tcp_data_pdu *data = &queue->pdu.data;
981981
struct nvmet_tcp_cmd *cmd;
982-
unsigned int plen;
982+
unsigned int exp_data_len;
983983

984984
if (likely(queue->nr_cmds)) {
985985
if (unlikely(data->ttag >= queue->nr_cmds)) {
@@ -999,9 +999,13 @@ static int nvmet_tcp_handle_h2c_data_pdu(struct nvmet_tcp_queue *queue)
999999
goto err_proto;
10001000
}
10011001

1002-
plen = le32_to_cpu(data->hdr.plen);
1002+
exp_data_len = le32_to_cpu(data->hdr.plen) -
1003+
nvmet_tcp_hdgst_len(queue) -
1004+
nvmet_tcp_ddgst_len(queue) -
1005+
sizeof(*data);
1006+
10031007
cmd->pdu_len = le32_to_cpu(data->data_length);
1004-
if (unlikely(cmd->pdu_len != (plen - sizeof(*data)) ||
1008+
if (unlikely(cmd->pdu_len != exp_data_len ||
10051009
cmd->pdu_len == 0 ||
10061010
cmd->pdu_len > NVMET_TCP_MAXH2CDATA)) {
10071011
pr_err("H2CData PDU len %u is invalid\n", cmd->pdu_len);

0 commit comments

Comments
 (0)