Skip to contentSkip to conversation

staging: greybus: bootrom: fix potential null pointer dereference

PATCH In review Oarora Etimis 2 participants 2 messages Mar 15 – Mar 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: bootrom: fix potential null pointer dereference

In gb_bootrom_get_firmware(), the 'fw' pointer could be NULL if the function jumps to the 'unlock' label. The execution flow continues into the 'queue_work' block where 'fw->size' is accessed, leading to a null pointer dereference.

Fix this by adding a NULL check for 'fw' before accessing its members.

---
 drivers/staging/greybus/bootrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +1 -1
index 83921d90c322..50c80475d241 100644
@@ -298,7 +298,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 
 queue_work:
 	/* Refresh timeout */
-	if (!ret && (offset + size == fw->size))
+	if (!ret && fw && (offset + size == fw->size))
 		next_request = NEXT_REQ_READY_TO_BOOT;
 	else
 		next_request = NEXT_REQ_GET_FIRMWARE;
Signature · 1 line
2.47.3
#1 lore raw
Quoted 17 lines · Oarora Etimis

In gb_bootrom_get_firmware(), the 'fw' pointer could be NULL if the function jumps to the 'unlock' label. The execution flow continues into the 'queue_work' block where 'fw->size' is accessed, leading to a null pointer dereference.

Fix this by adding a NULL check for 'fw' before accessing its members.

---
 drivers/staging/greybus/bootrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/bootrom.c +0 -0
index 83921d90c322..50c80475d241 100644

drivers/staging/greybus/bootrom.c static int gb_bootrom_get_firmware(struct gb_operation *op) · line 301

Quoted 5 lines
drivers/staging/greybus/bootrom.c +1 -1
@@ -298,7 +298,7 @@ static int gb_bootrom_get_firmware(struct gb_operation *op)
 
 queue_work:
 	/* Refresh timeout */
-	if (!ret && (offset + size == fw->size))
+	if (!ret && fw && (offset + size == fw->size))

Was this a static checker false positive? Which checker are you using?

If fw is NULL then "ret" is a negative error code so the original code is fine.

regards,
dan carpenter

Quoted 6 lines
drivers/staging/greybus/bootrom.c +0 -0
 		next_request = NEXT_REQ_READY_TO_BOOT;
 	else
 		next_request = NEXT_REQ_GET_FIRMWARE;
Signature · 1 line
2.47.3