]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
fs: btrfs: Fix unaligned memory accesses
authorAlberto Sánchez Molero <alsamolero@gmail.com>
Sat, 20 Jan 2018 07:17:57 +0000 (09:17 +0200)
committerTom Rini <trini@konsulko.com>
Sun, 28 Jan 2018 17:27:12 +0000 (12:27 -0500)
Loading files stored with lzo compression from a btrfs filesystem was
producing unaligned memory accesses, which were causing a data abort
and a reset on an Orange Pi Zero.

The change in hash.c is not triggered by any error but follows the
same pattern. Please confirm.

Fixed according to doc/README.unaligned-memory-access.txt

Signed-off-by: Alberto Sánchez Molero <alsamolero@gmail.com>
Tested-by: Robert Nelson <robertcnelson@gmail.com>
fs/btrfs/compression.c
fs/btrfs/hash.c

index a59ff5a8bbf4e845cdaea8d3ed498a6159d5c5ad..b1b4498fba51d87566061fb04e47b9f720bdd174 100644 (file)
@@ -9,6 +9,7 @@
 #include "btrfs.h"
 #include <linux/lzo.h>
 #include <u-boot/zlib.h>
+#include <asm/unaligned.h>
 
 static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
 {
@@ -19,7 +20,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
        if (clen < 4)
                return -1;
 
-       tot_len = le32_to_cpu(*(u32 *) cbuf);
+       tot_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
        cbuf += 4;
        clen -= 4;
        tot_len -= 4;
@@ -32,7 +33,7 @@ static u32 decompress_lzo(const u8 *cbuf, u32 clen, u8 *dbuf, u32 dlen)
        res = 0;
 
        while (tot_len > 4) {
-               in_len = le32_to_cpu(*(u32 *) cbuf);
+               in_len = le32_to_cpu(get_unaligned((u32 *)cbuf));
                cbuf += 4;
                clen -= 4;
 
index f8a50e532aeeb5edabce60b50fbee1fc8b3b4289..cde3abd3dfbb9f25218e6c37b469670d13960d44 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "btrfs.h"
 #include <u-boot/crc.h>
+#include <asm/unaligned.h>
 
 static u32 btrfs_crc32c_table[256];
 
@@ -34,5 +35,5 @@ u32 btrfs_csum_data(char *data, u32 seed, size_t len)
 
 void btrfs_csum_final(u32 crc, void *result)
 {
-       *((u32 *) result) = cpu_to_le32(~crc);
+       put_unaligned(cpu_to_le32(~crc), (u32 *)result);
 }