All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
@ 2026-07-28  6:30 ` Hongling Zeng
  0 siblings, 0 replies; 7+ messages in thread
From: Hongling Zeng @ 2026-07-28  6:30 UTC (permalink / raw)
  To: alexandre.belloni, Frank.Li, amergnat, tze.yee.ng,
	adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel, zhongling0719, Hongling Zeng

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 <zenghongling@kylinos.cn>
---
 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
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
@ 2026-07-28  6:30 ` Hongling Zeng
  0 siblings, 0 replies; 7+ messages in thread
From: Hongling Zeng @ 2026-07-28  6:30 UTC (permalink / raw)
  To: alexandre.belloni, Frank.Li, amergnat, tze.yee.ng,
	adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel, zhongling0719, Hongling Zeng

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 <zenghongling@kylinos.cn>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
  2026-07-28  6:30 ` Hongling Zeng
  (?)
@ 2026-07-28  6:46 ` sashiko-bot
  -1 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-28  6:46 UTC (permalink / raw)
  To: Hongling Zeng; +Cc: linux-i3c, Frank.Li, Alexandre Belloni

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the patch provides an incomplete fix for a theoretical NULL pointer dereference, leaving an identical dereference unhandled on the success path.
--

--- Patch [1]: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked ---
commit e29455a4616608ee623e301c945a087b370f698f
Author: Hongling Zeng <zenghongling@kylinos.cn>

i3c: fix potential NULL dereference in send_ccc_cmd_locked

This patch restricts resetting the payload actual_len to DIRECT commands
to avoid a potential NULL pointer dereference for broadcast commands with
NULL dests and ndests > 0.

> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> --- 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;
>  
>  		cmd->err = I3C_ERROR_UNKNOWN;
>  		ret = master->ops->send_ccc_cmd(master, cmd);
>  		if (!ret && cmd->err == I3C_ERROR_UNKNOWN)
>  			break;
>  	}
>  
>  	if (!ret)
>  		ret = i3c_ccc_validate_payload_len(cmd);

[Severity: Medium]
This is a pre-existing issue, but does this patch leave an identical NULL
pointer dereference unhandled on the success path?

If a broadcast command (where I3C_CCC_DIRECT is not set) with cmd->rnw true
and cmd->dests == NULL succeeds, the retry loop above is now safe. However,
execution proceeds to i3c_ccc_validate_payload_len():

drivers/i3c/master.c:i3c_ccc_validate_payload_len() {
    if (!cmd->rnw)
        return 0;

    for (i = 0; i < cmd->ndests; i++) {
        struct i3c_ccc_cmd_payload *p = &cmd->dests[i].payload;
        ...
}

Will this result in the exact same crash when evaluating
cmd->dests[i].payload?

Also, earlier in i3c_master_send_ccc_cmd_locked():

    if ((cmd->id & I3C_CCC_DIRECT) && (!cmd->dests || !cmd->ndests))
        return -EINVAL;

This early validation check only enforces cmd->dests != NULL for DIRECT
commands. Could this be updated to reject any command where cmd->dests is
NULL but cmd->ndests > 0, rather than patching individual dereferences?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728063045.73473-1-zenghongling@kylinos.cn?part=1

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
  2026-07-28  6:30 ` Hongling Zeng
@ 2026-07-28 10:27   ` Mukesh Savaliya
  -1 siblings, 0 replies; 7+ messages in thread
From: Mukesh Savaliya @ 2026-07-28 10:27 UTC (permalink / raw)
  To: Hongling Zeng, alexandre.belloni, Frank.Li, amergnat, tze.yee.ng,
	adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel, zhongling0719



On 7/28/2026 12:00 PM, Hongling Zeng wrote:
> 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 <zenghongling@kylinos.cn>
> ---
>   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))

Please review this recent fix @
https://lore.kernel.org/all/amJau9LgehYLnR20@lizhi-Precision-Tower-5810/

>   			for (i = 0; i < cmd->ndests; i++)
>   				cmd->dests[i].payload.actual_len = 0;
>   


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
@ 2026-07-28 10:27   ` Mukesh Savaliya
  0 siblings, 0 replies; 7+ messages in thread
From: Mukesh Savaliya @ 2026-07-28 10:27 UTC (permalink / raw)
  To: Hongling Zeng, alexandre.belloni, Frank.Li, amergnat, tze.yee.ng,
	adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel, zhongling0719



On 7/28/2026 12:00 PM, Hongling Zeng wrote:
> 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 <zenghongling@kylinos.cn>
> ---
>   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))

Please review this recent fix @
https://lore.kernel.org/all/amJau9LgehYLnR20@lizhi-Precision-Tower-5810/

>   			for (i = 0; i < cmd->ndests; i++)
>   				cmd->dests[i].payload.actual_len = 0;
>   


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
  2026-07-28 10:27   ` Mukesh Savaliya
@ 2026-07-30  2:31     ` Hongling Zeng
  -1 siblings, 0 replies; 7+ messages in thread
From: Hongling Zeng @ 2026-07-30  2:31 UTC (permalink / raw)
  To: Mukesh Savaliya, Hongling Zeng, alexandre.belloni, Frank.Li,
	amergnat, tze.yee.ng, adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel


在 2026年07月28日 18:27, Mukesh Savaliya 写道:
>
>
> On 7/28/2026 12:00 PM, Hongling Zeng wrote:
>> 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 <zenghongling@kylinos.cn>
>> ---
>>   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))
>
> Please review this recent fix @
> https://lore.kernel.org/all/amJau9LgehYLnR20@lizhi-Precision-Tower-5810/
>
|

|Thanks, Adrian's fix makes more sense by validating the input at the
entry point rather than fixing only the retry loop use site.|

|
>>               for (i = 0; i < cmd->ndests; i++)
>>                   cmd->dests[i].payload.actual_len = 0;


-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked
@ 2026-07-30  2:31     ` Hongling Zeng
  0 siblings, 0 replies; 7+ messages in thread
From: Hongling Zeng @ 2026-07-30  2:31 UTC (permalink / raw)
  To: Mukesh Savaliya, Hongling Zeng, alexandre.belloni, Frank.Li,
	amergnat, tze.yee.ng, adrian.ho.yin.ng
  Cc: linux-i3c, linux-kernel


在 2026年07月28日 18:27, Mukesh Savaliya 写道:
>
>
> On 7/28/2026 12:00 PM, Hongling Zeng wrote:
>> 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 <zenghongling@kylinos.cn>
>> ---
>>   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))
>
> Please review this recent fix @
> https://lore.kernel.org/all/amJau9LgehYLnR20@lizhi-Precision-Tower-5810/
>
|

|Thanks, Adrian's fix makes more sense by validating the input at the
entry point rather than fixing only the retry loop use site.|

|
>>               for (i = 0; i < cmd->ndests; i++)
>>                   cmd->dests[i].payload.actual_len = 0;


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-30  2:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28  6:30 [PATCH] i3c: fix potential NULL dereference in send_ccc_cmd_locked Hongling Zeng
2026-07-28  6:30 ` Hongling Zeng
2026-07-28  6:46 ` sashiko-bot
2026-07-28 10:27 ` Mukesh Savaliya
2026-07-28 10:27   ` Mukesh Savaliya
2026-07-30  2:31   ` Hongling Zeng
2026-07-30  2:31     ` Hongling Zeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.