* [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference in ucc_of_parse_tdm @ 2018-11-21 7:41 Wen Yang 2018-11-21 10:45 ` Christophe LEROY 0 siblings, 1 reply; 3+ messages in thread From: Wen Yang @ 2018-11-21 7:41 UTC (permalink / raw) To: qiang.zhao Cc: wang.yi59, zhong.weidong, linux-kernel, leoyang.li, Julia Lawall, linuxppc-dev, wen.yang99, linux-arm-kernel This patch fixes a possible null pointer dereference in ucc_of_parse_tdm, detected by the semantic patch deref_null.cocci, with the following warning: ./drivers/soc/fsl/qe/qe_tdm.c:177:21-24: ERROR: pdev is NULL but dereferenced. The following code has potential null pointer references: pdev = of_find_device_by_node(np2); if (!pdev) { ret = -EINVAL; pr_err("%pOFn: failed to lookup pdev\n", np2); of_node_put(np2); goto err_miss_siram_property; } ... err_miss_siram_property: devm_iounmap(&pdev->dev, utdm->si_regs); Signed-off-by: Wen Yang <wen.yang99@zte.com.cn> Reviewed-by: Tan Hu <tan.hu@zte.com.cn> CC: Julia Lawall <julia.lawall@lip6.fr> --- drivers/soc/fsl/qe/qe_tdm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c index f78c346..166378b 100644 --- a/drivers/soc/fsl/qe/qe_tdm.c +++ b/drivers/soc/fsl/qe/qe_tdm.c @@ -174,7 +174,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, return ret; err_miss_siram_property: - devm_iounmap(&pdev->dev, utdm->si_regs); + if (pdev) + devm_iounmap(&pdev->dev, utdm->si_regs); return ret; } EXPORT_SYMBOL(ucc_of_parse_tdm); -- 2.9.5 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference in ucc_of_parse_tdm 2018-11-21 7:41 [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference in ucc_of_parse_tdm Wen Yang @ 2018-11-21 10:45 ` Christophe LEROY 2018-11-22 2:41 ` 答复: Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference inucc_of_parse_tdm wen.yang99 0 siblings, 1 reply; 3+ messages in thread From: Christophe LEROY @ 2018-11-21 10:45 UTC (permalink / raw) To: Wen Yang, qiang.zhao Cc: wang.yi59, zhong.weidong, linux-kernel, leoyang.li, Julia Lawall, linuxppc-dev, linux-arm-kernel Le 21/11/2018 à 08:41, Wen Yang a écrit : > This patch fixes a possible null pointer dereference in > ucc_of_parse_tdm, detected by the semantic patch > deref_null.cocci, with the following warning: > > ./drivers/soc/fsl/qe/qe_tdm.c:177:21-24: ERROR: pdev is NULL but dereferenced. > > The following code has potential null pointer references: > pdev = of_find_device_by_node(np2); > if (!pdev) { > ret = -EINVAL; > pr_err("%pOFn: failed to lookup pdev\n", np2); > of_node_put(np2); > goto err_miss_siram_property; > } > ... > err_miss_siram_property: > devm_iounmap(&pdev->dev, utdm->si_regs); > > Signed-off-by: Wen Yang <wen.yang99@zte.com.cn> > Reviewed-by: Tan Hu <tan.hu@zte.com.cn> > CC: Julia Lawall <julia.lawall@lip6.fr> > --- > drivers/soc/fsl/qe/qe_tdm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c > index f78c346..166378b 100644 > --- a/drivers/soc/fsl/qe/qe_tdm.c > +++ b/drivers/soc/fsl/qe/qe_tdm.c > @@ -174,7 +174,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, > return ret; > > err_miss_siram_property: > - devm_iounmap(&pdev->dev, utdm->si_regs); > + if (pdev) > + devm_iounmap(&pdev->dev, utdm->si_regs); You are just hiding the issue, not fixing it. The problem is that pdev gets modified, so in any case that devm_iounmap() will fail even when the new pdev is valid, because the iomap was done with a different pdev. Christophe > return ret; > } > EXPORT_SYMBOL(ucc_of_parse_tdm); > ^ permalink raw reply [flat|nested] 3+ messages in thread
* 答复: Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference inucc_of_parse_tdm 2018-11-21 10:45 ` Christophe LEROY @ 2018-11-22 2:41 ` wen.yang99 0 siblings, 0 replies; 3+ messages in thread From: wen.yang99 @ 2018-11-22 2:41 UTC (permalink / raw) To: christophe.leroy, qiang.zhao Cc: wang.yi59, zhong.weidong, linux-kernel, leoyang.li, julia.lawall, linuxppc-dev, linux-arm-kernel, qiang.zhao [-- Attachment #1.1: Type: text/plain, Size: 3502 bytes --] Hi Christophe, thank you for your review. There are two problems in the ucc_of_parse_tdm function. 1, NULL pointer reference 2, pdev gets modified, iomap was done with a different pdev. We will submit a patch to repair it later. Thanks. 132 pdev = of_find_device_by_node(np2); ...... 141 utdm->si_regs = devm_ioremap_resource(&pdev->dev, res); ---> use pdev to call devm_ioremap ...... 153 pdev = of_find_device_by_node(np2); --->This line, pdev gets modified 154 if (!pdev) { 155 ret = -EINVAL; 156 pr_err("%pOFn: failed to lookup pdev\n", np2); 157 of_node_put(np2); 158 goto err_miss_siram_property; ------> This line, if pdev is NULL, will jump to label err_miss_siram_property 159 } ...... 163 utdm->siram = devm_ioremap_resource(&pdev->dev, res); --> use changed pdev to call devm_ioremap ...... 175 176 err_miss_siram_property: 177 devm_iounmap(&pdev->dev, utdm->si_regs); ------> Within the code block, if pdev is NULL, kernel panic will be triggered; devm_iounmap() will alse fail even when the new pdev is valid. 178 return ret; 179 } ------------------原始邮件------------------ 发件人:ChristopheLEROY <christophe.leroy@c-s.fr> 收件人:文洋10156314;qiang.zhao@nxp.com <qiang.zhao@nxp.com> 抄送人:汪翼10129963;钟卫东10001088;linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>leoyang.li@nxp.com <leoyang.li@nxp.com>Julia Lawall <julia.lawall@lip6.fr>linuxppc-dev@lists.ozlabs.org <linuxppc-dev@lists.ozlabs.org>linux-arm-kernel@lists.infradead.org <linux-arm-kernel@lists.infradead.org> 日 期 :2018年11月21日 18:46 主 题 :Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference inucc_of_parse_tdm Le 21/11/2018 à 08:41, Wen Yang a écrit : > This patch fixes a possible null pointer dereference in > ucc_of_parse_tdm, detected by the semantic patch > deref_null.cocci, with the following warning: > > ./drivers/soc/fsl/qe/qe_tdm.c:177:21-24: ERROR: pdev is NULL but dereferenced. > > The following code has potential null pointer references: > pdev = of_find_device_by_node(np2); > if (!pdev) { > ret = -EINVAL; > pr_err("%pOFn: failed to lookup pdev\n", np2); > of_node_put(np2); > goto err_miss_siram_property; > } > ... > err_miss_siram_property: > devm_iounmap(&pdev->dev, utdm->si_regs); > > Signed-off-by: Wen Yang <wen.yang99@zte.com.cn> > Reviewed-by: Tan Hu <tan.hu@zte.com.cn> > CC: Julia Lawall <julia.lawall@lip6.fr> > --- > drivers/soc/fsl/qe/qe_tdm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c > index f78c346..166378b 100644 > --- a/drivers/soc/fsl/qe/qe_tdm.c > +++ b/drivers/soc/fsl/qe/qe_tdm.c > @@ -174,7 +174,8 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm, > return ret; > > err_miss_siram_property: > - devm_iounmap(&pdev->dev, utdm->si_regs); > + if (pdev) > + devm_iounmap(&pdev->dev, utdm->si_regs); You are just hiding the issue, not fixing it. The problem is that pdev gets modified, so in any case that devm_iounmap() will fail even when the new pdev is valid, because the iomap was done with a different pdev. Christophe > return ret; > } > EXPORT_SYMBOL(ucc_of_parse_tdm); > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-22 2:59 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-11-21 7:41 [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference in ucc_of_parse_tdm Wen Yang 2018-11-21 10:45 ` Christophe LEROY 2018-11-22 2:41 ` 答复: Re: [PATCH 2/4] soc/fsl/qe: fix potential NULL pointer dereference inucc_of_parse_tdm wen.yang99
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).