Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

apparmor: Fix unaligned memory accesses in KUnit test

The testcase triggers some unnecessary unaligned memory accesses on the
parisc architecture:
Kernel: unaligned access to 0x12f28e27 in policy_unpack_test_init+0x180/0x374 (iir 0x0cdc1280)
Kernel: unaligned access to 0x12f28e67 in policy_unpack_test_init+0x270/0x374 (iir 0x64dc00ce)

Use the existing helper functions put_unaligned_le32() and
put_unaligned_le16() to avoid such warnings on architectures which
prefer aligned memory accesses.

Signed-off-by: Helge Deller <deller@gmx.de>
Fixes: 98c0cc48e27e ("apparmor: fix policy_unpack_test on big endian systems")
Signed-off-by: John Johansen <john.johansen@canonical.com>

authored by

Helge Deller and committed by
John Johansen
c6880419 c567de2c

+4 -2
+4 -2
security/apparmor/policy_unpack_test.c
··· 9 9 #include "include/policy.h" 10 10 #include "include/policy_unpack.h" 11 11 12 + #include <linux/unaligned.h> 13 + 12 14 #define TEST_STRING_NAME "TEST_STRING" 13 15 #define TEST_STRING_DATA "testing" 14 16 #define TEST_STRING_BUF_OFFSET \ ··· 82 80 *(buf + 1) = strlen(TEST_U32_NAME) + 1; 83 81 strscpy(buf + 3, TEST_U32_NAME, e->end - (void *)(buf + 3)); 84 82 *(buf + 3 + strlen(TEST_U32_NAME) + 1) = AA_U32; 85 - *((__le32 *)(buf + 3 + strlen(TEST_U32_NAME) + 2)) = cpu_to_le32(TEST_U32_DATA); 83 + put_unaligned_le32(TEST_U32_DATA, buf + 3 + strlen(TEST_U32_NAME) + 2); 86 84 87 85 buf = e->start + TEST_NAMED_U64_BUF_OFFSET; 88 86 *buf = AA_NAME; ··· 105 103 *(buf + 1) = strlen(TEST_ARRAY_NAME) + 1; 106 104 strscpy(buf + 3, TEST_ARRAY_NAME, e->end - (void *)(buf + 3)); 107 105 *(buf + 3 + strlen(TEST_ARRAY_NAME) + 1) = AA_ARRAY; 108 - *((__le16 *)(buf + 3 + strlen(TEST_ARRAY_NAME) + 2)) = cpu_to_le16(TEST_ARRAY_SIZE); 106 + put_unaligned_le16(TEST_ARRAY_SIZE, buf + 3 + strlen(TEST_ARRAY_NAME) + 2); 109 107 110 108 return e; 111 109 }