Skip to content

Commit 47d87f7

Browse files
Dan Carpenterquic-jhugo
authored andcommitted
accel/qaic: Add consistent integer overflow checks
The encode_dma() function has integer overflow checks. The encode_passthrough(), encode_activate() and encode_status() functions did not. I added integer overflow checking everywhere. I also updated the integer overflow checking in encode_dma() to use size_add() so everything is consistent. Fixes: 129776a ("accel/qaic: Add control path") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Pranjal Ramajor Asha Kanojiya <quic_pkanojiy@quicinc.com> Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Cc: stable@vger.kernel.org # 6.4.x [jhugo: tweak if in encode_dma() to match existing style] Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com> Link: https://patchwork.freedesktop.org/patch/msgid/ZK0Q7IsPkj6WSCcL@moroto
1 parent 51b5638 commit 47d87f7

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

drivers/accel/qaic/qaic_control.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int encode_passthrough(struct qaic_device *qdev, void *trans, struct wrap
367367
if (in_trans->hdr.len % 8 != 0)
368368
return -EINVAL;
369369

370-
if (msg_hdr_len + in_trans->hdr.len > QAIC_MANAGE_EXT_MSG_LENGTH)
370+
if (size_add(msg_hdr_len, in_trans->hdr.len) > QAIC_MANAGE_EXT_MSG_LENGTH)
371371
return -ENOSPC;
372372

373373
trans_wrapper = add_wrapper(wrappers,
@@ -558,11 +558,8 @@ static int encode_dma(struct qaic_device *qdev, void *trans, struct wrapper_list
558558
msg = &wrapper->msg;
559559
msg_hdr_len = le32_to_cpu(msg->hdr.len);
560560

561-
if (msg_hdr_len > (UINT_MAX - QAIC_MANAGE_EXT_MSG_LENGTH))
562-
return -EINVAL;
563-
564561
/* There should be enough space to hold at least one ASP entry. */
565-
if (msg_hdr_len + sizeof(*out_trans) + sizeof(struct wire_addr_size_pair) >
562+
if (size_add(msg_hdr_len, sizeof(*out_trans) + sizeof(struct wire_addr_size_pair)) >
566563
QAIC_MANAGE_EXT_MSG_LENGTH)
567564
return -ENOMEM;
568565

@@ -635,7 +632,7 @@ static int encode_activate(struct qaic_device *qdev, void *trans, struct wrapper
635632
msg = &wrapper->msg;
636633
msg_hdr_len = le32_to_cpu(msg->hdr.len);
637634

638-
if (msg_hdr_len + sizeof(*out_trans) > QAIC_MANAGE_MAX_MSG_LENGTH)
635+
if (size_add(msg_hdr_len, sizeof(*out_trans)) > QAIC_MANAGE_MAX_MSG_LENGTH)
639636
return -ENOSPC;
640637

641638
if (!in_trans->queue_size)
@@ -719,7 +716,7 @@ static int encode_status(struct qaic_device *qdev, void *trans, struct wrapper_l
719716
msg = &wrapper->msg;
720717
msg_hdr_len = le32_to_cpu(msg->hdr.len);
721718

722-
if (msg_hdr_len + in_trans->hdr.len > QAIC_MANAGE_MAX_MSG_LENGTH)
719+
if (size_add(msg_hdr_len, in_trans->hdr.len) > QAIC_MANAGE_MAX_MSG_LENGTH)
723720
return -ENOSPC;
724721

725722
trans_wrapper = add_wrapper(wrappers, sizeof(*trans_wrapper));

0 commit comments

Comments
 (0)