linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] staging: vc04_services: handle kzalloc failure
@ 2019-04-18 23:31 Nicholas Mc Guire
  2019-04-19 11:34 ` Stefan Wahren
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2019-04-18 23:31 UTC (permalink / raw)
  To: Eric Anholt
  Cc: Stefan Wahren, Greg Kroah-Hartman, Dominic Braun,
	Tobias Buettner, Nicolas Saenz Julienne, Luis Chamberlain,
	Phil Elwell, linux-rpi-kernel, linux-arm-kernel, devel,
	linux-kernel, Nicholas Mc Guire

The kzalloc here was being used without checking the return - if the
kzalloc fails return VCHIQ_ERROR. The call-site of
vchiq_platform_init_state() vchiq_init_state() was not responding
to an allocation failure so checks for != VCHIQ_SUCCESS
and pass VCHIQ_ERROR up to vchiq_platform_init() which then
will fail with -EINVAL.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
Reported-by: kbuild test robot <lkp@intel.com>
---

Problem located with experimental coccinelle script

V2: The != VCHIQ_SUCCES went unnoticed not clear how I did that as
    building drivers/staging/vc04_services/vchiq.o seemed to have succeeded
    anyway kbuild test found it. This is one of the disadvantages if one
    can not make path/file.o due to missing Makefiles and is required to
    build entire directories for compile-testing, I suspect that I did not
    clean the directory before compile-testing the patch.
    

Patch was compile-tested with: bcm2835_defconfig (implies BCM2835_VCHIQ=m)
(with sparse warning:
  CHECK   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29: warning: incorrect type in argument 1 (different address spaces)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29:    expected void const *x
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:410:29:    got char [noderef] <asn:1> *buf
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63: warning: incorrect type in argument 1 (different address spaces)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63:    expected void const *addr
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c:416:63:    got char [noderef] <asn:1> *
  CC [M]  drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.o
Q: should this buf have been remapped to user space e.g. remap_vmalloc_range ?

Patch is against 5.1-rc5 (localversion next is 20190417)

 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c | 3 +++
 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c     | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
index 31eb7d5..a9a2291 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
@@ -179,6 +179,9 @@ vchiq_platform_init_state(struct vchiq_state *state)
 	struct vchiq_2835_state *platform_state;
 
 	state->platform_state = kzalloc(sizeof(*platform_state), GFP_KERNEL);
+	if (!state->platform_state)
+		return VCHIQ_ERROR;
+
 	platform_state = (struct vchiq_2835_state *)state->platform_state;
 
 	platform_state->inited = 1;
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index 6057a90..92e6221 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -2209,6 +2209,8 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero)
 	local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
 
 	status = vchiq_platform_init_state(state);
+	if (status != VCHIQ_SUCCESS)
+		return VCHIQ_ERROR;
 
 	/*
 		bring up slot handler thread
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] staging: vc04_services: handle kzalloc failure
  2019-04-18 23:31 [PATCH V2] staging: vc04_services: handle kzalloc failure Nicholas Mc Guire
@ 2019-04-19 11:34 ` Stefan Wahren
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Wahren @ 2019-04-19 11:34 UTC (permalink / raw)
  To: Nicholas Mc Guire, Eric Anholt
  Cc: Greg Kroah-Hartman, Dominic Braun, Tobias Buettner,
	Nicolas Saenz Julienne, Luis Chamberlain, Phil Elwell,
	linux-rpi-kernel, linux-arm-kernel, devel, linux-kernel


Am 19.04.19 um 01:31 schrieb Nicholas Mc Guire:
> The kzalloc here was being used without checking the return - if the
> kzalloc fails return VCHIQ_ERROR. The call-site of
> vchiq_platform_init_state() vchiq_init_state() was not responding
> to an allocation failure so checks for != VCHIQ_SUCCESS
> and pass VCHIQ_ERROR up to vchiq_platform_init() which then
> will fail with -EINVAL.
>
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
> Reported-by: kbuild test robot <lkp@intel.com>
> ---
Acked-By: Stefan Wahren <stefan.wahren@i2se.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-04-19 21:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 23:31 [PATCH V2] staging: vc04_services: handle kzalloc failure Nicholas Mc Guire
2019-04-19 11:34 ` Stefan Wahren

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).