diff mbox series

[4.4.y-cip] gpiolib: Fix invalid access of nullptr

Message ID 14717888-518c-3643-b98e-4a052c14c102@siemens.com (mailing list archive)
State Rejected
Headers show
Series [4.4.y-cip] gpiolib: Fix invalid access of nullptr | expand

Commit Message

Stefan Koch Dec. 2, 2019, 3:37 p.m. UTC
Hi

There is a NULL pointer exception issue within the gpiolib of the CIP 
4.4 kernel.
The CIP kernel output and a patch that fix the invalid null pointer 
access are attached.

The vanilla 4.4 kernel is not affected by this bug, because this 
regression affects only CIP 4.4.176-cip32 or newer kernels that contain 
back ported code for the gpiolib. The upstream vanilla kernel contains 
similar code beginning with version 4.17.

The following commits introduce the new functionality for the CIP 
4.4.176-cip32 kernel:
gpiolib: Avoid calling chip->request() for unused gpios, 
ed4f40244354af7b19b3bae5c56cce2620877b7c
gpiolib: Support 'gpio-reserved-ranges' property, 
baff4777cdb80256cd24dede2a3d0af761356307
gpiolib: Extract mask allocation into subroutine, 
171aad2d8519db9940d84e337da96aac8b1eb36c

Thank you.

Comments

Fabrizio Castro Dec. 2, 2019, 3:42 p.m. UTC | #1
Hi Stefan,

That's a known problem, please have a  look at:
https://patchwork.kernel.org/patch/11235267/

Pavel, Iwamatsu-san, could you please take patch:
https://patchwork.kernel.org/patch/11235267/

I think this is quite urgent as others will stumble across the problem and will try and fix it.

Thanks,
Fab

> -----Original Message-----
> From: Koch, Stefan <stefan-koch@siemens.com>
> Sent: 02 December 2019 15:37
> To: cip-dev@lists.cip-project.org
> Cc: Fabrizio Castro <fabrizio.castro@bp.renesas.com>; pavel@denx.de; nobuhiro1.iwamatsu@toshiba.co.jp
> Subject: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> 
> Hi
> 
> There is a NULL pointer exception issue within the gpiolib of the CIP
> 4.4 kernel.
> The CIP kernel output and a patch that fix the invalid null pointer
> access are attached.
> 
> The vanilla 4.4 kernel is not affected by this bug, because this
> regression affects only CIP 4.4.176-cip32 or newer kernels that contain
> back ported code for the gpiolib. The upstream vanilla kernel contains
> similar code beginning with version 4.17.
> 
> The following commits introduce the new functionality for the CIP
> 4.4.176-cip32 kernel:
> gpiolib: Avoid calling chip->request() for unused gpios,
> ed4f40244354af7b19b3bae5c56cce2620877b7c
> gpiolib: Support 'gpio-reserved-ranges' property,
> baff4777cdb80256cd24dede2a3d0af761356307
> gpiolib: Extract mask allocation into subroutine,
> 171aad2d8519db9940d84e337da96aac8b1eb36c
> 
> Thank you.
> 
> --
> Best regards
> Stefan Koch
> 
> Siemens AG
> Digital Industries
> Process Automation
> Software House Nbg
> DI PA CI R&D 3
> Gleiwitzer Str. 555
> 90475 Nuernberg, Germany
> stefan-koch@siemens.com <mailto:stefan-koch@siemens.com>
> www.siemens.com/ingenuityforlife <https://siemens.com/ingenuityforlife>
> www.siemens.com/ingenuityforlife
> Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Jim Hagemann Snabe; Managing Board: Joe Kaeser, Chairman,
> President and Chief Executive Officer; Roland Busch, Lisa Davis, Klaus Helmrich, Janina Kugel, Cedrik Neike, Michael Sen, Ralf P.
> Thomas; Registered offices: Berlin and Munich, Germany; Commercial registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684;
> WEEE-Reg.-No. DE 23691322
> 
>
Johnson CH Chen (陳昭勳) Dec. 3, 2019, 4:11 a.m. UTC | #2
Hi Pavel and Iwamatsu-san,

> From: cip-dev <cip-dev-bounces@lists.cip-project.org> On Behalf Of 
> Fabrizio Castro
> Sent: Monday, December 2, 2019 11:43 PM
> To: Koch, Stefan <stefan-koch@siemens.com>; 
> cip-dev@lists.cip-project.org
> Cc: Biju Das <biju.das@bp.renesas.com>
> Subject: Re: [cip-dev] [PATCH 4.4.y-cip] gpiolib: Fix invalid access 
> of nullptr
>
> Hi Stefan,
>
> That's a known problem, please have a  look at:
> https://patchwork.kernel.org/patch/11235267/
>
> Pavel, Iwamatsu-san, could you please take patch:
> https://patchwork.kernel.org/patch/11235267/
>
> I think this is quite urgent as others will stumble across the problem and will try and fix it.
>

For "fix" a backport issue, should we follow upstream first in CIP?

> Thanks,
> Fab
>


Best regards,
Johnson

<span class="sew4j6gfd2s3o7x"><br></span>> > -----Original Message-----
> > From: Koch, Stefan <stefan-koch@siemens.com>
> > Sent: 02 December 2019 15:37
> > To: cip-dev@lists.cip-project.org
> > Cc: Fabrizio Castro <fabrizio.castro@bp.renesas.com>; pavel@denx.de; 
> > nobuhiro1.iwamatsu@toshiba.co.jp
> > Subject: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> >
> > Hi
> >
> > There is a NULL pointer exception issue within the gpiolib of the 
> > CIP
> > 4.4 kernel.
> > The CIP kernel output and a patch that fix the invalid null pointer 
> > access are attached.
> >
> > The vanilla 4.4 kernel is not affected by this bug, because this 
> > regression affects only CIP 4.4.176-cip32 or newer kernels that 
> > contain back ported code for the gpiolib. The upstream vanilla 
> > kernel contains similar code beginning with version 4.17.
> >
> > The following commits introduce the new functionality for the CIP
> > 4.4.176-cip32 kernel:
> > gpiolib: Avoid calling chip->request() for unused gpios, 
> > ed4f40244354af7b19b3bae5c56cce2620877b7c
> > gpiolib: Support 'gpio-reserved-ranges' property,
> > baff4777cdb80256cd24dede2a3d0af761356307
> > gpiolib: Extract mask allocation into subroutine, 
> > 171aad2d8519db9940d84e337da96aac8b1eb36c
> >
> > Thank you.
> >
> > --
> > Best regards
> > Stefan Koch
> >
> > Siemens AG
> > Digital Industries
> > Process Automation
> > Software House Nbg
> > DI PA CI R&D 3
> > Gleiwitzer Str. 555
> > 90475 Nuernberg, Germany
> > stefan-koch@siemens.com <mailto:stefan-koch@siemens.com> 
> > www.siemens.com/ingenuityforlife 
> > <https://siemens.com/ingenuityforlife>
> > www.siemens.com/ingenuityforlife
> > Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Jim 
> > Hagemann Snabe; Managing Board: Joe Kaeser, Chairman, President and Chief Executive Officer; Roland Busch, Lisa Davis, Klaus Helmrich, Janina Kugel, Cedrik Neike, Michael Sen, Ralf P.
> > Thomas; Registered offices: Berlin and Munich, Germany; Commercial
> > registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684; 
> > WEEE-Reg.-No. DE 23691322
> >
> >
>
> _______________________________________________
> cip-dev mailing list
> cip-dev@lists.cip-project.org
> https://lists.cip-project.org/mailman/listinfo/cip-dev
Nobuhiro Iwamatsu Dec. 4, 2019, 12:19 a.m. UTC | #3
Hi Fabrizio, Stefan,

> -----Original Message-----
> From: Fabrizio Castro [mailto:fabrizio.castro@bp.renesas.com]
> Sent: Tuesday, December 3, 2019 12:43 AM
> To: Koch, Stefan <stefan-koch@siemens.com>;
> cip-dev@lists.cip-project.org
> Cc: pavel@denx.de; iwamatsu nobuhiro(岩松 信洋 ○SWC□OST)
> <nobuhiro1.iwamatsu@toshiba.co.jp>; Chris Paterson
> <Chris.Paterson2@renesas.com>; Biju Das <biju.das@bp.renesas.com>
> Subject: RE: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> 
> Hi Stefan,
> 
> That's a known problem, please have a  look at:
> https://patchwork.kernel.org/patch/11235267/
> 
> Pavel, Iwamatsu-san, could you please take patch:
> https://patchwork.kernel.org/patch/11235267/
> 
> I think this is quite urgent as others will stumble across the problem
> and will try and fix it.

OK, I will apply this with following comment if there is no other opinion.

NOTE: gpiochip_add_data()'s fixes is based on 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.

Best regards,
  Nobuhiro
Fabrizio Castro Dec. 4, 2019, 8:24 a.m. UTC | #4
Hi Iwamatsu-san,

Thank you for your feedback!

> From: nobuhiro1.iwamatsu@toshiba.co.jp <nobuhiro1.iwamatsu@toshiba.co.jp>
> Sent: 04 December 2019 00:20
> Subject: RE: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> 
> Hi Fabrizio, Stefan,
> 
> > -----Original Message-----
> > From: Fabrizio Castro [mailto:fabrizio.castro@bp.renesas.com]
> > Sent: Tuesday, December 3, 2019 12:43 AM
> > To: Koch, Stefan <stefan-koch@siemens.com>;
> > cip-dev@lists.cip-project.org
> > Cc: pavel@denx.de; iwamatsu nobuhiro(岩松 信洋 ○SWC□OST)
> > <nobuhiro1.iwamatsu@toshiba.co.jp>; Chris Paterson
> > <Chris.Paterson2@renesas.com>; Biju Das <biju.das@bp.renesas.com>
> > Subject: RE: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> >
> > Hi Stefan,
> >
> > That's a known problem, please have a  look at:
> > https://patchwork.kernel.org/patch/11235267/
> >
> > Pavel, Iwamatsu-san, could you please take patch:
> > https://patchwork.kernel.org/patch/11235267/
> >
> > I think this is quite urgent as others will stumble across the problem
> > and will try and fix it.
> 
> OK, I will apply this with following comment if there is no other opinion.
> 
> NOTE: gpiochip_add_data()'s fixes is based on 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.

Great, thanks!

Fab

> 
> Best regards,
>   Nobuhiro
>
Pavel Machek Dec. 4, 2019, 12:36 p.m. UTC | #5
Hi!

> > That's a known problem, please have a  look at:
> > https://patchwork.kernel.org/patch/11235267/
> > 
> > Pavel, Iwamatsu-san, could you please take patch:
> > https://patchwork.kernel.org/patch/11235267/
> > 
> > I think this is quite urgent as others will stumble across the problem
> > and will try and fix it.
> 
> OK, I will apply this with following comment if there is no other opinion.
> 
> NOTE: gpiochip_add_data()'s fixes is based on 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.

Sounds good to me.

Best regards,
								Pavel
Nobuhiro Iwamatsu Dec. 4, 2019, 11:21 p.m. UTC | #6
> -----Original Message-----
> From: Pavel Machek [mailto:pavel@denx.de]
> Sent: Wednesday, December 4, 2019 9:37 PM
> To: iwamatsu nobuhiro(岩松 信洋 ○SWC□OST)
> <nobuhiro1.iwamatsu@toshiba.co.jp>
> Cc: fabrizio.castro@bp.renesas.com; stefan-koch@siemens.com;
> cip-dev@lists.cip-project.org; pavel@denx.de;
> Chris.Paterson2@renesas.com; biju.das@bp.renesas.com
> Subject: Re: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> 
> Hi!
> 
> > > That's a known problem, please have a  look at:
> > > https://patchwork.kernel.org/patch/11235267/
> > >
> > > Pavel, Iwamatsu-san, could you please take patch:
> > > https://patchwork.kernel.org/patch/11235267/
> > >
> > > I think this is quite urgent as others will stumble across the
> > > problem and will try and fix it.
> >
> > OK, I will apply this with following comment if there is no other opinion.
> >
> > NOTE: gpiochip_add_data()'s fixes is based on
> 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.
> 
> Sounds good to me.

Applied.

Best regards,
  Nobuhiro
Chris Paterson Dec. 5, 2019, 9:44 a.m. UTC | #7
Hello all,

> From: nobuhiro1.iwamatsu@toshiba.co.jp
> <nobuhiro1.iwamatsu@toshiba.co.jp>
> Sent: 04 December 2019 23:21
> 
> > From: Pavel Machek [mailto:pavel@denx.de]
> > Sent: Wednesday, December 4, 2019 9:37 PM
> >
> > Hi!
> >
> > > > That's a known problem, please have a  look at:
> > > > https://patchwork.kernel.org/patch/11235267/
> > > >
> > > > Pavel, Iwamatsu-san, could you please take patch:
> > > > https://patchwork.kernel.org/patch/11235267/
> > > >
> > > > I think this is quite urgent as others will stumble across the
> > > > problem and will try and fix it.
> > >
> > > OK, I will apply this with following comment if there is no other opinion.
> > >
> > > NOTE: gpiochip_add_data()'s fixes is based on
> > 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.
> >
> > Sounds good to me.
> 
> Applied.

This patch seems to have broken builds for 2/16 of our v4.4.y-cip configurations.
Pipeline: https://gitlab.com/cip-project/cip-kernel/linux-cip/pipelines/100757773

1) x86_plathome_obsvx1.config:  https://gitlab.com/cip-project/cip-kernel/linux-cip/-/jobs/369871332

Error log:
3274 drivers/gpio/gpiolib.c: In function 'gpiochip_add_data':
3275 drivers/gpio/gpiolib.c:363:12: error: 'struct gpio_chip' has no member named 'of_node'
3276   if ((!chip->of_node) && (chip->dev))
3277             ^~
3278 drivers/gpio/gpiolib.c:364:7: error: 'struct gpio_chip' has no member named 'of_node'
3279    chip->of_node = chip->dev->of_node;
3280        ^~
3281   CC      drivers/dma/ioat/prep.o
3282 scripts/Makefile.build:277: recipe for target 'drivers/gpio/gpiolib.o' failed
3283 make[2]: *** [drivers/gpio/gpiolib.o] Error 1
3284 scripts/Makefile.build:484: recipe for target 'drivers/gpio' failed
3285 make[1]: *** [drivers/gpio] Error 2
3286 make[1]: *** Waiting for unfinished jobs....


2) x86_siemens_iot2000.config: https://gitlab.com/cip-project/cip-kernel/linux-cip/-/jobs/369871333

Error log:
2729 drivers/gpio/gpiolib.c: In function 'gpiochip_add_data':
2730 drivers/gpio/gpiolib.c:363:12: error: 'struct gpio_chip' has no member named 'of_node'
2731   if ((!chip->of_node) && (chip->dev))
2732             ^~
2733 drivers/gpio/gpiolib.c:364:7: error: 'struct gpio_chip' has no member named 'of_node'
2734    chip->of_node = chip->dev->of_node;
2735        ^~
2736 scripts/Makefile.build:277: recipe for target 'drivers/gpio/gpiolib.o' failed
2737 make[2]: *** [drivers/gpio/gpiolib.o] Error 1
2738 make[1]: *** [drivers/gpio] Error 2
2739 make[1]: *** Waiting for unfinished jobs....
2740 scripts/Makefile.build:484: recipe for target 'drivers/gpio' failed


Kind regards, Chris

> 
> Best regards,
>   Nobuhiro
Fabrizio Castro Dec. 5, 2019, 10:04 a.m. UTC | #8
Hi Chris,

Thank you for your feedback!

> From: Chris Paterson <Chris.Paterson2@renesas.com>
> Sent: 05 December 2019 09:44
> To: nobuhiro1.iwamatsu@toshiba.co.jp; pavel@denx.de
> Cc: Fabrizio Castro <fabrizio.castro@bp.renesas.com>; stefan-koch@siemens.com; cip-dev@lists.cip-project.org; Biju Das
> <biju.das@bp.renesas.com>
> Subject: RE: [PATCH 4.4.y-cip] gpiolib: Fix invalid access of nullptr
> 
> Hello all,
> 
> > From: nobuhiro1.iwamatsu@toshiba.co.jp
> > <nobuhiro1.iwamatsu@toshiba.co.jp>
> > Sent: 04 December 2019 23:21
> >
> > > From: Pavel Machek [mailto:pavel@denx.de]
> > > Sent: Wednesday, December 4, 2019 9:37 PM
> > >
> > > Hi!
> > >
> > > > > That's a known problem, please have a  look at:
> > > > > https://patchwork.kernel.org/patch/11235267/
> > > > >
> > > > > Pavel, Iwamatsu-san, could you please take patch:
> > > > > https://patchwork.kernel.org/patch/11235267/
> > > > >
> > > > > I think this is quite urgent as others will stumble across the
> > > > > problem and will try and fix it.
> > > >
> > > > OK, I will apply this with following comment if there is no other opinion.
> > > >
> > > > NOTE: gpiochip_add_data()'s fixes is based on
> > > 6ff0497402ef7269ee6a72f62eb85adaa7a4768e.
> > >
> > > Sounds good to me.
> >
> > Applied.
> 
> This patch seems to have broken builds for 2/16 of our v4.4.y-cip configurations.
> Pipeline: https://gitlab.com/cip-project/cip-kernel/linux-cip/pipelines/100757773
> 
> 1) x86_plathome_obsvx1.config:  https://gitlab.com/cip-project/cip-kernel/linux-cip/-/jobs/369871332
> 
> Error log:
> 3274 drivers/gpio/gpiolib.c: In function 'gpiochip_add_data':
> 3275 drivers/gpio/gpiolib.c:363:12: error: 'struct gpio_chip' has no member named 'of_node'
> 3276   if ((!chip->of_node) && (chip->dev))
> 3277             ^~
> 3278 drivers/gpio/gpiolib.c:364:7: error: 'struct gpio_chip' has no member named 'of_node'
> 3279    chip->of_node = chip->dev->of_node;
> 3280        ^~
> 3281   CC      drivers/dma/ioat/prep.o
> 3282 scripts/Makefile.build:277: recipe for target 'drivers/gpio/gpiolib.o' failed
> 3283 make[2]: *** [drivers/gpio/gpiolib.o] Error 1
> 3284 scripts/Makefile.build:484: recipe for target 'drivers/gpio' failed
> 3285 make[1]: *** [drivers/gpio] Error 2
> 3286 make[1]: *** Waiting for unfinished jobs....
> 
> 
> 2) x86_siemens_iot2000.config: https://gitlab.com/cip-project/cip-kernel/linux-cip/-/jobs/369871333
> 
> Error log:
> 2729 drivers/gpio/gpiolib.c: In function 'gpiochip_add_data':
> 2730 drivers/gpio/gpiolib.c:363:12: error: 'struct gpio_chip' has no member named 'of_node'
> 2731   if ((!chip->of_node) && (chip->dev))
> 2732             ^~
> 2733 drivers/gpio/gpiolib.c:364:7: error: 'struct gpio_chip' has no member named 'of_node'
> 2734    chip->of_node = chip->dev->of_node;
> 2735        ^~
> 2736 scripts/Makefile.build:277: recipe for target 'drivers/gpio/gpiolib.o' failed
> 2737 make[2]: *** [drivers/gpio/gpiolib.o] Error 1
> 2738 make[1]: *** [drivers/gpio] Error 2
> 2739 make[1]: *** Waiting for unfinished jobs....
> 2740 scripts/Makefile.build:484: recipe for target 'drivers/gpio' failed

This makes a lot of sense, Intel would not have CONFIG_OF_GPIO set!
I'll send another version.

Thanks,
Fab

> 
> 
> Kind regards, Chris
> 
> >
> > Best regards,
> >   Nobuhiro
diff mbox series

Patch

From 876e624bab1f8be84221f9bdb6a69a42d47ff085 Mon Sep 17 00:00:00 2001
From: Stefan Koch <stefan-koch@siemens.com>
Date: Mon, 2 Dec 2019 15:00:58 +0100
Subject: [PATCH] gpiolib: Fix invalid access of nullptr

This patch fixes a kernel panic exception because of invalid nullptr access.
The error was caused by backporting of new gpiolib functionality from kernel 4.17.

The upstream vanilla kernel 4.4 is not affected by this issue.

Signed-off-by: Stefan Koch <stefan-koch@siemens.com>
---
 drivers/gpio/gpiolib-of.c |  6 +++++-
 drivers/gpio/gpiolib.c    | 12 +++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index ec642bf1d976..eb8b595f9b9b 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -338,8 +338,12 @@  static void of_gpiochip_init_valid_mask(struct gpio_chip *chip)
 {
 	int len, i;
 	u32 start, count;
-	struct device_node *np = chip->dev->of_node;
+	struct device_node *np;
+
+	if (!chip->dev)
+		return;
 
+	np = chip->dev->of_node;
 	len = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
 	if (len < 0 || len % 2 != 0)
 		return;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index d72218fcaeeb..c3ec4372c439 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -295,12 +295,14 @@  static unsigned long *gpiochip_allocate_mask(struct gpio_chip *chip)
 static int gpiochip_init_valid_mask(struct gpio_chip *gpiochip)
 {
 #ifdef CONFIG_OF_GPIO
-	int size;
-	struct device_node *np = gpiochip->dev->of_node;
+	if (gpiochip->dev) {
+		int size;
+		struct device_node *np = gpiochip->dev->of_node;
 
-	size = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
-	if (size > 0 && size % 2 == 0)
-		gpiochip->need_valid_mask = true;
+		size = of_property_count_u32_elems(np,  "gpio-reserved-ranges");
+		if (size > 0 && size % 2 == 0)
+			gpiochip->need_valid_mask = true;
+	}
 #endif
 
 	if (!gpiochip->need_valid_mask)
-- 
2.20.1