From 0835ece5bc10f3cfe4a09cf0ef24351ee315ba68 Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Tue, 31 Oct 2023 16:24:46 +0100 Subject: [PATCH] hardware_manager: Prevent race-condition in upgrade check --- tools/services/hardware_manager.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/services/hardware_manager.py b/tools/services/hardware_manager.py index b9cff46..9175022 100644 --- a/tools/services/hardware_manager.py +++ b/tools/services/hardware_manager.py @@ -30,12 +30,18 @@ def start(args): helpers.lxc.start(args) def upgrade(system_zip, system_time, vendor_zip, vendor_time): - if os.path.exists(system_zip) and not helpers.images.validate(args, "system_ota", system_zip): - logging.warning("Not upgrading because system.img comes from an unverified source") - return - if os.path.exists(vendor_zip) and not helpers.images.validate(args, "vendor_ota", vendor_zip): - logging.warning("Not upgrading because vendor.img comes from an unverified source") - return + if os.path.exists(system_zip): + if not helpers.images.validate(args, "system_ota", system_zip): + logging.warning("Not upgrading because system.img comes from an unverified source") + return + else: + system_zip = "" # Race prevention + if os.path.exists(vendor_zip): + if not helpers.images.validate(args, "vendor_ota", vendor_zip): + logging.warning("Not upgrading because vendor.img comes from an unverified source") + return + else: + vendor_zip = "" # Race prevention helpers.lxc.stop(args) helpers.images.umount_rootfs(args) helpers.images.replace(args, system_zip, system_time, -- 2.47.3