[PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked

Hongling Zeng <[email protected]> Tue, 28 Jul 2026 14:30:45 +0800
Newsgroups org.infradead.lists.linux-i3c,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
The retry loop added in commit 02cc832191dd ("i3c: master: Validate GET
 CCC payload length and retry Direct GET once") resets payload actual_len
before each attempt. However, cmd->dests is only validated for DIRECT
CCC commands (I3C_CCC_DIRECT bit set). For broadcast commands, dests
can be NULL while ndests > 0, causing a NULL pointer dereference at
cmd->dests[i].payload.actual_len.

Fix by restricting the actual_len reset to DIRECT commands.

Fixes: 02cc832191dd ("i3c: master: Validate GET CCC payload length and retry Direct GET once")
Signed-off-by: Hongling Zeng <[email protected]>
---
 drivers/i3c/master.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index fd3e79d10c84..21212c34c31e 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -1051,7 +1051,7 @@ static int i3c_master_send_ccc_cmd_locked(struct i3c_master_controller *master,
 	for (attempt = 0; attempt < max_attempts; attempt++) {
 		unsigned int i;
 
-		if (cmd->rnw)
+		if (cmd->rnw && (cmd->id & I3C_CCC_DIRECT))
 			for (i = 0; i < cmd->ndests; i++)
 				cmd->dests[i].payload.actual_len = 0;
 
-- 
2.25.1


-- 
linux-i3c mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-i3c