]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootcount: Fix potential clobbering issue
authorNiko Mauno <niko.mauno@vaisala.com>
Wed, 4 Feb 2026 13:17:36 +0000 (15:17 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 18 Feb 2026 22:35:07 +0000 (16:35 -0600)
When storing the single word bootcount value, apply the bootcount count
mask to prevent clobbering the magic half of the value.

Signed-off-by: Niko Mauno <niko.mauno@vaisala.com>
drivers/bootcount/bootcount.c

index 454e50591df676e4f13419f477e04328ec40231b..2c0114d97054185d7c268e1223e0011e612fa728 100644 (file)
@@ -19,7 +19,8 @@ __weak void bootcount_store(ulong a)
        uintptr_t flush_end;
 
 #if defined(CONFIG_SYS_BOOTCOUNT_SINGLEWORD)
-       raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK) | a);
+       raw_bootcount_store(reg, (CONFIG_SYS_BOOTCOUNT_MAGIC & BOOTCOUNT_MAGIC_MASK)
+               | (a & BOOTCOUNT_COUNT_MASK));
 
        flush_end = roundup(CONFIG_SYS_BOOTCOUNT_ADDR + 4,
                            CONFIG_SYS_CACHELINE_SIZE);
@@ -98,7 +99,8 @@ static int bootcount_mem_set(struct udevice *dev, const u32 a)
        uintptr_t flush_end;
 
        if (priv->singleword) {
-               raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK) | a);
+               raw_bootcount_store(reg, (magic & BOOTCOUNT_MAGIC_MASK)
+                       | (a & BOOTCOUNT_COUNT_MASK));
                flush_end = roundup(priv->base + 4,
                                    CONFIG_SYS_CACHELINE_SIZE);
        } else {