Edward O'Callaghan submitted this change.

View Change


Approvals: build bot (Jenkins): Verified Felix Singer: Looks good to me, approved Edward O'Callaghan: Looks good to me, but someone else must approve
flashrom: Check for flash access restrictions in erase path

Skip unwritable regions if FLASHROM_FLAG_SKIP_UNWRITABLE_REGIONS is
true. If the flag is false, erase operations that include an unwritable
region will not erase anything and return an error.

BUG=b:260440773
BRANCH=none
TEST=flashrom -E on dedede (JSL)

Change-Id: If027a96a024782c7707c6d38680709a1a117f3ef
CoAuthored-by: Edward O'Callaghan <quasisec@google.com>
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/70517
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Reviewed-by: Felix Singer <felixsinger@posteo.net>
---
M flashrom.c
1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/flashrom.c b/flashrom.c
index b611beb..62f38f8 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -1460,13 +1460,39 @@
all_skipped = false;

msg_cdbg("E");
- if (erasefn(flashctx, info->erase_start, erase_len))
- goto _free_ret;
- if (check_erased_range(flashctx, info->erase_start, erase_len)) {
- msg_cerr("ERASE FAILED!\n");
- goto _free_ret;
+
+ if (!flashctx->flags.skip_unwritable_regions) {
+ if (check_for_unwritable_regions(flashctx, info->erase_start, erase_len))
+ goto _free_ret;
}

+ unsigned int len;
+ for (unsigned int addr = info->erase_start; addr < info->erase_start + erase_len; addr += len) {
+ struct flash_region region;
+ get_flash_region(flashctx, addr, &region);
+
+ len = min(info->erase_start + erase_len, region.end) - addr;
+
+ if (region.write_prot) {
+ msg_gdbg("%s: cannot erase inside %s region (%#08x..%#08x), skipping range (%#08x..%#08x).\n",
+ __func__, region.name, region.start, region.end - 1, addr, addr + len - 1);
+ free(region.name);
+ continue;
+ }
+
+ msg_gdbg("%s: %s region (%#08x..%#08x) is writable, erasing range (%#08x..%#08x).\n",
+ __func__, region.name, region.start, region.end - 1, addr, addr + len - 1);
+ free(region.name);
+
+ if (erasefn(flashctx, addr, len))
+ goto _free_ret;
+ if (check_erased_range(flashctx, addr, len)) {
+ msg_cerr("ERASE FAILED!\n");
+ goto _free_ret;
+ }
+ }
+
+
if (region_unaligned) {
unsigned int starthere = 0, lenhere = 0, writecount = 0;
/* get_next_write() sets starthere to a new value after the call. */

To view, visit change 70517. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: If027a96a024782c7707c6d38680709a1a117f3ef
Gerrit-Change-Number: 70517
Gerrit-PatchSet: 11
Gerrit-Owner: Nikolai Artemiev <nartemiev@google.com>
Gerrit-Reviewer: Aarya <aarya.chaumal@gmail.com>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged