Skip to contentSkip to conversation

vc04_services: vchiq_arm: fix a NULL pointer dereference

PATCH In review Kangjie Lu 3 participants 3 messages Mar 24, 2019 – Mar 27, 2019

Subsystems (2)
lore
Share & tools
lore

Kangjie Lu

author
#0 lore raw

PATCH 1/1 vc04_services: vchiq_arm: fix a NULL pointer dereference

When kzalloc fails, "platform_state->inited = 1" is a NULL pointer dereference. The fix returns VCHIQ_ERROR in case it failed to avoid NULL pointer dereference.

---
 .../staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c  | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +2 -0
index dd4898861b83..0f12fe617575 100644
@@ -209,6 +209,8 @@ 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;
Signature · 1 line
2.17.1
#1 lore raw

Hi Kangjie,

Am 24.03.19 um 23:43 schrieb Kangjie Lu:

Quoted 5 lines

When kzalloc fails, "platform_state->inited = 1" is a NULL pointer dereference. The fix returns VCHIQ_ERROR in case it failed to avoid NULL pointer dereference.

please add a proper fixes tag.

Quoted 9 lines
---
 .../staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c  | 2 ++
 1 file changed, 2 insertions(+)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +0 -0
index dd4898861b83..0f12fe617575 100644

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c vchiq_platform_init_state(struct vchiq_state *state) · line 213

Quoted 5 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +2 -0
@@ -209,6 +209,8 @@ 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;

this change is good, but vchiq_init_state doesn't bail out immediately in case vchiq_platform_init_state fails.

Could you please fix that, too?

Thanks Stefan

Quoted 3 lines
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +0 -0
 	platform_state = (struct vchiq_2835_state *)state->platform_state;
 
 	platform_state->inited = 1;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kangjie Lu
Quoted 5 lines · Kangjie Lu

When kzalloc fails, "platform_state->inited = 1" is a NULL pointer dereference. The fix returns VCHIQ_ERROR in case it failed to avoid NULL pointer dereference.

-Mukesh

Quoted 17 lines
---
  .../staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c  | 2 ++
  1 file changed, 2 insertions(+)
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c +2 -0
index dd4898861b83..0f12fe617575 100644
@@ -209,6 +209,8 @@ 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;