From: Wentao_Liang <Wentao_Liang_g@163.com>
To: dongchun.zhu@mediatek.com
Cc: mchehab@kernel.org, linux-media@vger.kernel.org,
linux-kernel@vger.kernel.org,
Wentao_Liang <Wentao_Liang_g@163.com>
Subject: [PATCH] drivers:media:i2c:ov02a10.c: fix a potential use-after-put bug
Date: Thu, 19 Aug 2021 22:12:49 +0800 [thread overview]
Message-ID: <20210819141249.257945-1-Wentao_Liang_g@163.com> (raw)
In line 825 (#1), "fwnode_handle_put(ep);" drops the reference to ep
and may cause ep to be released. However, ep is subsequently used in
lines 831 (#3) by "ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-
voltage", &clk_volt);". This may result in an use-after-put bug.
It can be fixed by removing "fwnode_handle_put(ep);" in line 825 (#1)
and call it respectively before the function returns (line 827, #2) and
after ep has been used again (line 831, #3).
806 static int ov02a10_check_hwcfg(struct device *dev,
struct ov02a10 *ov02a10)
807 {
...
825 fwnode_handle_put(ep); //#1 Memory can be released.
826 if (ret)
827 return ret;
//#2 One of the branch ways ends here.
// Function returns.
...
830 ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage",
831 &clk_volt);
//#3 Use of memory after it may be freed.
...
853 return ret;
854 }
Signed-off-by: Wentao_Liang <Wentao_Liang_g@163.com>
---
drivers/media/i2c/ov02a10.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/media/i2c/ov02a10.c b/drivers/media/i2c/ov02a10.c
index a3ce5500d355..1066a17e9cf8 100644
--- a/drivers/media/i2c/ov02a10.c
+++ b/drivers/media/i2c/ov02a10.c
@@ -822,13 +822,15 @@ static int ov02a10_check_hwcfg(struct device *dev, struct ov02a10 *ov02a10)
return -ENXIO;
ret = v4l2_fwnode_endpoint_alloc_parse(ep, &bus_cfg);
- fwnode_handle_put(ep);
- if (ret)
+ if (ret) {
+ fwnode_handle_put(ep);
return ret;
+ }
/* Optional indication of MIPI clock voltage unit */
ret = fwnode_property_read_u32(ep, "ovti,mipi-clock-voltage",
&clk_volt);
+ fwnode_handle_put(ep);
if (!ret)
ov02a10->mipi_clock_voltage = clk_volt;
--
2.25.1
reply other threads:[~2021-08-19 14:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210819141249.257945-1-Wentao_Liang_g@163.com \
--to=wentao_liang_g@163.com \
--cc=dongchun.zhu@mediatek.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
/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 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.