dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hongling Zeng" <zenghongling@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd()
Date: Mon, 22 Jun 2026 02:28:37 +0000	[thread overview]
Message-ID: <20260622022838.028621F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260622021207.14764-6-zenghongling@kylinos.cn>

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

Pre-existing issues:
- [High] A malformed GSP message size causes r535_gsp_msgq_recv() to return NULL, which propagates through nvkm_gsp_rpc_rd() and leads to a NULL pointer dereference in its callers.
--

commit 604de241374540fdccd3d8af5fec3fe8ff826d71
Author: Hongling Zeng <zenghongling@kylinos.cn>

    nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd()

    This commit cleans up nvkm_gsp_rpc_rd() by replacing IS_ERR_OR_NULL()
    with IS_ERR(). The commit message notes that nvkm_gsp_rpc_push() expects
    a reply under the RECV policy and should return an error pointer rather
    than NULL if the RPC fails.

> diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> index 64fed208e4cf8..a061779e0107b 100644
> --- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> +++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/gsp.h
> @@ -293,7 +293,7 @@ nvkm_gsp_rpc_rd(struct nvkm_gsp *gsp, u32 fn, u32 argc)
>  {
>  	void *argv = nvkm_gsp_rpc_get(gsp, fn, argc);
>  
> -	if (IS_ERR_OR_NULL(argv))
> +	if (IS_ERR(argv))
>  		return argv;
>  
>  	return nvkm_gsp_rpc_push(gsp, argv, NVKM_GSP_RPC_REPLY_RECV, argc);

[Severity: High]
This is a pre-existing issue, but does nvkm_gsp_rpc_push() strictly return
an error pointer instead of NULL on failure under the RECV policy?

If the GSP firmware returns an RPC message with an invalid length,
r535_gsp_msgq_recv() triggers a WARN_ON and returns NULL:

r535_gsp_msgq_recv() in drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/rpc.c:

	...
	if (WARN_ON(rpc->length > max_rpc_size))
		return NULL;
	...

This NULL propagates up through r535_gsp_msg_recv() and
r535_gsp_rpc_handle_reply() to nvkm_gsp_rpc_push(), which is then returned
directly by nvkm_gsp_rpc_rd() here.

Since callers like r535_gsp_get_static_info() only check IS_ERR(), could this
lead to a NULL pointer dereference?

r535_gsp_get_static_info() in drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/gsp.c:

	...
	rpc = nvkm_gsp_rpc_rd(gsp, NV_VGPU_MSG_FUNCTION_GET_GSP_STATIC_INFO, sizeof(*rpc));
	if (IS_ERR(rpc))
		return PTR_ERR(rpc);

	gsp->internal.client.object.client = &gsp->internal.client;
	gsp->internal.client.object.parent = NULL;
	gsp->internal.client.object.handle = rpc->hInternalClient;
	...

Similarly, does r535_gsp_rpc_rm_ctrl_push() mishandle this NULL?

r535_gsp_rpc_rm_ctrl_push() in drivers/gpu/drm/nouveau/nvkm/subdev/gsp/rm/r535/ctrl.c:

	...
	repv = nvkm_gsp_rpc_push(gsp, rpc, repc ? NVKM_GSP_RPC_REPLY_RECV :
					   NVKM_GSP_RPC_REPLY_NOWAIT, repc);
	if (IS_ERR_OR_NULL(repv)) {
		*params = NULL;
		return PTR_ERR(repv);
	}
	...

If nvkm_gsp_rpc_push() returns NULL, PTR_ERR(repv) evaluates to 0 (success),
which causes it to return success while passing a NULL pointer back to callers
like r535_gsp_intr_get_table().

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

  reply	other threads:[~2026-06-22  2:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-22  2:12 [PATCH v3 0/5] nouveau/gsp: Clean up IS_ERR vs IS_ERR_OR_NULL usage Hongling Zeng
2026-06-22  2:12 ` [PATCH v3 1/5] nouveau/gsp/rpc: Document RPC function return value contracts Hongling Zeng
2026-06-22  2:26   ` sashiko-bot
2026-06-22  2:12 ` [PATCH v3 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c Hongling Zeng
2026-06-22  2:27   ` sashiko-bot
2026-06-22  2:12 ` [PATCH v3 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage Hongling Zeng
2026-06-22  4:28   ` sashiko-bot
2026-06-22  2:12 ` [PATCH v3 4/5] nouveau/gsp/rm/bar: " Hongling Zeng
2026-06-22  2:27   ` sashiko-bot
2026-06-22  2:12 ` [PATCH v3 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() Hongling Zeng
2026-06-22  2:28   ` sashiko-bot [this message]
     [not found] ` <1782119054239712.17995.seg@mailgw.kylinos.cn>
2026-06-22  9:20   ` [PATCH v3 1/5] nouveau/gsp/rpc: Document RPC function return value contracts sashiko-bot
     [not found] ` <1782119054238429.17993.seg@mailgw.kylinos.cn>
2026-06-22  9:33   ` [PATCH v3 2/5] nouveau/gsp/rpc: Cleanup incorrect IS_ERR_OR_NULL in rpc.c sashiko-bot
     [not found] ` <1782119054236227.17989.seg@mailgw.kylinos.cn>
2026-06-22  9:47   ` [PATCH v3 3/5] nouveau/gsp/rm/alloc: Cleanup IS_ERR_OR_NULL usage sashiko-bot
     [not found] ` <1782119054234413.17986.seg@mailgw.kylinos.cn>
2026-06-22 12:09   ` [PATCH v3 5/5] nouveau/gsp: Cleanup IS_ERR_OR_NULL in nvkm_gsp_rpc_rd() sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260622022838.028621F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zenghongling@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox