* [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference
@ 2025-01-20 19:07 Chenyuan Yang
2025-01-27 16:30 ` Chenyuan Yang
2025-02-10 17:33 ` Lee Jones
0 siblings, 2 replies; 9+ messages in thread
From: Chenyuan Yang @ 2025-01-20 19:07 UTC (permalink / raw)
To: lee, lkundrak; +Cc: linux-kernel, zijie98, Chenyuan Yang
The off_gpios could be NULL. Add missing check in the kb3930_probe().
This is similar to the issue fixed in commit
b1ba8bcb2d1ffce11b308ce166c9cc28d989e3b9 ("backlight: hx8357:Fix potential NULL pointer dereference").
Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller")
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
---
drivers/mfd/ene-kb3930.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c
index fa0ad2f14a39..60824d847bf0 100644
--- a/drivers/mfd/ene-kb3930.c
+++ b/drivers/mfd/ene-kb3930.c
@@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client)
devm_gpiod_get_array_optional(dev, "off", GPIOD_IN);
if (IS_ERR(ddata->off_gpios))
return PTR_ERR(ddata->off_gpios);
+ if (!ddata->off_gpios)
+ return -ENOMEM;
if (ddata->off_gpios->ndescs < 2) {
dev_err(dev, "invalid off-gpios property\n");
return -EINVAL;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-01-20 19:07 [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference Chenyuan Yang @ 2025-01-27 16:30 ` Chenyuan Yang 2025-01-27 17:43 ` Krzysztof Kozlowski 2025-02-10 17:33 ` Lee Jones 1 sibling, 1 reply; 9+ messages in thread From: Chenyuan Yang @ 2025-01-27 16:30 UTC (permalink / raw) To: lee, lkundrak; +Cc: linux-kernel, zijie98 Dear Developers, I am writing to check if there has been any update on this issue. Given that it involves a potential null pointer dereference, I believe we should address it as soon as possible Best, Chenyuan On Mon, Jan 20, 2025 at 1:07 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote: > > The off_gpios could be NULL. Add missing check in the kb3930_probe(). > This is similar to the issue fixed in commit > b1ba8bcb2d1ffce11b308ce166c9cc28d989e3b9 ("backlight: hx8357:Fix potential NULL pointer dereference"). > > Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller") > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com> > --- > drivers/mfd/ene-kb3930.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > index fa0ad2f14a39..60824d847bf0 100644 > --- a/drivers/mfd/ene-kb3930.c > +++ b/drivers/mfd/ene-kb3930.c > @@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client) > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > if (IS_ERR(ddata->off_gpios)) > return PTR_ERR(ddata->off_gpios); > + if (!ddata->off_gpios) > + return -ENOMEM; > if (ddata->off_gpios->ndescs < 2) { > dev_err(dev, "invalid off-gpios property\n"); > return -EINVAL; > -- > 2.34.1 > ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-01-27 16:30 ` Chenyuan Yang @ 2025-01-27 17:43 ` Krzysztof Kozlowski 2025-01-27 19:45 ` Chenyuan Yang 0 siblings, 1 reply; 9+ messages in thread From: Krzysztof Kozlowski @ 2025-01-27 17:43 UTC (permalink / raw) To: Chenyuan Yang, lee, lkundrak; +Cc: linux-kernel, zijie98 On 27/01/2025 17:30, Chenyuan Yang wrote: > Dear Developers, > > I am writing to check if there has been any update on this issue. > Given that it involves a potential null pointer dereference, I believe > we should address it as soon as possible > How did you test it or reproduce the issue? You claim that it is ASAP and ping during the merge window, so I assume this is real issue and tested on device? Best regards, Krzysztof ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-01-27 17:43 ` Krzysztof Kozlowski @ 2025-01-27 19:45 ` Chenyuan Yang 2025-01-28 7:10 ` Krzysztof Kozlowski 0 siblings, 1 reply; 9+ messages in thread From: Chenyuan Yang @ 2025-01-27 19:45 UTC (permalink / raw) To: Krzysztof Kozlowski; +Cc: lee, lkundrak, linux-kernel, zijie98 Hi Krzysztof, This was caught by our static analysis tool because devm_gpiod_get_array_optional() can return a NULL pointer in low-memory situations. It's essentially the same scenario described here: https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/. Best, Chenyuan On Mon, Jan 27, 2025 at 11:43 AM Krzysztof Kozlowski <krzk@kernel.org> wrote: > > On 27/01/2025 17:30, Chenyuan Yang wrote: > > Dear Developers, > > > > I am writing to check if there has been any update on this issue. > > Given that it involves a potential null pointer dereference, I believe > > we should address it as soon as possible > > > How did you test it or reproduce the issue? You claim that it is ASAP > and ping during the merge window, so I assume this is real issue and > tested on device? > > Best regards, > Krzysztof ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-01-27 19:45 ` Chenyuan Yang @ 2025-01-28 7:10 ` Krzysztof Kozlowski 0 siblings, 0 replies; 9+ messages in thread From: Krzysztof Kozlowski @ 2025-01-28 7:10 UTC (permalink / raw) To: Chenyuan Yang; +Cc: lee, lkundrak, linux-kernel, zijie98 On 27/01/2025 20:45, Chenyuan Yang wrote: > Hi Krzysztof, > > This was caught by our static analysis tool because > devm_gpiod_get_array_optional() can return a NULL pointer in > low-memory situations. It's essentially the same scenario described Don't top post. So you did not reproduce it, did not test it, thus I suggest not to ping us as we missed anything. Try to get this tested first. Best regards, Krzysztof ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-01-20 19:07 [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference Chenyuan Yang 2025-01-27 16:30 ` Chenyuan Yang @ 2025-02-10 17:33 ` Lee Jones 2025-02-10 23:47 ` Chenyuan Yang 1 sibling, 1 reply; 9+ messages in thread From: Lee Jones @ 2025-02-10 17:33 UTC (permalink / raw) To: Chenyuan Yang; +Cc: lkundrak, linux-kernel, zijie98 On Mon, 20 Jan 2025, Chenyuan Yang wrote: > The off_gpios could be NULL. Add missing check in the kb3930_probe(). > This is similar to the issue fixed in commit > b1ba8bcb2d1ffce11b308ce166c9cc28d989e3b9 ("backlight: hx8357:Fix potential NULL pointer dereference"). > > Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller") > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com> > --- > drivers/mfd/ene-kb3930.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > index fa0ad2f14a39..60824d847bf0 100644 > --- a/drivers/mfd/ene-kb3930.c > +++ b/drivers/mfd/ene-kb3930.c > @@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client) > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > if (IS_ERR(ddata->off_gpios)) > return PTR_ERR(ddata->off_gpios); > + if (!ddata->off_gpios) > + return -ENOMEM; I don't see many other call sites checking for NULL - why is this different? What about IS_ERR_OR_NULL() instead? > if (ddata->off_gpios->ndescs < 2) { > dev_err(dev, "invalid off-gpios property\n"); > return -EINVAL; > -- > 2.34.1 > -- Lee Jones [李琼斯] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-02-10 17:33 ` Lee Jones @ 2025-02-10 23:47 ` Chenyuan Yang 2025-02-11 15:06 ` Lee Jones 0 siblings, 1 reply; 9+ messages in thread From: Chenyuan Yang @ 2025-02-10 23:47 UTC (permalink / raw) To: Lee Jones; +Cc: lkundrak, linux-kernel, zijie98 On Mon, Feb 10, 2025 at 11:34 AM Lee Jones <lee@kernel.org> wrote: > > On Mon, 20 Jan 2025, Chenyuan Yang wrote: > > > The off_gpios could be NULL. Add missing check in the kb3930_probe(). > > This is similar to the issue fixed in commit > > https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/> > > > Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller") > > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com> > > --- > > drivers/mfd/ene-kb3930.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > > index fa0ad2f14a39..60824d847bf0 100644 > > --- a/drivers/mfd/ene-kb3930.c > > +++ b/drivers/mfd/ene-kb3930.c > > @@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client) > > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > > if (IS_ERR(ddata->off_gpios)) > > return PTR_ERR(ddata->off_gpios); > > + if (!ddata->off_gpios) > > + return -ENOMEM; > > I don't see many other call sites checking for NULL - why is this > different? It looks like other places using devm_gpiod_get_array_optional do check for a NULL return value, such as in drivers/iio/resolver/ad2s1210.c, drivers/mtd/maps/physmap-core.c, and this patch commit: https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/. > What about IS_ERR_OR_NULL() instead? Yes, that sounds good. However, I have a question—what error number should be returned in this case? > > if (ddata->off_gpios->ndescs < 2) { > > dev_err(dev, "invalid off-gpios property\n"); > > return -EINVAL; > > -- > > 2.34.1 > > > > -- > Lee Jones [李琼斯] -Chenyuan ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-02-10 23:47 ` Chenyuan Yang @ 2025-02-11 15:06 ` Lee Jones 2025-02-13 2:14 ` Chenyuan Yang 0 siblings, 1 reply; 9+ messages in thread From: Lee Jones @ 2025-02-11 15:06 UTC (permalink / raw) To: Chenyuan Yang; +Cc: lkundrak, linux-kernel, zijie98 On Mon, 10 Feb 2025, Chenyuan Yang wrote: > On Mon, Feb 10, 2025 at 11:34 AM Lee Jones <lee@kernel.org> wrote: > > > > On Mon, 20 Jan 2025, Chenyuan Yang wrote: > > > > > The off_gpios could be NULL. Add missing check in the kb3930_probe(). > > > This is similar to the issue fixed in commit > > > https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/> > > > > Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller") > > > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com> > > > --- > > > drivers/mfd/ene-kb3930.c | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > > > index fa0ad2f14a39..60824d847bf0 100644 > > > --- a/drivers/mfd/ene-kb3930.c > > > +++ b/drivers/mfd/ene-kb3930.c > > > @@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client) > > > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > > > if (IS_ERR(ddata->off_gpios)) > > > return PTR_ERR(ddata->off_gpios); > > > + if (!ddata->off_gpios) > > > + return -ENOMEM; > > > > I don't see many other call sites checking for NULL - why is this > > different? > > It looks like other places using devm_gpiod_get_array_optional do > check for a NULL return value, such as in > drivers/iio/resolver/ad2s1210.c, drivers/mtd/maps/physmap-core.c, and > this patch commit: > https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/. > > > What about IS_ERR_OR_NULL() instead? > > Yes, that sounds good. However, I have a question—what error number > should be returned in this case? I just took a closer look and don't thing returning on NULL is correct. The call is *_optional() meaning that NULL is an acceptable value. I believe that this is the correct solution: diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c index fa0ad2f14a39..9460a67acb0b 100644 --- a/drivers/mfd/ene-kb3930.c +++ b/drivers/mfd/ene-kb3930.c @@ -162,7 +162,7 @@ static int kb3930_probe(struct i2c_client *client) devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); if (IS_ERR(ddata->off_gpios)) return PTR_ERR(ddata->off_gpios); - if (ddata->off_gpios->ndescs < 2) { + if (ddata->off_gpios && ddata->off_gpios->ndescs < 2) { dev_err(dev, "invalid off-gpios property\n"); return -EINVAL; } -- Lee Jones [李琼斯] ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference 2025-02-11 15:06 ` Lee Jones @ 2025-02-13 2:14 ` Chenyuan Yang 0 siblings, 0 replies; 9+ messages in thread From: Chenyuan Yang @ 2025-02-13 2:14 UTC (permalink / raw) To: Lee Jones; +Cc: lkundrak, linux-kernel, zijie98 Thanks so much for your insights! I will resubmit the patch. -Chenyuan On Tue, Feb 11, 2025 at 9:06 AM Lee Jones <lee@kernel.org> wrote: > > On Mon, 10 Feb 2025, Chenyuan Yang wrote: > > > On Mon, Feb 10, 2025 at 11:34 AM Lee Jones <lee@kernel.org> wrote: > > > > > > On Mon, 20 Jan 2025, Chenyuan Yang wrote: > > > > > > > The off_gpios could be NULL. Add missing check in the kb3930_probe(). > > > > This is similar to the issue fixed in commit > > > > https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/> > > > > > Fixes: ede6b2d1dfc0 ("mfd: ene-kb3930: Add driver for ENE KB3930 Embedded Controller") > > > > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com> > > > > --- > > > > drivers/mfd/ene-kb3930.c | 2 ++ > > > > 1 file changed, 2 insertions(+) > > > > > > > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > > > > index fa0ad2f14a39..60824d847bf0 100644 > > > > --- a/drivers/mfd/ene-kb3930.c > > > > +++ b/drivers/mfd/ene-kb3930.c > > > > @@ -162,6 +162,8 @@ static int kb3930_probe(struct i2c_client *client) > > > > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > > > > if (IS_ERR(ddata->off_gpios)) > > > > return PTR_ERR(ddata->off_gpios); > > > > + if (!ddata->off_gpios) > > > > + return -ENOMEM; > > > > > > I don't see many other call sites checking for NULL - why is this > > > different? > > > > It looks like other places using devm_gpiod_get_array_optional do > > check for a NULL return value, such as in > > drivers/iio/resolver/ad2s1210.c, drivers/mtd/maps/physmap-core.c, and > > this patch commit: > > https://patchwork.kernel.org/project/linux-fbdev/patch/20240114143921.550736-1-andriy.shevchenko@linux.intel.com/. > > > > > What about IS_ERR_OR_NULL() instead? > > > > Yes, that sounds good. However, I have a question—what error number > > should be returned in this case? > > I just took a closer look and don't thing returning on NULL is correct. > > The call is *_optional() meaning that NULL is an acceptable value. > > I believe that this is the correct solution: > > diff --git a/drivers/mfd/ene-kb3930.c b/drivers/mfd/ene-kb3930.c > index fa0ad2f14a39..9460a67acb0b 100644 > --- a/drivers/mfd/ene-kb3930.c > +++ b/drivers/mfd/ene-kb3930.c > @@ -162,7 +162,7 @@ static int kb3930_probe(struct i2c_client *client) > devm_gpiod_get_array_optional(dev, "off", GPIOD_IN); > if (IS_ERR(ddata->off_gpios)) > return PTR_ERR(ddata->off_gpios); > - if (ddata->off_gpios->ndescs < 2) { > + if (ddata->off_gpios && ddata->off_gpios->ndescs < 2) { > dev_err(dev, "invalid off-gpios property\n"); > return -EINVAL; > } > > -- > Lee Jones [李琼斯] ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-02-13 2:14 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-01-20 19:07 [PATCH] mfd: ene-kb3930: Fix potential NULL pointer dereference Chenyuan Yang 2025-01-27 16:30 ` Chenyuan Yang 2025-01-27 17:43 ` Krzysztof Kozlowski 2025-01-27 19:45 ` Chenyuan Yang 2025-01-28 7:10 ` Krzysztof Kozlowski 2025-02-10 17:33 ` Lee Jones 2025-02-10 23:47 ` Chenyuan Yang 2025-02-11 15:06 ` Lee Jones 2025-02-13 2:14 ` Chenyuan Yang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox