slimbus: qcom-ngd: fix NULL pointer dereference in qcom_slim_ngd_xfer_msg()
PATCH 1/1 slimbus: qcom-ngd: fix NULL pointer dereference in qcom_slim_ngd_xfer_msg()
txn->msg is dereferenced without a prior NULL check in qcom_slim_ngd_xfer_msg(), which may lead to a NULL pointer dereference.
Although current callers initialize txn->msg, add a defensive check to prevent potential crashes if a NULL pointer is passed.
Fixes 917809e2280bb ("slimbus: ngd: Add qcom SLIMBus NGD driver")
Signed-off-by Anas Iqbal <[email protected]>
--- drivers/slimbus/qcom-ngd-ctrl.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/slimbus/qcom-ngd-ctrl.c +3 -0
@@ -805,6 +805,9 @@ static int qcom_slim_ngd_xfer_msg(struct slim_controller *sctrl,if (txn->dt ==SLIM_MSG_DEST_ENUMADDR )return -EPROTONOSUPPORT ; +if (!txn->msg) +return -EINVAL ; +if (txn->msg->num_bytes >SLIM_MSGQ_BUF_LEN || txn->rl >SLIM_MSGQ_BUF_LEN ) {dev_err (ctrl->dev,"msg exceeds HW limit\n" );
Signature · 1 line
2.43.0
Quoted 6 lines · Anas Iqbal
txn->msgis dereferenced without a prior NULL check inqcom_slim_ngd_xfer_msg(), which may lead to a NULL pointer dereference.Although current callers initialize
txn->msg, add a defensive check to prevent potential crashes if a NULL pointer is passed.
Defensive coding is generally not appreciated in the kernel.
Quoted 24 lines
Fixes 917809e2280bb ("slimbus: ngd: Add qcom SLIMBus NGD driver")Signed-off-by Anas Iqbal <[email protected]>--- drivers/slimbus/qcom-ngd-ctrl.c | 3 +++ 1 file changed, 3 insertions(+)drivers/slimbus/qcom-ngd-ctrl.c +3
-0@@ -805,6 +805,9 @@ static int qcom_slim_ngd_xfer_msg(struct slim_controller *sctrl,if (txn->dt ==SLIM_MSG_DEST_ENUMADDR )return -EPROTONOSUPPORT ; +if (!txn->msg) +return -EINVAL ; +if (txn->msg->num_bytes >SLIM_MSGQ_BUF_LEN || txn->rl >SLIM_MSGQ_BUF_LEN ) {dev_err (ctrl->dev,"msg exceeds HW limit\n" );Signature · 1 line
2.43.0
Signature · 2 lines
With best wishes Dmitry