Skip to contentSkip to conversation

bootstd: android: avoid possible null pointer dereference

PATCH In review Gary Bisson 2 participants 3 messages Apr 2, 2025 – Apr 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bootstd: android: avoid possible null pointer dereference

- avb_slot_verify_data_free() doesn't check its data parameter
- out_data can be null if avb_slot_verify() fails to allocate memory

---
Another approach would be to fix avb_slot_verify_data_free() to check its paramter but I believe the goal is not to touch libavb to be closer to upstream.

---
 boot/bootmeth_android.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
boot/bootmeth_android.c +4 -2
index 3a59a4e3f6..f431b6ae58 100644
@@ -481,7 +481,8 @@ static int run_avb_verification(struct bootflow *bflow)
 		if (result != AVB_SLOT_VERIFY_RESULT_OK) {
 			printf("Verification failed, reason: %s\n",
 			       str_avb_slot_error(result));
-			avb_slot_verify_data_free(out_data);
+			if (out_data)
+				avb_slot_verify_data_free(out_data);
 			return log_msg_ret("avb verify", -EIO);
 		}
 		boot_state = AVB_GREEN;
@@ -491,7 +492,8 @@ static int run_avb_verification(struct bootflow *bflow)
 		    result != AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) {
 			printf("Unlocked verification failed, reason: %s\n",
 			       str_avb_slot_error(result));
-			avb_slot_verify_data_free(out_data);
+			if (out_data)
+				avb_slot_verify_data_free(out_data);
 			return log_msg_ret("avb verify unlocked", -EIO);
 		}
 		boot_state = AVB_ORANGE;
Signature · 1 line
2.47.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Gary,

Thank you for the patch.

Quoted 4 lines · Gary Bisson

- avb_slot_verify_data_free() doesn't check its data parameter
- out_data can be null if avb_slot_verify() fails to allocate memory

Quoted 34 lines

---
Another approach would be to fix avb_slot_verify_data_free() to check its paramter but I believe the goal is not to touch libavb to be closer to upstream.

---
 boot/bootmeth_android.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
boot/bootmeth_android.c +4 -2
index 3a59a4e3f6..f431b6ae58 100644
@@ -481,7 +481,8 @@ static int run_avb_verification(struct bootflow *bflow)
 		if (result != AVB_SLOT_VERIFY_RESULT_OK) {
 			printf("Verification failed, reason: %s\n",
 			       str_avb_slot_error(result));
-			avb_slot_verify_data_free(out_data);
+			if (out_data)
+				avb_slot_verify_data_free(out_data);
 			return log_msg_ret("avb verify", -EIO);
 		}
 		boot_state = AVB_GREEN;
@@ -491,7 +492,8 @@ static int run_avb_verification(struct bootflow *bflow)
 		    result != AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION) {
 			printf("Unlocked verification failed, reason: %s\n",
 			       str_avb_slot_error(result));
-			avb_slot_verify_data_free(out_data);
+			if (out_data)
+				avb_slot_verify_data_free(out_data);
 			return log_msg_ret("avb verify unlocked", -EIO);
 		}
 		boot_state = AVB_ORANGE;
Signature · 1 line
2.47.2