From: Chenyuan Yang <chenyuan0y@gmail.com>
To: ming.qian@nxp.com, eagle.zhou@nxp.com, mchehab@kernel.org,
shijie.qin@nxp.com, hverkuil@xs4all.nl
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
Chenyuan Yang <chenyuan0y@gmail.com>
Subject: [PATCH] media: amphion: fix potential NULL deref in vpu_core_parse_dt()
Date: Fri, 11 Apr 2025 13:43:56 -0500 [thread overview]
Message-ID: <20250411184356.2910366-1-chenyuan0y@gmail.com> (raw)
The result of memremap() may be NULL on failure, leading to a null
dereference in the subsequent memset(). Add explicit checks after
each memremap() call: if the firmware region fails to map, return
immediately; if the RPC region fails, unmap the firmware window before
returning.
This is similar to the commit 966d47e1f27c
("efi: fix potential NULL deref in efi_mem_reserve_persistent").
This is found by our static analysis tool KNighter.
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Fixes: 9f599f351e86 ("media: amphion: add vpu core driver")
---
drivers/media/platform/amphion/vpu_core.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
index 8df85c14ab3f..26568987586d 100644
--- a/drivers/media/platform/amphion/vpu_core.c
+++ b/drivers/media/platform/amphion/vpu_core.c
@@ -586,7 +586,18 @@ static int vpu_core_parse_dt(struct vpu_core *core, struct device_node *np)
}
core->fw.virt = memremap(core->fw.phys, core->fw.length, MEMREMAP_WC);
+ if (!core->fw.virt) {
+ dev_err(core->dev, "failed to remap fw region\n");
+ of_node_put(node);
+ return -ENOMEM;
+ }
core->rpc.virt = memremap(core->rpc.phys, core->rpc.length, MEMREMAP_WC);
+ if (!core->rpc.virt) {
+ dev_err(core->dev, "failed to remap rpc region\n");
+ memunmap(core->fw.virt);
+ of_node_put(node);
+ return -ENOMEM;
+ }
memset(core->rpc.virt, 0, core->rpc.length);
ret = vpu_iface_check_memory_region(core, core->rpc.phys, core->rpc.length);
--
2.34.1
next reply other threads:[~2025-04-11 18:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 18:43 Chenyuan Yang [this message]
2025-04-11 21:20 ` [PATCH] media: amphion: fix potential NULL deref in vpu_core_parse_dt() Nicolas Dufresne
2025-04-22 21:13 ` Nicolas Dufresne
2025-04-23 7:19 ` [EXT] " Ming Qian
2025-04-12 15:15 ` Markus Elfring
2025-04-22 21:16 ` Nicolas Dufresne
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=20250411184356.2910366-1-chenyuan0y@gmail.com \
--to=chenyuan0y@gmail.com \
--cc=eagle.zhou@nxp.com \
--cc=hverkuil@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=ming.qian@nxp.com \
--cc=shijie.qin@nxp.com \
/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