From 29f90958cd9f8c4e9d500c57fc3ea5650951ebb5 Mon Sep 17 00:00:00 2001 From: Winfred Lu Date: Tue, 3 Jun 2014 21:10:59 +0800 Subject: [PATCH] char: random: Workaround the Illegal unaligned access In extract_buf(), hash will be copied to out. Compiler optimizes memcpy() aggresively and does not test the unaligned destination address. Specify aligned attributes to workaound it. crash log: KERNEL: fault at 0x080872a0 [pc=0x080872a0, sp=0x9004bdb8] Illegal unaligned access Pid: 1, comm: swapper CPU: 0 Not tainted (2.6.33-arm1 #70) pc : [<080872a0>] lr : [<00000000>] psr: 2100000b sp : 9004bdb8 ip : 00000000 fp : 00000000 Code dump at pc [080872a0]: 60696028 a801812b f7f02114 b066fbe7 r10: 00000000 r9 : 9004a008 r8 : 90017ba0 r7 : 00000000 r6 : 90013950 r5 : 9004bf66 r4 : 00000020 r3 : 00005f10 r2 : 6183a03c r1 : 31f8a394 r0 : 8ddee099 Flags: nzCv IRQs on FIQs on Mode UK11_26 ISA unknown Segment kernel Kernel panic - not syncing: disassembly: 08087230 : ... 8087238: 460d mov r5, r1 ... 80872a0: 6028 str r0, [r5, #0] 80872a2: 6069 str r1, [r5, #4] 80872a4: 812b strh r3, [r5, #8] ... Signed-off-by: Jim Huang --- drivers/char/random.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/char/random.c b/drivers/char/random.c index 2849713d223..64f97710ff1 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -853,7 +853,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf, size_t nbytes, int min, int reserved) { ssize_t ret = 0, i; - __u8 tmp[EXTRACT_SIZE]; + __u8 tmp[EXTRACT_SIZE] __attribute__((aligned(32))); unsigned long flags; xfer_secondary_pool(r, nbytes); @@ -886,7 +886,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf, size_t nbytes) { ssize_t ret = 0, i; - __u8 tmp[EXTRACT_SIZE]; + __u8 tmp[EXTRACT_SIZE] __attribute__((aligned(32))); xfer_secondary_pool(r, nbytes); nbytes = account(r, nbytes, 0, 0);