Skip to content

Commit

Permalink
char: random: Workaround the Illegal unaligned access
Browse files Browse the repository at this point in the history
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 <extract_buf>:
...
 8087238:       460d            mov     r5, r1
...
 80872a0:       6028            str     r0, [r5, #0]
 80872a2:       6069            str     r1, [r5, #4]
 80872a4:       812b            strh    r3, [r5, EmcraftSystems#8]
...

Signed-off-by: Jim Huang <[email protected]>
  • Loading branch information
winfred-lu authored and jserv committed Dec 11, 2014
1 parent 164beca commit 29f9095
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 29f9095

Please sign in to comment.